From: Egor Date: Sat, 17 Aug 2024 22:07:55 +0000 (+0300) Subject: spam.lua: refactor basic filters X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=cd27316f959b0ab595bcbbe5e099da11b1a918e9;p=patchyircd.git spam.lua: refactor basic filters --- diff --git a/lua/spam.lua b/lua/spam.lua index 488b3d4..bb73106 100644 --- a/lua/spam.lua +++ b/lua/spam.lua @@ -6,22 +6,8 @@ local function ascii(txt) txt = txt:gsub("[^ -~]", ""):lower() return txt end -function setspamlevel(newlevel) - spamlevel = newlevel - hook_add("sendtochannel", "supernets_filter", spamlevel >= 10 and function(hook, cl1, cl2, chan, txt) - if cl1.umode & 2 ~= 0 then -- UMODE_OPER - return 0 - end - if cl1.umode & 8 ~= 0 then -- UMODE_REGISTERED - return 0 - end - txt = ascii(txt) - if not chan.v[cl1.key] and not chan.o[cl1.key] and - txt:find("irc.supernets.org", 1, true) then - return -1 - end - end) - hook_add("sendtoclient", "supernets_pm_filter", spamlevel >= 10 and function(hook, cl1, cl2, chan, txt) +local function simple_filter(id, badword, level) + hook_add("sendtochannel", id.."_filter", spamlevel >= level and function(hook, cl1, cl2, chan, txt) if cl1.umode & 2 ~= 0 then -- UMODE_OPER return 0 end @@ -29,11 +15,11 @@ function setspamlevel(newlevel) return 0 end txt = ascii(txt) - if txt:find("irc.supernets.org", 1, true) then + if not chan.v[cl1.key] and not chan.o[cl1.key] and txt:find(badword, 1, true) then return -1 end end) - hook_add("sendtochannel", "hardchats_filter", spamlevel >= 10 and function(hook, cl1, cl2, chan, txt) + hook_add("sendtoclient", id.."_pm_filter", spamlevel >= level and function(hook, cl1, cl2, chan, txt) if cl1.umode & 2 ~= 0 then -- UMODE_OPER return 0 end @@ -41,48 +27,16 @@ function setspamlevel(newlevel) return 0 end txt = ascii(txt) - if txt:find("hardchats.com", 1, true) or txt:find("hardchat", 1, true) then - return -1 - end - end) - hook_add("sendtoclient", "hardchats_pm_filter", spamlevel >= 10 and function(hook, cl1, cl2, chan, txt) - if cl1.umode & 2 ~= 0 then -- UMODE_OPER - return 0 - end - if cl1.umode & 8 ~= 0 then -- UMODE_REGISTERED - return 0 - end - txt = ascii(txt) - if not chan.v[cl1.key] and not chan.o[cl1.key] and - (txt:find("hardchats.com", 1, true) or txt:find("hardchat", 1, true)) then - return -1 - end - end) - hook_add("sendtochannel", "l0de_radio_hour_filter", spamlevel >= 10 and function(hook, cl1, cl2, chan, txt) - if cl1.umode & 2 ~= 0 then -- UMODE_OPER - return 0 - end - if cl1.umode & 8 ~= 0 then -- UMODE_REGISTERED - return 0 - end - txt = ascii(txt) - if not chan.v[cl1.key] and not chan.o[cl1.key] and - (txt:find("1-877-293-1933", 1, true)) then - return -1 - end - end) - hook_add("sendtoclient", "l0de_radio_hour_pm_filter", spamlevel >= 10 and function(hook, cl1, cl2, chan, txt) - if cl1.umode & 2 ~= 0 then -- UMODE_OPER - return 0 - end - if cl1.umode & 8 ~= 0 then -- UMODE_REGISTERED - return 0 - end - txt = ascii(txt) - if txt:find("1-877-293-1933", 1, true) then + if txt:find(badword, 1, true) then return -1 end end) +end +function setspamlevel(newlevel) + spamlevel = newlevel + simple_filter("supernets", "irc.supernets.org", 10) + simple_filter("hardchats", "hardchat", 10) + simple_filter("l0de_radio_hour", "1-877-293-1933", 10) hook_add("sendtoclient", "no_unsolicited_pm", spamlevel >= 20 and function(hook, cl1, cl2, chan, txt) if cl1.umode & 2 ~= 0 then -- UMODE_OPER return 0