aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2020-05-31 02:16:59 +0100
committerGravatar jesopo2020-05-31 02:16:59 +0100
commit3d4d20872bac491dd6e8cb98e4edcfd9a563192e (patch)
tree97c97853df36488f045a822e981fce836d11133c
parent+draft/typing has been ratified (diff)
signature
add ban_enforce.py, to kick people affected by new bans
-rw-r--r--modules/ban_enforce.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/modules/ban_enforce.py b/modules/ban_enforce.py
new file mode 100644
index 00000000..4e40bb84
--- /dev/null
+++ b/modules/ban_enforce.py
@@ -0,0 +1,27 @@
+from src import ModuleManager, utils
+
+REASON = "User is banned from this channel"
+
+@utils.export("channelset", utils.BoolSetting("ban-enforce",
+ "Whether or not to parse new bans and kick who they affect"))
+class Module(ModuleManager.BaseModule):
+ @utils.hook("received.mode.channel")
+ def on_mode(self, event):
+ if event["channel"].get_setting("ban-enforce", False):
+ bans = []
+ kicks = set([])
+ for mode, arg in event["modes"]:
+ if mode[0] == "+" and mode[1] == "b":
+ bans.append(arg)
+
+ if bans:
+ umasks = {u.hostmask(): u for u in event["channel"].users}
+ for ban in bans:
+ mask = utils.irc.hostmask_parse(ban)
+ matches = list(utils.irc.hostmask_match_many(
+ umasks.keys(), mask))
+ for match in matches:
+ kicks.add(umasks[match])
+ if kicks:
+ nicks = [u.nickname for u in kicks]
+ event["channel"].send_kicks(sorted(nicks), REASON)