Java Menu

Using Java to create standalone program or applet

We choose that we are going to build automated chat robot or bot ... ircbot.

To build a program we need Java SDK from Sun with NetBeans editor ,

this can be downloaded as bundle from sun website free!

PircBot java code eg. library or jar package from PircBot library.

 

Java irc library - PircBot

We are going to modify library so that our bot can connect over secured connection using SSL.

Other than that library is perfect.

That means that we are going to open two projects in NetBeans IDE ,

one will be PircBot and other our bot itself.

Now digg into NetBeans IDE

Extract pircbot.jar , take *.java files into pircbot_source folder

in NetBeans create new java project with existing sources, files pointing to pircbot_source folder. Now you can try compiling it , everything should go without any errors.

Create second java application project named PlayBot

also click on create main class.

Create PlayBot our ircbot

Now create new java file and name it PlayBot.java :

package playbot;

import org.jibble.pircbot.PircBot;

public class PlayBot extends PircBot {

public PlayBot() {

setName("PlayBot");
setLogin("PlayBot");
setVersion("PlayBot 1.0");
setAutoNickChange(true);
setVerbose(true);
}

@Override
public void onConnect() {

joinChannel("#PlayBot");

setTopic("#PlayBot", "PLayBot Table");

}
@Override
public void onMessage(String channel, String sender, String login, String hostname, String message) {

if (message.contains("version")) {

sendMessage(channel, getVersion());

}
}

}

 

In Main.java put this source :

package playbot;

public class Main {
public static void main(String[] args) throws Exception {
PlayBot bot = new PlayBot();
bot.connect("irc.freenode.net");

}

}

Compile and run from NetBeans IDE

Finaly run PlayBot from whithin IDE and connect with your favorite irc client to irc.freenode.net and join #PlayBot the bot should be there and the channel topic set to PLayBot Table.

After sending message version to channel the PlayBot responds with his version number.

[20:57] * PlayBot (n=PlayBot@1.1.1.1.com) has joined #PlayBot
[20:57] * PlayBot sets topic to: PLayBot Table
[20:58] <Os> version
[20:58] <PlayBot> PlayBot 1.0