I’m trying to learn how pircBot works with Java. I’ve already programmed a working chat bot in python. I’m using Java to try and refresh my java knowledge. I’ve looked around and can’t find any other topics on this site that address this.
Here’s my current code:
Bot Code:
import java.io.IOException;
import org.jibble.pircbot.*;
public class MyBot extends PircBot {
private static String channel;
public MyBot() { this.setName("sato_chat"); } public MyBot(String channel) { this.channel = channel; } public void sendmember() throws NickAlreadyInUseException, IOException, IrcException { this.sendRawLine("CAP REQ :twitch.tv/membership\r\n"); this.sendRawLine("CAP REQ :twitch.tv/tags\r\n"); this.sendRawLine("CAP REQ :twitch.tv/commands\r\n"); } public void onMessage(String channel, String sender, String login, String hostname, String message) { System.out.println("On Message Handler"); if (message == "Hi") { this.sendMessage(channel, "Hello"); } System.out.println(channel + " " + sender + " " + message); }
}
Main code:
import org.jibble.pircbot.*;
public class MyBotMain {
public static void main(String[] args) throws Exception { // Now start our bot up. MyBot bot = new MyBot("#satokaheni"); // Enable debugging output. bot.setVerbose(true); // Connect to the IRC server. bot.connect("irc.chat.twitch.tv", 80, pass); bot.sendmember(); bot.joinChannel("#satokaheni"); }
}
the on message handler doesn’t register when I send a message to the chat room. So I’m not sure what I’m doing incorrectly here.