Quick & Easy IRC Bots with Java
February 18, 2008 · by Eric Sorenson
Every day at around 11:30 the developers in my area are faced with the most difficult question of the morning: where to go to lunch? To help move things along, I decided to create an IRC Bot for our developer channel. There’s no point in reinventing the wheel. After 30 seconds of Googling, I found a very capable framework: http://www.jibble.org/pircbot.php. Just extend the PircBot class, and in minutes you’ll have a functional IRC Bot!
import org.jibble.pircbot.PircBot;
public class LunchBot extends PircBot {
public static String[] lunchSpots = {
"Copp's",
"Chipotle",
"Chin's",
"Quizno's",
"Casa Bianca",
"Panera",
"Cousin's",
"Milio's",
"Subway",
"Boston's",
"JT Whitney's",
"Takara",
"Laredo's",
"Quaker Steak & Lube",
"TGI Fridays",
"PF Chang's",
"the Hubbard Ave Diner",
"McDonald's",
"the West Towne Mall Food Court",
"the first floor",
"the fridge in the break room and steal a brownbag"
};
public LunchBot() {
super();
setName("LunchBot");
}
public void onMessage(String channel, String sender, String login, String hostname, String message) {
if (message.equalsIgnoreCase("lunch")) {
sendMessage(channel, sender + ": you should go to " + lunchSpots[(int) (Math.random()*lunchSpots.length)] );
}
}
}
If anyone types “lunch” in our channel, they’ll get a random item from the list. It took more time to think of the lunch options than it did to do the research and coding!
Filed in: Team Member Blog Comments (0)

Comments
There are no comments for this entry.
Commenting is not available in this section entry.