aboutsummaryrefslogtreecommitdiff
path: root/modules/highlight_spam.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-08-14 14:38:47 +0100
committerGravatar jesopo2019-08-14 14:38:47 +0100
commitfa279aab93c80b50c24d700c8d9d959399897371 (patch)
tree12a449b394d921d157f70fdd6ad16b82502123a3 /modules/highlight_spam.py
parentalias !remindme to !in (diff)
refactor/rewrite channel_op.py, split highlight spam protection out
Diffstat (limited to 'modules/highlight_spam.py')
-rw-r--r--modules/highlight_spam.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/modules/highlight_spam.py b/modules/highlight_spam.py
new file mode 100644
index 00000000..8d02ee87
--- /dev/null
+++ b/modules/highlight_spam.py
@@ -0,0 +1,31 @@
+#--depends-on config
+
+from src import ModuleManager, utils
+
+@utils.export("channelset", utils.IntSetting("highlight-spam-threshold",
+ "Set the number of nicknames in a message that qualifies as spam"))
+@utils.export("channelset", utils.BoolSetting("highlight-spam-protection",
+ "Enable/Disable highlight spam protection"))
+@utils.export("channelset", utils.BoolSetting("highlight-spam-ban",
+ "Enable/Disable banning highlight spammers instead of just kicking"))
+class Module(ModuleManager.BaseModule):
+ @utils.hook("received.message.channel")
+ def highlight_spam(self, event):
+ if event["channel"].get_setting("highlight-spam-protection", False):
+ nicknames = list(map(lambda user: user.nickname,
+ event["channel"].users))
+
+ highlights = set(nicknames) & set(event["message_split"])
+ print(highlights)
+ if len(highlights) > 1 and len(highlights) >= event["channel"
+ ].get_setting("highlight-spam-threshold", 10):
+ has_mode = event["channel"].mode_or_above(event["user"], "v")
+ should_ban = event["channel"].get_setting("highlight-spam-ban",
+ False)
+ if not has_mode:
+ if should_ban:
+ event["channel"].send_ban("*!%s@%s" % (
+ event["user"].username, event["user"].hostname))
+ event["channel"].send_kick(event["user"].nickname,
+ "highlight spam detected")
+