0

我将当前配置与 IRC freenode 服务器一起使用:

BOT_PREFIX = '@'
BOT_PREFIX_OPTIONAL_ON_CHAT = True
BOT_ALT_PREFIXES = ('Err', "bot", "mybot", "botka", "errbot")
BOT_ALT_PREFIX_SEPARATORS = (':', ',', ';')
BOT_ALT_PREFIX_CASEINSENSITIVE = True

我对 IRC 服务使用身份验证。

但是当 bot 登录时,它有一个问题:当它用 NickServ 标识自己时,bot 从 NickServ 获取消息,其中包括它的 nick 并将它们视为命令(因为BOT_PREFIX_OPTIONAL_ON_CHATand BOT_ALT_PREFIXES)。然后 errbot 向 NickServ 发送关于“错误命令”的错误消息,NickServ 回复说它不理解“错误命令”到 bot 的私有并重新开始......

所以在这些机器人通过这个对话吃掉所有互联网流量之前,我怎样才能从这个对话中排除 NickServ 或导致 errbot 不回复“错误命令”或任何其他解决方案?

目前我在我的插件中使用肮脏的黑客来覆盖来自 NickServ 的“无效命令”:

@botcmd()
def Invalid(self, msg, args):
    if args.startswith("Invalid command."):
        return

这可以防止 errbot 回复 NickServ。还需要使用

HIDE_RESTRICTED_COMMANDS = True
HIDE_RESTRICTED_ACCESS = True

但我正在寻找更好的解决方案。提前致谢!

来自机器人对话的日志:

22:40:06 DEBUG    irc.client                FROM SERVER: :NickServ!NickServ@services. NOTICE botka :This nickname is registered. Please choose a different nickname, or identify via /msg NickServ identify <passw
ord>.
22:40:06 DEBUG    irc.client                _dispatcher: all_raw_messages
22:40:06 DEBUG    irc.client                command: privnotice, source: NickServ!NickServ@services., target: botka, arguments: ['This nickname is registered. Please choose a different nickname, or identify via
 \x02/msg NickServ identify <password>\x02.'], tags: None
22:40:06 DEBUG    irc.client                _dispatcher: privnotice
22:40:06 DEBUG    errbot.core               *** frm = NickServ!NickServ@services.
22:40:06 DEBUG    errbot.core               *** username = NickServ
22:40:06 DEBUG    errbot.core               *** text = This nickname is registered. Please choose a different nickname, or identify via /msg NickServ identify <password>.
22:40:06 DEBUG    errbot.core               Assuming 'This nickname is registered. Please choose a different nickname, or identify via /msg NickServ identify <password>.' to be a command because BOT_PREFIX_OPTIO
NAL_ON_CHAT is True
22:40:06 DEBUG    errbot.core               Command not found
22:40:06 DEBUG    errbot.utils              Elapsed 0.005545 since last call
22:40:06 DEBUG    errbot.utils              Wait 0.994455 due to rate limiting...
22:40:07 DEBUG    irc.client                TO SERVER: PRIVMSG NickServ :Command "This" / "This nickname" not found.
22:40:07 DEBUG    errbot.core               Triggering callback_message on Flows

............................skipped
22:40:07 DEBUG    irc.client                FROM SERVER: :NickServ!NickServ@services. NOTICE botka :You are now identified for botka.
22:40:07 DEBUG    irc.client                _dispatcher: all_raw_messages
22:40:07 DEBUG    irc.client                command: privnotice, source: NickServ!NickServ@services., target: botka, arguments: ['You are now identified for \x02botka\x02.'], tags: None
22:40:07 DEBUG    irc.client                _dispatcher: privnotice
22:40:07 DEBUG    errbot.core               *** frm = NickServ!NickServ@services.
22:40:07 DEBUG    errbot.core               *** username = NickServ
22:40:07 DEBUG    errbot.core               *** text = You are now identified for botka.
22:40:07 DEBUG    errbot.core               Assuming 'You are now identified for botka.' to be a command because BOT_PREFIX_OPTIONAL_ON_CHAT is True
22:40:07 DEBUG    errbot.core               Command not found
22:40:07 DEBUG    errbot.utils              Elapsed 0.014732 since last call
22:40:07 DEBUG    errbot.utils              Wait 0.985268 due to rate limiting...
22:40:08 DEBUG    irc.client                TO SERVER: PRIVMSG NickServ :Command "You" / "You are" not found.

............afterwards

22:40:20 DEBUG    irc.client                FROM SERVER: :NickServ!NickServ@services. NOTICE botka :Invalid command. Use /msg NickServ help for a command listing.
22:40:20 DEBUG    irc.client                _dispatcher: all_raw_messages
22:40:20 DEBUG    irc.client                command: privnotice, source: NickServ!NickServ@services., target: botka, arguments: ['Invalid command. Use \x02/msg NickServ help\x02 for a command listing.'], tags: None
22:40:20 DEBUG    irc.client                _dispatcher: privnotice
22:40:20 DEBUG    errbot.core               *** frm = NickServ!NickServ@services.
22:40:20 DEBUG    errbot.core               *** username = NickServ
22:40:20 DEBUG    errbot.core               *** text = Invalid command. Use /msg NickServ help for a command listing.
22:40:20 DEBUG    errbot.core               Assuming 'Invalid command. Use /msg NickServ help for a command listing.' to be a command because BOT_PREFIX_OPTIONAL_ON_CHAT is True
22:40:20 DEBUG    errbot.core               Command not found
22:40:20 DEBUG    errbot.utils              Elapsed 0.015257 since last call
22:40:20 DEBUG    errbot.utils              Wait 0.984743 due to rate limiting...
22:40:21 DEBUG    irc.client                TO SERVER: PRIVMSG NickServ :Command "Invalid" / "Invalid command." not found.
22:40:21 DEBUG    errbot.core               Triggering callback_message on Flows
.............skpped
22:40:21 DEBUG    irc.client                FROM SERVER: :NickServ!NickServ@services. NOTICE botka :Invalid command. Use /msg NickServ help for a command listing.
4

2 回答 2

1

我用过滤器插件做到了这一点;在配置中,我有一个要忽略的用户列表:

from errbot import BotPlugin, cmdfilter

IGNORE_COMMAND = (None, None, None)

class IgnoreUsers(BotPlugin):
    """Command filter that causes blocks any response to zombot."""

    @cmdfilter
    def ignore_users(self, msg, cmd, args, dry_run):
        """
        Check command to see if it came from zombot, and if so block it

        :param msg: The original chat message.
        :param cmd: The command name itself.
        :param args: Arguments passed to the command.
        :param dry_run: True when this is a dry-run.
        """
        for user in self.bot_config.IGNORE_USERS:
            if msg.frm.person == user:
                self.log.info("Ignored %s from %s." % (cmd, user))
                return IGNORE_COMMAND # didn't hear a thing
        return msg, cmd, args # ok, don't ignore it
于 2018-11-30T16:50:23.207 回答
0

我需要更仔细地阅读文档: SUPPRESS_CMD_NOT_FOUND = True虽然关于忽略特定用户/消息的问题仍然存在,但会成功。

于 2018-08-15T10:46:04.053 回答