diff --git a/omnibot/bot.py b/omnibot/bot.py index 675b4d3..49a1490 100644 --- a/omnibot/bot.py +++ b/omnibot/bot.py @@ -135,10 +135,27 @@ class Bot: # Don't raise on_message events for ourselves. return line = message.parameters[1] - # Filter plugins by get_message_types() and channel + + # TL;DR OF THE BELOW: if the first parameter looks like a channel in + # addition to message type, then filter by channel. Otherwise, don't + # filter by channel. + # + # Here's the issue: plugins are *usually* multiplexed by channel. But + # that's only for messages that target channels, such as PRIVMSG and + # JOIN. For non-channel messages, such as server status messages (such + # as 001 on connect, or 372 for MOTD, etc) we want to ignore the channel + # aspect of plugin multiplexing. + # In order to accomplish this, we just check if the first parameter + # looks like a channel - i.e., starts with an octothorpe #. + if channel and channel[0] == "#": + plugin_pool = self.channel_plugins(channel) + else: + plugin_pool = self.plugins + + # Filter plugins by get_message_types() plugins = [ plugin - for plugin in self.channel_plugins(channel) + for plugin in plugin_pool if message.command in plugin.get_message_types() ] if plugins: diff --git a/omnibot/plugin.py b/omnibot/plugin.py index b515bd0..aa2fe78 100644 --- a/omnibot/plugin.py +++ b/omnibot/plugin.py @@ -58,6 +58,9 @@ class Plugin: def send_to(self, conn: IrcProtocol, who: str, message: str): message = Message(None, None, "PRIVMSG", who, message[:1024]) + self.send_message(conn, message) + + def send_message(self, conn: IrcProtocol, message: Message): conn.send(str(message)) async def on_join(self, conn: IrcProtocol, channel: str, who: Prefix):