Writing a bot becomes much simpler, as illustrated in this second Java version of a simple IRC bot. Save the following code as HackBot2.java:
import org.jibble.pircbot.*;
public class HackBot2 extends PircBot {
public HackBot2( ) {
this.setName("HackBot2");
}
}
Believe it or not, that's all you have to do to create a bot. Creating an instance of the HackBot2 class gives you an object that inherits all of the methods from the PircBot class, thereby allowing you to tell it to connect to a server, join a channel, and so on.
Create another class in a new source file, Main.java, which contains a simple main method to create an instance of the bot. The main method also tells it to connect to a server and join a channel. A separate class called Main is used to store the main method so it is easier to work out how to run the bot—when a newcomer stumbles across your project, it is obvious where the main method is without having to look at any source code.
import org.jibble.pircbot.*;
public class Main {
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment