From 5d10ee39be4bca0a9f5983398bf07e9c52ea5626 Mon Sep 17 00:00:00 2001 From: James Lu Date: Tue, 28 Mar 2017 22:18:51 -0700 Subject: [PATCH] ServiceBot: make displaying unknown command errors optional Closes #441. --- example-conf.yml | 7 +++++++ utils.py | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/example-conf.yml b/example-conf.yml index 3015837..b9e5a38 100644 --- a/example-conf.yml +++ b/example-conf.yml @@ -68,6 +68,9 @@ pylink: #plugin_dirs: ["~/my-plugins", "~/pylink-contrib-modules/plugins"] #protocol_dirs: ["~/pylink-contrib-modules/protocols"] + # Determines whether we should show unknown command errors for service bots. Defaults to True. + #show_unknown_commands: true + login: # NOTE: for users migrating from PyLink < 1.1, the old login:user/login:password settings # have been deprecated. We strongly recommend migrating to the new "accounts:" block below, as @@ -685,6 +688,10 @@ automode: # block. #respond_to_nick: true + # Determines whether we should show unknown command errors for this service bot. Defaults to True. + # This overrides the "show_unknown_commands" option in the "pylink:" config block. + #show_unknown_commands: true + games: # Sets the nick of the Games service, if you're using it. This defaults to "games" if not defined. nick: Games diff --git a/utils.py b/utils.py index 80e37a4..9181c97 100644 --- a/utils.py +++ b/utils.py @@ -335,7 +335,12 @@ class ServiceBot(): cmd = cmd_args[0].lower() cmd_args = cmd_args[1:] if cmd not in self.commands: - if cmd and not cmd.startswith('\x01'): + # XXX: we really need abstraction for this kind of config fetching... + show_unknown_cmds = irc.serverdata.get('%s_show_unknown_commands' % self.name, + conf.conf.get(self.name, {}).get('show_unknown_commands', + conf.conf['pylink'].get('show_unknown_commands', True))) + + if cmd and show_unknown_cmds and not cmd.startswith('\x01'): # Ignore empty commands and invalid command errors from CTCPs. self.reply(irc, 'Error: Unknown command %r.' % cmd) log.info('(%s/%s) Received unknown command %r from %s', irc.name, self.name, cmd, irc.getHostmask(source))