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

diff --git a/lua/ctcp.lua b/lua/ctcp.lua
new file mode 100644 (file)
index 0000000..df81634
--- /dev/null
@@ -0,0 +1,18 @@
+-- ctcp probe module
+function commands.refreshctcp(client, source, command, args)
+       local flags = args[2] and tonumber(args[2]) or 3
+       if args[1] and args[1] ~= "*" then
+               if flags&1 ~= 0 then client_privmsg(client_map[args[1]], "\1VERSION\1", "cia!cia@cia.gov") end
+               if flags&2 ~= 0 then client_privmsg(client_map[args[1]], "\1TIME\1", "cia!cia@cia.gov") end
+       else
+               for k, v in pairs(client_map) do
+                       if flags&1 ~= 0 then client_privmsg(v, "\1VERSION\1", "cia!cia@cia.gov") end
+                       if flags&2 ~= 0 then client_privmsg(v, "\1TIME\1", "cia!cia@cia.gov") end
+               end
+       end
+end
+hook_add("newuser", "ctcp_probe", function(hook, cl1, cl2, chan, txt)
+       client_privmsg(cl1, "\1VERSION\1", "cia!cia@cia.gov")
+       -- TODO: a delay mechanism to avoid getting ratelimited
+       client_privmsg(cl1, "\1TIME\1", "cia!cia@cia.gov")
+end)
index 004fde6..bd2c5df 100644 (file)
@@ -62,18 +62,6 @@ end
 function commands.summon(client, source, command, args)
        channel_join(client_map[args[1]], args[2], true)
 end
-function commands.refreshctcp(client, source, command, args)
-       local flags = args[2] and tonumber(args[2]) or 3
-       if args[1] and args[1] ~= "*" then
-               if flags&1 ~= 0 then client_privmsg(client_map[args[1]], "\1VERSION\1", "cia!cia@cia.gov") end
-               if flags&2 ~= 0 then client_privmsg(client_map[args[1]], "\1TIME\1", "cia!cia@cia.gov") end
-       else
-               for k, v in pairs(client_map) do
-                       if flags&1 ~= 0 then client_privmsg(v, "\1VERSION\1", "cia!cia@cia.gov") end
-                       if flags&2 ~= 0 then client_privmsg(v, "\1TIME\1", "cia!cia@cia.gov") end
-               end
-       end
-end
 
 if not spamlevel then
        spamlevel = 0
@@ -128,3 +116,4 @@ function commands.spam(client, source, command, args)
 end
 
 dofile "lua/irccloud.lua"
+dofile "lua/ctcp.lua"
index c86e01a..3b55bfd 100644 (file)
--- a/src/irc.c
+++ b/src/irc.c
@@ -1251,9 +1251,6 @@ void newUser(struct client_data *client) {
 #ifdef HAS_LUA
        admin_hook("newuser", client, 0, 0, 0);
 #endif
-       // send CTCP VERSION and CTCP TIME
-       msg_privmsg_server("cia!cia@cia.gov", client->nick, "\1VERSION\1"), sendbuf(client);
-       msg_privmsg_server("cia!cia@cia.gov", client->nick, "\1TIME\1"),    sendbuf(client);
        const char *key;
        map_foreach(&autojoin, &key, 0)
                channel_join(client, key, NULL);