diff options
| author | 2018-11-13 20:31:54 +0000 | |
|---|---|---|
| committer | 2018-11-13 20:31:54 +0000 | |
| commit | e4a8647ebdc477ba095c73d582860ca89a3fe787 (patch) | |
| tree | dc6ea8f3954d661509ea18c1f3656585252ee0eb | |
| parent | Merge branch 'scheduling-cleanup' into 'master' (diff) | |
| parent | #47: Don't trigger URL filtering on a single message. (diff) | |
Merge branch 'issue/47-no-url-filter-trigger-on-single-message' into 'master'
#47: Don't trigger URL filtering on a single message.
See merge request python-discord/projects/bot!85
| -rw-r--r-- | bot/rules/links.py | 16 | ||||
| -rw-r--r-- | 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 |