aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2017-12-26 11:50:18 +0000
committerGravatar jesopo2017-12-26 11:50:18 +0000
commit14ffa6716df69ccccb60c97710b6a31d07a07df4 (patch)
tree0df1e2218e98b5b70a33f38bc4318736ec94aaa3
parentAdded a "replay" system to EventManager hooks, to replay missed .calls (diff)
signature
Added highlight spam detection/prevention logic to channel_op
-rw-r--r--Utils.py4
-rw-r--r--modules/channel_op.py22
2 files changed, 25 insertions, 1 deletions
diff --git a/Utils.py b/Utils.py
index 03b7bd31..1e0e90b3 100644
--- a/Utils.py
+++ b/Utils.py
@@ -183,6 +183,10 @@ def bool_or_none(s):
return True
elif s in IS_FALSE:
return False
+def int_or_none(s):
+ stripped_s = s.lstrip("0")
+ if stripped_s.isdigit():
+ return int(stripped_s)
def get_closest_setting(event, setting, default=None):
server = event["server"]
diff --git a/modules/channel_op.py b/modules/channel_op.py
index 68391052..d24314d5 100644
--- a/modules/channel_op.py
+++ b/modules/channel_op.py
@@ -1,4 +1,4 @@
-
+import Utils
class Module(object):
_name = "Channel Op"
@@ -21,6 +21,16 @@ class Module(object):
).hook(self.voice, channel_only=True, require_mode="o")
bot.events.on("received").on("command").on("devoice"
).hook(self.devoice, channel_only=True, require_mode="o")
+ bot.events.on("received").on("message").on("channel").hook(self.highlight_spam)
+
+ bot.events.on("postboot").on("configure").on(
+ "channelset").call(setting="highlight-spam-threshold",
+ help="Set the number of nicknames in a message that qualifies as spam",
+ validate=Utils.int_or_none)
+ bot.events.on("postboot").on("configure").on(
+ "channelset").call(setting="highlight-spam-protection",
+ help="Enable/Disable highligh spam protection",
+ validate=Utils.bool_or_none)
def kick(self, event):
target = event["args_split"][0]
@@ -69,3 +79,13 @@ class Module(object):
target = event["user"].nickname if not event["args_split"] else event[
"args_split"][0]
event["target"].send_mode("-v", target)
+
+ def highlight_spam(self, event):
+ nicknames = list(map(lambda user: user.nickname, event["channel"].users)
+ ) + [event["server"].nickname]
+ if len(set(nicknames) & set(event["message_split"])) >= event["channel"].get_setting(
+ "highlight-spam-threshold", 10):
+ if event["channel"].get_setting("highlight-spam-protection", False):
+ if not event["channel"].mode_or_above(event["user"].nickname, "v"):
+ event["channel"].send_kick(event["user"].nickname,
+ "highlight spam detected")