def handle_message(self, message: MessageEvent, reply_channel: Callable[[FriskyResponse], bool]) -> None: if message.channel_name in self.ignored_channels or message.username == self.name: return message.command, message.args = self.parse_message_string(message.text) if message.command != '': plugins = self.get_plugins_for_command(message.command) if len(plugins) == 0: # Reformat the message as a generic one message = self.convert_message_to_generic(message) plugins = self.get_generic_handlers() for plugin in plugins: reply = plugin.handle_message(message) if reply is not None: reply_channel(reply)
def handle_message_synchronously(self, message: MessageEvent) -> List[FriskyResponse]: message.command, message.args = self.parse_message_string(message.text) replies = [] if message.command != '': plugins = self.get_plugins_for_command(message.command) if len(plugins) == 0: # Reformat the message as a generic one message = self.convert_message_to_generic(message) plugins = self.get_generic_handlers() for plugin in plugins: reply = plugin.handle_message(message) if reply is not None: replies.append(reply) return replies
def convert_message_to_generic(message: MessageEvent) -> MessageEvent: message.args = [message.command] + message.args message.command = '*' return message