PIRCBOT - 如何为频道中的所有用户添加语音 - Java

时间:2011-06-03 09:39:58

标签: java irc

我正在使用pircbot制作一个IRC机器人。如何让机器人为频道中的所有用户添加语音?或者当用户加入?

1 个答案:

答案 0 :(得分:0)

可能是这样的:

import org.jibble.pircbot.*;

public class MyBot extends PircBot {

  public MyBot() {
    this.setName("MyBot");
  }

  public void onJoin(String channel, String sender,
                   String login, String hostname, String message) {
    this.voice(channel, sender);
  }

  public void voiceAll(String channel) {
    int i = 0;
    User[] users = this.getUsers(channel);
    while (i < users.length)
      this.voice(channel, users[i++].getNick());
  }
}

public class MyBotMain {

  public static void main(String[] args) throws Exception {
    MyBot bot = new MyBot();
    bot.connect("irc.freenode.net");
    bot.joinChannel("#chan");
    bot.voiceAll("#chan"); 
  }

}

你应该在发声之前验证一些东西(你在陈?你是操作员?)。 请查看API页面:http://www.jibble.org/javadocs/pircbot/index.html

相关问题