0

I'm trying to set mode to an IRC channel but PircBotX doesn't seems to execute the command when called in the main method. The command executes when I send the message (!setRModePlus) that I have set up in the code. Where am I wrong with my code?

import org.pircbotx.Channel;
import org.pircbotx.Configuration;
import org.pircbotx.PircBotX;
import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.types.GenericMessageEvent;

public class MyListener extends ListenerAdapter {

static Channel channel = null;
static PircBotX bot = null;

@Override
public void onGenericMessage(GenericMessageEvent event) {

   if (event.getMessage().startsWith("!setRModePlus")) {
         channel = bot.getUserChannelDao().getChannel("#mychannel");
         channel.send().setMode("+R");
    }
    if (event.getMessage().startsWith("!setRModeMinus")) {
         channel = bot.getUserChannelDao().getChannel("#mychannel");
         channel.send().setMode("-R");
    }
}

public static void main(String[] args) throws Exception {
    //Configure the bot
    Configuration configuration = new Configuration.Builder()
            .setName("myname")
            .addServer("myserver")
            .setNickservPassword("mypassword")
            .addAutoJoinChannel("#mychannel") 
            .addListener(new MyListener()) 
            .buildConfiguration();

    //Create  bot with the configuration
    bot = new PircBotX(configuration);
    bot.startBot();
    channel = bot.getUserChannelDao().getChannel("#mychannel");
    channel.send().setMode("+R");



}

Thank you for any help you can offer. Sorry for my English.

OttPrime
  • 1,878
  • 1
  • 15
  • 24
jeriko
  • 5
  • 4

1 Answers1

0

Problem solved now. I added onConnect method and send the command like this

 public void onConnect(ConnectEvent event) {

        event.getBot().send().mode("#mychannel", "+R");
        event.getBot().send().mode("#mychannel", "-R");


}
jeriko
  • 5
  • 4