Skip to content

Commit

Permalink
Improved censor (refs #87)
Browse files Browse the repository at this point in the history
* fixed case insensitivity
* updated some default censor rules
  • Loading branch information
timosmit committed Feb 12, 2019
1 parent 0bcc454 commit 1976135
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 6 additions & 6 deletions config/censor.toml
@@ -1,24 +1,24 @@
# words
[[word]]
pattern = "f[%a%p]-ck" # fuck and similar
pattern = "f[u*]-ck" # 'fuck' and similar

[[word]]
pattern = "homo"

[[word]]
pattern = "gay"
pattern = "g[a4]y" # 'gay' and similar

[[word]]
pattern = "fag"
pattern = "f[a4]g" # 'fag' and similar

[[word]]
pattern = "shit"
pattern = "sh[i1*]t" # 'shit' and similar

[[word]]
pattern = "bitch"
pattern = "b[i1*]tch" # 'bitch' and similar

[[word]]
pattern = "asshole"
pattern = "asshole" # 'asshole' and similar

# names
[[name]]
Expand Down
10 changes: 7 additions & 3 deletions luascripts/wolfadmin/admin/censor.lua
Expand Up @@ -37,11 +37,15 @@ function censor.filter(dictionary, subject)
local censored = false

for _, item in ipairs(dictionary) do
local occurrences
local pos1, pos2 = string.find(string.lower(subject), item["pattern"])

subject, occurrences = string.gsub(subject, item["pattern"], "*censor*")
while pos1 and pos2 do
subject = string.sub(subject, 1, pos1 - 1).."*censor*"..string.sub(subject, pos2 + 1)

censored = (censored or occurrences > 0) and true or false
pos1, pos2 = string.find(string.lower(subject), item["pattern"])

censored = true
end
end

return censored, subject
Expand Down

0 comments on commit 1976135

Please sign in to comment.