Add get_message_types() to plugin API
This allows plugins to specify the types of messages they handle. This will be used specifically for the nickserv plugin, but could be useful for other things too. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -61,7 +61,7 @@ class Bot:
|
||||
self.connection.register("JOIN", self.on_join)
|
||||
self.connection.register("PART", self.on_part)
|
||||
self.connection.register("KICK", self.on_kick)
|
||||
self.connection.register("PRIVMSG", self.on_message)
|
||||
self.connection.register("*", self.on_message)
|
||||
# Connect
|
||||
log.info("Connecting to %s", self.server_config.server)
|
||||
await self.connection.connect()
|
||||
@@ -135,10 +135,16 @@ class Bot:
|
||||
# Don't raise on_message events for ourselves.
|
||||
return
|
||||
line = message.parameters[1]
|
||||
plugins = self.channel_plugins(channel)
|
||||
await asyncio.gather(
|
||||
*[plugin.on_message(conn, channel, who, line) for plugin in plugins]
|
||||
)
|
||||
# Filter plugins by get_message_types() and channel
|
||||
plugins = [
|
||||
plugin
|
||||
for plugin in self.channel_plugins(channel)
|
||||
if message.command in plugin.get_message_types()
|
||||
]
|
||||
if plugins:
|
||||
await asyncio.gather(
|
||||
*[plugin.on_message(conn, channel, who, line) for plugin in plugins]
|
||||
)
|
||||
|
||||
async def keepalive(self):
|
||||
# loop while we're connected, check every second
|
||||
|
||||
Reference in New Issue
Block a user