|
It is very simple to generate a GlassBot(R) in Jbuilder environment.
It consist of 4 easy steps:
-
Creating a new project
-
Creating a new class
-
Edit the class
-
Executing the GlassBot(R)
1. Creating a new project
A. First of all, you must create a project in Jbuilder. Choose "GlassBotTest"
as your project name therefore all the class files will be generated under "glassbottest"
package.
B. In the second step of the project wizard select required libraries tab and
press on Add... button. A pop up window will be displayed. Push New... button in
this window. Name your library as "GlassBot" and press on Add... button. Explore your hard drive and find "GlassBot.jar" file. It must be in GlassRoom
installation folder under "classes" subfolder. Press on OK and continue the
process.
2. Creating a new class
Use File->New Class... menu to start class wizard. Enter "TestBot" as your class
name.
Choose "com.chatessentials.GlassBot.GlassBot" as your base class name. In the
options pane select the "Public", and "Generate main method" checkboxes.
3. Edit the class (using an example)
Edit your class file as below:
--------------------
package glassbottest;
import com.chatessentials.GlassBot.GlassBot;
import com.chatessentials.GlassRoom.*;
import java.net.URL;
public class TestBot extends GlassBot
{
public void onPrivateMessage (UserMinor sender, String message, URL url)
{
this.sendPrivateMessage(sender.nick + ", you said : " + message, sender.nick);
}
public static void main (String args[])
{
main(new TestBot(), args);
}
}
--------------------
This simple code is a GlassBot(R). As you can see, this simple
robot repeats all the private messages. Suppose "jack" sends a private message
such as "hello" to this Bot, a message will be sent to jack in private in the
form of "jack, you said : hello". Indeed, we have overridden onPrivateMessage()
method of GlassBot(R) this method is called when a private message arrives to Bot,
and we used sendPrivateMessage() method to send a private message to a user.
4. Executing the GlassBot
First, run the chat server and make sure that it comes up successfully. You have
two methods to run your GlassBot :
A) You can run it by main() method. In this case you must make a runtime
environment in Jbuilder and choose glassbottest.TestBot as your Main class and
set "127.0.0.1 -n robo_tester" in Application parameters section. Now run the
project by pressing the F9 key. If there is no problem, this message will be
appeared :
"Bot is initiated." And you can test the functionality of your Bot by launching
a browser and opening the chat page and sending a message to the robo_test user.
B) You can embed this class in your chat server. In this case, you must compile
your Bot by pressing ctrl+F9. Then copy the glassbottest folder in classes
subfolder of your project into "classes" subfolder of your chat server in
installation folder.
Use GlassRoom's control panel to add this Bot to system. Note that you must set
glassbottest.TestBot as your "class file" don't use "robots." prefix because you
didn't use robots directory (package) in this example.
|