Improved censor (refs #87)

* fixed case insensitivity
* updated some default censor rules
This commit is contained in:
Timo Smit 2019-02-12 13:06:17 +01:00
parent 0bcc4543d7
commit 19761350ab
2 changed files with 13 additions and 9 deletions

View file

@ -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]]

View file

@ -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