Making A Java IRC Bot With The PircBot Framework
Making A Java IRC Bot With The PircBot Framework
import org.jibble.pircbot.*;
if (message.equalsIgnoreCase(“time”)) {
String time = new java.util.Date().toString();
sendMessage(channel, sender + “: ” + time);
}
if (recipientNick.equalsIgnoreCase(getNick())) {
joinChannel(channel);
}
}
Note that we only attempt to rejoin the
channel if it was us that was kicked
while (!isConnected()) {
try {
reconnect();
}
catch (Exception e) {
// Couldn’t reconnect.
// Pause for a short while before retrying?
}
}
}
Copyright Paul Mutton, http://www.jibble.org/pircbot.php 19
PircBot Ident Server
Some IRC servers require you to
connect from a machine that runs an
Ident Server
PircBot can emulate the functionality of
an Ident Server if you do not already
run one
Provides the IRC server with your Bot’s
login when it asks for it
bot.startIdentServer();
Copyright Paul Mutton, http://www.jibble.org/pircbot.php 20
PircBot Flood Protection
Some IRC servers disconnect clients
that send too many messages too
quickly.
PircBot queues most outgoing
messages.
Queued messages are sent with a small
delay between them to prevent
“flooding”
You can get the current size of this
queue by calling the 21
Copyright Paul Mutton, http://www.jibble.org/pircbot.php
Colors and Formatting
Examples
String chan = “#bots”;