From: CMDR furrycat Date: Wed, 30 Aug 2017 12:41:48 +0000 (+0100) Subject: Added on_typing() and non_command_message() methods. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=9ca3511fd5a7fb31c636109f9c45a9099f9a0211;p=furrycat%2Fcatbot.git Added on_typing() and non_command_message() methods. Plugins can implement on_typing() to react to a client typing. Plugins can implement non_command_message() to handle a message that mentions the bot but was not recognised as a command. --- diff --git a/app.py b/app.py index b9d7630..814caef 100644 --- a/app.py +++ b/app.py @@ -328,6 +328,17 @@ def mentioned_in(message, explicit = True): return True @client.event +async def on_typing(channel, user, when): + if user.id == client.user.id: + return + if user.bot: + return + if channel.is_private: + return + log.debug('{} is typing in {}'.format(user, channel)) + await plugins.on_typing(channel, user, when) + +@client.event async def on_message(message): if message.author.id == client.user.id: return @@ -350,6 +361,7 @@ async def on_message(message): m = re.match(r'^(\S+)', raw) if m is None: + await plugins.non_command_message(message) return command = m.group(1) result = await builtin_commands(message, command, raw) diff --git a/plugins.py b/plugins.py index 1e12be9..03f7e4c 100644 --- a/plugins.py +++ b/plugins.py @@ -18,9 +18,11 @@ class Plugins(object): 'on_ready', 'on_member_join', 'on_member_update', + 'on_typing', 'handle_command', 'handle_help', 'eddn_message', + 'non_command_message', 'not_our_message' ] self.plugins_supporting_methods = {} @@ -136,6 +138,10 @@ class Plugins(object): for name in self.method_cache('on_member_update'): asyncio.ensure_future(self.call_coroutine(name, 'on_member_update', before, after)) + async def on_typing(self, channel, user, when): + for name in self.method_cache('on_typing'): + asyncio.ensure_future(self.call_coroutine(name, 'on_typing', channel, user, when)) + # Plugin can return True to force skipping other handlers. async def handle_command(self, message, command, raw): for name in self.method_cache('handle_command'): @@ -154,6 +160,11 @@ class Plugins(object): log.debug('Plugin {} handled command {}.'.format(name, command)) continue + async def non_command_message(self, message): + for name in self.plugins(): + if self.has_method(name, 'non_command_message'): + asyncio.ensure_future(self.call_coroutine(name, 'non_command_message', message)) + async def not_our_message(self, message): for name in self.plugins(): if self.has_method(name, 'not_our_message'):