简体   繁体   English

Java的PircBot是否需要帮助来创建中继机器人?

[英]PircBot with java need help creating relay bot?

I would like help creating a relay bot with PircBot. 我想帮助使用PircBot创建中继机器人。 I want it for each message it sends a message to a channel with that message. 我希望它为每条消息发送一条消息到带有该消息的通道。 And I wish to have this multi networks. 我希望拥有这样的多网络。 I made a command 我发出命令

if (split[0].equalsIgnoreCase(commandPrefix + "addnet")) {
    // sendRawLine("QUIT : joining " + split[1]);
    BrookieBot bot = new BrookieBot();
    bot.setVerbose(true);
    addnet = addnet + " " + split[1];
    try {
        bot.connect(split[1]);
        sendMessage("nickserv", "identify pass");
        bot.joinChannel("#brookies-use-of-bot");

    } catch (NickAlreadyInUseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IrcException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    bot = new BrookieBot();
    quit = 6;

    this.joinChannel("#brookies-use-of-bot");
}

That is how I made it connect to multiple networks, but I want it to reconise the net and send a message each time it recieves a message to that channel no matter what network. 这就是我使它连接到多个网络的方式,但是我希望它重新调整网络并在每次接收消息到该通道时都发送消息,而不管它是哪个网络。 Having the message be in this format: [<net>] [<sender>] [<message>] . 使消息采用以下格式: [<net>] [<sender>] [<message>] Thank you for all your help! 谢谢你的帮助! I have this version: http://www.jibble.org/pircbot.php 我有这个版本: http : //www.jibble.org/pircbot.php

I've made one such relay bot before. 我之前做了一个这样的中继机器人。 Let's discuss what you need. 让我们讨论您的需求。

When a bot recieves a message in a channel to be relayed, the message is sent using an array of bots to their respective channels based on server and channel combination, provided: 当漫游器在要中继的通道中接收消息时,根据服务器和通道组合,使用一系列漫游器将漫游器发送到各自的通道,前提是:

  1. The channel selected in the loop is not the current channel 循环中选择的通道不是当前通道
  2. The channel is in the list of to be synchronized channels 该频道在要同步的频道列表中
  3. The sender is not part of the bot names to prevent infinite loops 发件人不是机器人名称的一部分,以防止无限循环

The same goes for quit, part, join and anything else you want. 退出,部分加入和其他您想要的任何事情也是如此。

1) PircBot isn't good for multi networks. 1)PircBot不适用于多网络。 Also, it has several design problems. 而且,它有几个设计问题。 I would recommend PircBotX. 我会推荐PircBotX。

2) If you really have to use PircBot: 2)如果您确实必须使用PircBot:

Create one PircBot object per connection. 每个连接创建一个PircBot对象。
That will create one thread per PircBot. 这将为每个PircBot创建一个线程。
Then, create a bus which will distribute the messages amongst PircBot instances. 然后,创建一个总线,该总线将在PircBot实例之间分发消息。
Be careful with synchronization. 注意同步。

For an example on how to send messages outside PircBot object, see JawaBot , which is based on it. 有关如何在PircBot对象外部发送消息的示例,请参见基于它的JawaBot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM