From 1464b7a53fc8271702b0e48f44773ad9030d0939 Mon Sep 17 00:00:00 2001 From: Egor Date: Tue, 23 Jan 2024 12:50:25 +0200 Subject: [PATCH] move spam filtering to a separate module --- lua/init.lua | 53 +--------------------------------------------------- lua/spam.lua | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 52 deletions(-) create mode 100644 lua/spam.lua diff --git a/lua/init.lua b/lua/init.lua index bd2c5df..165e133 100644 --- a/lua/init.lua +++ b/lua/init.lua @@ -63,57 +63,6 @@ function commands.summon(client, source, command, args) channel_join(client_map[args[1]], args[2], true) end -if not spamlevel then - spamlevel = 0 -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 not chan.v[cl1.key] and not chan.o[cl1.key] and - (txt:find("irc.supernets.org", 1, true) or txt:find("IRC.SUPERNETS.ORG", 1, true)) then - return -1 - end - end) - 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 - end - if cl1.umode & 8 ~= 0 then -- UMODE_REGISTERED - return 0 - end - -- allow is cl1 has perms in any of the channels cl2 is in - for k, v in pairs(cl2.channels) do - if v.v[cl1.key] or v.o[cl1.key] then - return 0 - end - end - return -1 - end) - hook_add("sendtochannel", "globally_moderated", spamlevel >= 30 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 - if not chan.v[cl1.key] and not chan.o[cl1.key] then - return 1 - end - end) -end -setspamlevel(spamlevel) - -function commands.spam(client, source, command, args) - if args.n == 0 then - client_notice(client, "current spam protection level: "..tostring(spamlevel)) - else - setspamlevel(tonumber(args[1])) - client_notice(client, "new spam protection level: "..tostring(spamlevel)) - end -end - dofile "lua/irccloud.lua" dofile "lua/ctcp.lua" +dofile "lua/spam.lua" diff --git a/lua/spam.lua b/lua/spam.lua new file mode 100644 index 0000000..749c4b5 --- /dev/null +++ b/lua/spam.lua @@ -0,0 +1,52 @@ +-- spam filtering +if not spamlevel then + spamlevel = 0 +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 not chan.v[cl1.key] and not chan.o[cl1.key] and + (txt:find("irc.supernets.org", 1, true) or txt:find("IRC.SUPERNETS.ORG", 1, true)) then + return -1 + end + end) + 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 + end + if cl1.umode & 8 ~= 0 then -- UMODE_REGISTERED + return 0 + end + -- allow is cl1 has perms in any of the channels cl2 is in + for k, v in pairs(cl2.channels) do + if v.v[cl1.key] or v.o[cl1.key] then + return 0 + end + end + return -1 + end) + hook_add("sendtochannel", "globally_moderated", spamlevel >= 30 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 + if not chan.v[cl1.key] and not chan.o[cl1.key] then + return 1 + end + end) +end +setspamlevel(spamlevel) + +function commands.spam(client, source, command, args) + if args.n == 0 then + client_notice(client, "current spam protection level: "..tostring(spamlevel)) + else + setspamlevel(tonumber(args[1])) + client_notice(client, "new spam protection level: "..tostring(spamlevel)) + end +end -- 2.56.0