Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions example.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]
19 changes: 14 additions & 5 deletions src/command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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]`
Expand Down
2 changes: 1 addition & 1 deletion src/slash.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down