From 31a1315ebca2622f35ef2ba18fb1bb990b9a6ff3 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Tue, 13 Nov 2018 20:31:54 +0000 Subject: #47: Don't trigger URL filtering on a single message. --- bot/rules/links.py | 16 +++++++++++++--- config-default.yml | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bot/rules/links.py b/bot/rules/links.py index dfeb38c61..fa4043fcb 100644 --- a/bot/rules/links.py +++ b/bot/rules/links.py @@ -20,9 +20,19 @@ async def apply( for msg in recent_messages if msg.author == last_message.author ) - total_links = sum(len(LINK_RE.findall(msg.content)) for msg in relevant_messages) - - if total_links > config['max']: + total_links = 0 + messages_with_links = 0 + + for msg in relevant_messages: + total_matches = len(LINK_RE.findall(msg.content)) + if total_matches: + messages_with_links += 1 + total_links += total_matches + + # Only apply the filter if we found more than one message with + # links to prevent wrongfully firing the rule on users posting + # e.g. an installation log of pip packages from GitHub. + if total_links > config['max'] and messages_with_links > 1: return ( f"sent {total_links} links in {config['interval']}s", (last_message.author,), diff --git a/config-default.yml b/config-default.yml index 046c1ea56..c04571482 100644 --- a/config-default.yml +++ b/config-default.yml @@ -288,7 +288,7 @@ anti_spam: links: interval: 10 - max: 20 + max: 10 mentions: interval: 10 -- cgit v1.2.3