diff --git a/example.config.yml b/example.config.yml index 5479b1e..df668d8 100644 --- a/example.config.yml +++ b/example.config.yml @@ -13,21 +13,21 @@ ban_message: "You have been banned from The Coding Den. Reason: `%s`.\nTo appeal groups: - name: badware mode: delete - words: - - skype - - teamspeak + phrases: + - \w*skype\w* + - \w*teamspeak\w* whitelist: - discord - name: spam mode: softban - words: - - somepornsite101010.com + phrases: + - \w*somepornsite101010.com\w* whitelist: - discord - name: slurs mode: log - words: - - jap + phrases: + - \w*jap\w* whitelist: - japan message_cache_config: @@ -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 diff --git a/src/command.cr b/src/command.cr index a999726..aafca50 100644 --- a/src/command.cr +++ b/src/command.cr @@ -175,17 +175,26 @@ 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 regex=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..] + 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}`." + 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