From 5c1b53c5f14bf0ff8cca56c58c0f417174b83f6c Mon Sep 17 00:00:00 2001 From: Egor Date: Tue, 23 Jan 2024 12:48:56 +0200 Subject: [PATCH] move ctcp probing to a separate module --- lua/ctcp.lua | 18 ++++++++++++++++++ lua/init.lua | 13 +------------ src/irc.c | 3 --- 3 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 lua/ctcp.lua diff --git a/lua/ctcp.lua b/lua/ctcp.lua new file mode 100644 index 0000000..df81634 --- /dev/null +++ b/lua/ctcp.lua @@ -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) diff --git a/lua/init.lua b/lua/init.lua index 004fde6..bd2c5df 100644 --- a/lua/init.lua +++ b/lua/init.lua @@ -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" diff --git a/src/irc.c b/src/irc.c index c86e01a..3b55bfd 100644 --- 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); -- 2.56.0