From: CMDR furrycat Date: Mon, 17 Jul 2017 10:14:00 +0000 (+0100) Subject: Pass public messages without our mention to not_our_message() plugin method. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=d58b58d6a61c9a38fecd007565e6914fcd79ab6e;p=furrycat%2Fcatbot.git Pass public messages without our mention to not_our_message() plugin method. --- diff --git a/plugins.py b/plugins.py index 8a8a271..1e12be9 100644 --- a/plugins.py +++ b/plugins.py @@ -20,7 +20,8 @@ class Plugins(object): 'on_member_update', 'handle_command', 'handle_help', - 'eddn_message' + 'eddn_message', + 'not_our_message' ] self.plugins_supporting_methods = {} self.loaded = {} @@ -153,6 +154,20 @@ class Plugins(object): log.debug('Plugin {} handled command {}.'.format(name, command)) continue + async def not_our_message(self, message): + for name in self.plugins(): + if self.has_method(name, 'not_our_message'): + result = asyncio.ensure_future(self.call_coroutine(name, 'not_our_message', message)) + if result is PluginCommand.ignored: + log.debug('Plugin {} ignored message.'.format(name)) + continue + elif result is PluginCommand.exclusive: + log.info('Plugin {} handled message exclusively.'.format(name)) + return True + elif result is PluginCommand.handled: + log.debug('Plugin {} handled message.'.format(name)) + continue + async def handle_help(self, message, command, *args): for name in self.method_cache('handle_help'): if self.has_method(name, 'valid_commands'):