February 02, 2010

IRC Bot Tutorial

« Java SVG Example | Main | Easymock example »
PircBot is a Java Framework which provides an API to write different kinds of interactive IRC bots. If you have finished your bot, you have only to compile and run your little Java program on your irc server console. But keep an eye on your user rights and don’t start your bot as root to avoid possible complete server hacks due to your bot software.

Example:
import org.jibble.pircbot.PircBot;

public class OwnBot extends PircBot {

  public  OwnBot() {
    //set bot name
    this.setName("BotName");
  }

  public static void main(String[] args) throws Exception {
    // now start the bot up
    OwnBot bot = new OwnBot();
    // enable debugging output
    bot.setVerbose(true);
    // connect to your own irc server
    bot.connect("irc.domain.de", 6668);
    bot.identify("botpassword");
    // join the #bottest1 channel
    bot.joinChannel("#bottest1");
    // left the #bottest2 channel
    bot.partChannel("#bottest2");
  }

  public void onMessage(String channel, String sender, String login,
                        String hostname, String message) {
    if (message.equalsIgnoreCase("!time")) {
      String time = new java.util.Date().toString();
      sendMessage(channel, sender + ": The time is now " + time);
    }                             
   …
  }
}
see http://www.jibble.org/pircbot.php

Technorati Tags:

Posted by corinna.herrmann at 12:51 PM in Java

 

[Trackback URL for this entry]

Your comment:

(not displayed)
 
 
 

Live Comment Preview:

 
« February »
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28