]> PatchyGit - patchyircd.git/commitdiff
move spam filtering to a separate module
authorEgor <egor@patchysicp.xyz>
Tue, 23 Jan 2024 10:50:25 +0000 (12:50 +0200)
committerEgor <egor@patchysicp.xyz>
Tue, 23 Jan 2024 11:15:04 +0000 (13:15 +0200)
lua/init.lua
lua/spam.lua [new file with mode: 0644]

index bd2c5df..165e133 100644 (file)
@@ -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 (file)
index 0000000..749c4b5
--- /dev/null
@@ -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