From b4044eb4752643027cd6d6821e79546404713208 Mon Sep 17 00:00:00 2001 From: Egor Date: Wed, 28 Jan 2026 16:28:24 +0200 Subject: [PATCH] autojoin: rewrite in lua --- README.md | 6 +++--- lua/autojoin.lua | 10 ++++++++++ lua/init.lua | 3 ++- src/admin.cpp | 2 -- src/irc.cpp | 3 --- src/main.cpp | 6 ------ 6 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 lua/autojoin.lua diff --git a/README.md b/README.md index 6d2f645..c34b605 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,9 @@ if not local_processed then end ``` +You can also make users automatically join a channel on connect with: +`autojoin["#chan"] = true` + Channel state changes are logged in `chanlog.txt`, in a format similar to IRC protocol. Lines are prefixed with `$123`, which indicates the unix timestamp for when the action has occured. @@ -112,9 +115,6 @@ none are specified, the default is: ``` IPv4 and IPv6 must be specified separately. -With `--autojoin \#ircmoment` clients will automatically join the `#ircmoment` -channel. This option can be specified multiple times. - The server hostname can be set via `--hostname`. The default is the machine's actual hostname diff --git a/lua/autojoin.lua b/lua/autojoin.lua new file mode 100644 index 0000000..b04fb4b --- /dev/null +++ b/lua/autojoin.lua @@ -0,0 +1,10 @@ +-- Copyright (c) 2026 Egor +-- SPDX-License-Identifier: GPL-2.0-or-later +if not autojoin then + autojoin = {} +end +hook_add("newuser", "autojoin", function(hook, cl1, cl2, chan, txt) + for k in pairs(autojoin) do + channel_join(cl1, k, false) + end +end) diff --git a/lua/init.lua b/lua/init.lua index 1cc1d50..66da1ca 100644 --- a/lua/init.lua +++ b/lua/init.lua @@ -1,4 +1,4 @@ --- Copyright (c) 2023-2025 Egor +-- Copyright (c) 2023-2026 Egor -- SPDX-License-Identifier: GPL-2.0-or-later function commands.reload(client, source, command, args) client_notice(client, "reloading...") @@ -97,4 +97,5 @@ end dofile(getluafile "irccloud.lua") dofile(getluafile "ctcp.lua") dofile(getluafile "spam.lua") +dofile(getluafile "autojoin.lua") pcall(dofile, getluafile "local.lua") diff --git a/src/admin.cpp b/src/admin.cpp index 6daf73c..d9db90e 100644 --- a/src/admin.cpp +++ b/src/admin.cpp @@ -199,8 +199,6 @@ static int globals_index(lua_State *L) return map_push(L, &client_map, MAPTYPE_CLIENT), 1; if (!strcmp(key, "channel_map")) return map_push(L, &channel_map, MAPTYPE_CHANNEL), 1; - if (!strcmp(key, "autojoin")) - return map_push(L, &autojoin, MAPTYPE_STRINGSET), 1; if (!strcmp(key, "clients")) { *(Client **)lua_newuserdatauv(L, sizeof(Client *), 0) = clients; luaL_setmetatable(L, "client"); diff --git a/src/irc.cpp b/src/irc.cpp index 8e7f6ed..8ea267f 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -10,7 +10,6 @@ std::vector databuf; clientmap client_map = {}; channelmap channel_map = {}; -stringset autojoin = {}; const char *hostname = 0; void sendbuf(Client *client) { @@ -1265,8 +1264,6 @@ void newUser(Client *client) { rpl_umodeis(client), sendbuf(client); sendMOTD(client); admin_hook("newuser", client, 0, 0, 0); - for (auto key : autojoin) - channel_join(client, key, NULL); } void sendLUSERS(Client *client) { diff --git a/src/main.cpp b/src/main.cpp index 06ab55c..1f21903 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -254,11 +254,6 @@ int main(int argc, char *argv[]) return fprintf(stderr, "no TLS support\n"), 1; listeners.push_back(create_listen_sock(argv[i+1], argv[i+2], is_tls ? tls_ctx : 0)); i += 2; - } else if(!strcmp(argv[i], "--autojoin")) { - if (i + 1 >= argc) - return fprintf(stderr, "not enough parameters\n"), 1; - autojoin.add(argv[i+1]); - i += 1; } else if(!strcmp(argv[i], "--datadir")) { if (i + 1 >= argc) return fprintf(stderr, "not enough parameters\n"), 1; @@ -380,7 +375,6 @@ int main(int argc, char *argv[]) channel_kill(chan); client_map.clear(); channel_map.clear(); - autojoin.clear(); if (fchanlog) fclose(fchanlog); return 0; -- 2.56.0