From 6e4ec91003e3a9bb1baa6a9363f5eee5f563f615 Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 5 Sep 2019 14:14:21 +0100 Subject: [PATCH] add channel_blacklist.py --- modules/channel_blacklist.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 modules/channel_blacklist.py diff --git a/modules/channel_blacklist.py b/modules/channel_blacklist.py new file mode 100644 index 00000000..aa3213f3 --- /dev/null +++ b/modules/channel_blacklist.py @@ -0,0 +1,30 @@ +from src import EventManager, ModuleManager, utils + +@utils.export("channelset", utils.BoolSetting("blacklist", + "Refuse to join a given channel")) +class Module(ModuleManager.BaseModule): + @utils.hook("preprocess.send.join") + @utils.kwarg("priority", EventManager.PRIORITY_HIGH) + def preprocess_send_join(self, event): + if event["line"].args: + channels = event["line"].args[0].split(",") + keys = event["line"].args[1:] + + remove = [] + for channel_name in channels: + id = event["server"].channels.get_id(channel_name, create=False) + if not id == None: + if self.bot.database.channel_settings.get(id, "blacklist", + False): + remove.append(channel_name) + if keys: + keys.pop(0) + for channel_name in remove: + channels.remove(channel_name) + + if remove: + if not channels: + event["line"].invalidate() + else: + event["line"].args[0] = ",".join(channels) + event["line"].args[1:] = keys