Open source reader

Thursday, May 11, 2006

Your *own* java irc bot in 10 java lines with PircBot !

I was looking for a method to have an html history on a specific irc channel ... I installed irssi went on pisg installed id, it worked fine, but I got only statistics ...

I thought that php had a very simple api for me to implement in a few minutes ... They have an irc api but nothing to get a message ... that's quite bad :)

Then I found pircbot hey, that's exactly what I needed ! Look at how simple it is ...

import org.jibble.pircbot.*;

public class MyBotMain {

public static void main(String[] args) throws Exception {
MyBot bot = new MyBot();
bot.connect("irc.freenode.net");
bot.joinChannel("#pircbot");
}

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);
}
}
}
One word: thanks guys ! I have now a simple tool that fits my need in record time !

0 Comments:

Post a Comment

<< Home