import java.io.IOException; import org.jibble.pircbot.DccChat; import org.jibble.pircbot.PircBot; // This is a very simple example usage of the PircBot API. public class Project3Bot extends PircBot { // The following method will be called every time a message is received in a // channel that this bot is joined to. protected void onMessage(String channel, String sender, String login, String hostname, String message) { // This sends a message back to the channel. sendMessage(channel, "Sender " + sender + " sent message: " + message); } // This method is called whenever a private message is sent to the PircBot. protected void onPrivateMessage(String sender, String login, String hostname, String message) { // This sends a private message back to the sender. sendMessage(sender, "You said: " + message); } // This method is called whenever someone tries to initiate a direct chat with // the bot. Note that this may or may not work depending on you NAT/Firewall // setup. public void onIncomingChatRequest(DccChat chat) { try { // Accept all chat, whoever it's from. chat.accept(); chat.sendLine("Hello"); String response = chat.readLine(); chat.sendLine("You said: " + response); chat.close(); } catch (IOException e) { e.printStackTrace(); } } // Example of how to connect to an IRC server and join a channel with this // bot. public static void main(String[] args) throws Exception { Project3Bot bot = new Project3Bot(); // Enable debugging output. bot.setVerbose(true); bot.setName("Project3Bot"); // Make sucessive messages be sent instantly bot.setMessageDelay(0); // Connect to an IRC server specified on the command line // or to localhost if no server is specified. if (args.length >= 1) bot.connect(args[0]); else bot.connect("localhost"); // Join a channel bot.joinChannel("#channel_name"); } }