From fa279aab93c80b50c24d700c8d9d959399897371 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 14 Aug 2019 14:38:47 +0100 Subject: refactor/rewrite channel_op.py, split highlight spam protection out --- modules/highlight_spam.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 modules/highlight_spam.py (limited to 'modules/highlight_spam.py') 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") + -- cgit v1.3.1-10-gc9f91