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.
|
# Don't raise on_message events for ourselves.
|
||||||
return
|
return
|
||||||
line = message.parameters[1]
|
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 = [
|
plugins = [
|
||||||
plugin
|
plugin
|
||||||
for plugin in self.channel_plugins(channel)
|
for plugin in plugin_pool
|
||||||
if message.command in plugin.get_message_types()
|
if message.command in plugin.get_message_types()
|
||||||
]
|
]
|
||||||
if plugins:
|
if plugins:
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ class Plugin:
|
|||||||
|
|
||||||
def send_to(self, conn: IrcProtocol, who: str, message: str):
|
def send_to(self, conn: IrcProtocol, who: str, message: str):
|
||||||
message = Message(None, None, "PRIVMSG", who, message[:1024])
|
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))
|
conn.send(str(message))
|
||||||
|
|
||||||
async def on_join(self, conn: IrcProtocol, channel: str, who: Prefix):
|
async def on_join(self, conn: IrcProtocol, channel: str, who: Prefix):
|
||||||
|
|||||||
Reference in New Issue
Block a user