Small fix for plugins that accept non-channel messages
There's a long explanation in the code of this commit that says this: > 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 #. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user