From 5d4070cfc025b3a6dd725c8b91598cc402c9ec3b Mon Sep 17 00:00:00 2001 From: Jonathan B Date: Tue, 12 Oct 2021 16:14:24 +0200 Subject: [PATCH 1/4] I give to you the power of regex I always meant to implement this, but it somehow got lost somewhere along the way. But LW including a `|`, and thus causing anyone who mentions `Discord Nitro` or `Steam Store` to get banned, and making me look for a bug at first, made me realize, we never got around to it. Luckily no false positive bans caused by this though :akek: Welp, never thought mini slash would still be in use in 2021, especially after it came practically useless after the switch to zeppelin. --- src/command.cr | 15 ++++++++++----- src/slash.cr | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/command.cr b/src/command.cr index a999726..e6e3b8e 100644 --- a/src/command.cr +++ b/src/command.cr @@ -175,17 +175,22 @@ class Slash when "word" case cmd[1]? when "add" - # `word add [group] [phrase]` + # `word add [group] [phrase] [regex=false]` + # eg `word add log abc|test true` group = cmd[2]? phrase_existence = cmd[3]? if group && !@groups.has_key? group m = "Group does not exist" - elsif group && phrase_existence && @groups[group].add_phrase(cmd[3..].join(" ")) - write - m = "Successfully added `#{cmd[3..].join(" ")}` to group `#{group}`." + elsif group && phrase_existence + raw_phrase = cmd[3..] + phrase = raw_phrase.last.ends_with?("true") ? raw_phrase[..-2].join(" ") : Regex.escape(raw_phrase.join(" ")) + if @groups[group].add_phrase(phrase) + write + m = "Successfully added `#{phrase}` to group `#{group}`." + end else - m = "Unable to add phrase. Syntax: `word add [group] [phrase]`" + m = "Unable to add phrase. Syntax: `word add [group] [phrase] [regex=false]`" end when "delete", "remove" # `word delete [group] [phrase]` diff --git a/src/slash.cr b/src/slash.cr index e8c9b20..0995f22 100644 --- a/src/slash.cr +++ b/src/slash.cr @@ -142,7 +142,7 @@ class Slash @groups.each_value do |group| word = nil group.phrases.each do |y| - if matchdata = content.match(/\w*#{y}\w*/i) + if matchdata = content.match(/#{y}/i) match = matchdata[0]? next if group.whitelist.any?(match.downcase) if match word = y From f90fe122507dd02c7a495da58c58f45a29a40805 Mon Sep 17 00:00:00 2001 From: Jonathan B Date: Mon, 25 Oct 2021 21:25:21 +0200 Subject: [PATCH 2/4] change format to regex=true --- src/command.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/command.cr b/src/command.cr index e6e3b8e..6ff4422 100644 --- a/src/command.cr +++ b/src/command.cr @@ -176,7 +176,7 @@ class Slash case cmd[1]? when "add" # `word add [group] [phrase] [regex=false]` - # eg `word add log abc|test true` + # eg `word add log abc|test regex=true` group = cmd[2]? phrase_existence = cmd[3]? @@ -184,7 +184,7 @@ class Slash m = "Group does not exist" elsif group && phrase_existence raw_phrase = cmd[3..] - phrase = raw_phrase.last.ends_with?("true") ? raw_phrase[..-2].join(" ") : Regex.escape(raw_phrase.join(" ")) + phrase = raw_phrase.last.ends_with?("regex=true") ? raw_phrase[..-2].join(" ") : Regex.escape(raw_phrase.join(" ")) if @groups[group].add_phrase(phrase) write m = "Successfully added `#{phrase}` to group `#{group}`." From 43f4e566c826e9fdca8eab4694597b71783427b8 Mon Sep 17 00:00:00 2001 From: greenbigfrog Date: Sun, 12 Jun 2022 17:16:24 +0200 Subject: [PATCH 3/4] fix example config --- example.config.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/example.config.yml b/example.config.yml index 5479b1e..95faf13 100644 --- a/example.config.yml +++ b/example.config.yml @@ -13,20 +13,20 @@ ban_message: "You have been banned from The Coding Den. Reason: `%s`.\nTo appeal groups: - name: badware mode: delete - words: + phrases: - skype - teamspeak whitelist: - discord - name: spam mode: softban - words: + phrases: - somepornsite101010.com whitelist: - discord - name: slurs mode: log - words: + phrases: - jap whitelist: - japan @@ -38,4 +38,4 @@ message_cache_config: similarity_threshold: 60 max_time_diff_minutes: 3 max_size_diff_percentage: 30 - ignored_channels: [856970378545725463] + ignored_channels: [856970378545725463] \ No newline at end of file From e4ab5f8af76e7a18a01b0b17c37965b52d3c1a23 Mon Sep 17 00:00:00 2001 From: greenbigfrog Date: Sun, 12 Jun 2022 17:55:22 +0200 Subject: [PATCH 4/4] fix regex matching for normal phrases --- example.config.yml | 8 ++++---- src/command.cr | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/example.config.yml b/example.config.yml index 95faf13..df668d8 100644 --- a/example.config.yml +++ b/example.config.yml @@ -14,20 +14,20 @@ groups: - name: badware mode: delete phrases: - - skype - - teamspeak + - \w*skype\w* + - \w*teamspeak\w* whitelist: - discord - name: spam mode: softban phrases: - - somepornsite101010.com + - \w*somepornsite101010.com\w* whitelist: - discord - name: slurs mode: log phrases: - - jap + - \w*jap\w* whitelist: - japan message_cache_config: diff --git a/src/command.cr b/src/command.cr index 6ff4422..aafca50 100644 --- a/src/command.cr +++ b/src/command.cr @@ -184,7 +184,11 @@ class Slash m = "Group does not exist" elsif group && phrase_existence raw_phrase = cmd[3..] - phrase = raw_phrase.last.ends_with?("regex=true") ? raw_phrase[..-2].join(" ") : Regex.escape(raw_phrase.join(" ")) + if raw_phrase.last.ends_with?("regex=true") + phrase = raw_phrase[..-2].join(" ") + else + phrase = "\\w*#{Regex.escape(raw_phrase.join(" "))}\\w*" + end if @groups[group].add_phrase(phrase) write m = "Successfully added `#{phrase}` to group `#{group}`."