]> PatchyGit - patchyircd.git/commitdiff
autojoin: rewrite in lua
authorEgor <egor@patchysicp.xyz>
Wed, 28 Jan 2026 14:28:24 +0000 (16:28 +0200)
committerEgor <egor@patchysicp.xyz>
Wed, 28 Jan 2026 14:28:24 +0000 (16:28 +0200)
README.md
lua/autojoin.lua [new file with mode: 0644]
lua/init.lua
src/admin.cpp
src/irc.cpp
src/main.cpp

index 6d2f645..c34b605 100644 (file)
--- 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 (file)
index 0000000..b04fb4b
--- /dev/null
@@ -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)
index 1cc1d50..66da1ca 100644 (file)
@@ -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")
index 6daf73c..d9db90e 100644 (file)
@@ -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");
index 8e7f6ed..8ea267f 100644 (file)
@@ -10,7 +10,6 @@
 std::vector<char> 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)
 {
index 06ab55c..1f21903 100644 (file)
@@ -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;