aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGravatar jesopo2019-09-05 14:14:21 +0100
committerGravatar jesopo2019-09-05 14:14:21 +0100
commit6e4ec91003e3a9bb1baa6a9363f5eee5f563f615 (patch)
tree3ae5c8a0fa98420e4168c58be0456d17ce07f5c3 /modules
parentadd a `create` flag to IRCChannels.get_id() to optionally not create new ids (diff)
signature
add channel_blacklist.py
Diffstat (limited to 'modules')
-rw-r--r--modules/channel_blacklist.py30
1 files changed, 30 insertions, 0 deletions
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