How to ignore specific messages or users in errbot?

285 Views Asked by At

I use current config with IRC freenode server:

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

and I use authentication for IRC services.

But when bot logs in it has a problem: when it identifies itself with NickServ the bot gets messages from NickServ which includes its nick and treats them as a command (because of BOT_PREFIX_OPTIONAL_ON_CHAT and BOT_ALT_PREFIXES). Then the errbot sends error message to NickServ about "wrong command" and NickServ replies that it does't understand "wrong command" to private of bot and it starts again...

So before these bots eats all internet traffic with this conversation, how can I exclude NickServ from this conversation or cause errbot not to reply with "wrong command" or any other solution?

Currently I use dirty hack in my plugin to cover "Invalid command" coming from NickServ:

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

and this prevents from errbot to reply to NickServ. Also need to use

HIDE_RESTRICTED_COMMANDS = True
HIDE_RESTRICTED_ACCESS = True

But I'm looking for better solution. Thanks in advance!

Logs from bots conversation:

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.
2

There are 2 best solutions below

0
On

I need to read documentation more carefully: SUPPRESS_CMD_NOT_FOUND = True will do the trick, although the question about ignoring specific users/messages still remains.

0
On

I did this with a filter plugin; in the configuration I have a list of users to ignore:

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