]> PatchyGit - patchyircd.git/commitdiff
admin: let lua send PRIVMSG to channels
authorEgor <egor@patchysicp.xyz>
Wed, 11 Feb 2026 23:21:56 +0000 (01:21 +0200)
committerEgor <egor@patchysicp.xyz>
Wed, 11 Feb 2026 23:21:56 +0000 (01:21 +0200)
src/admin.cpp
src/irc.cpp
src/irc.hpp

index 9cdd0a2..1a9acb2 100644 (file)
@@ -297,6 +297,20 @@ static int fn_client_notice(lua_State *L)
        msg_notice_server(luaL_optstring(L, 3, hostname), cl->nick, msg), sendbuf(cl);
        return 0;
 }
+static int fn_channel_privmsg(lua_State *L)
+{
+       Channel *chan = ChannelRef::check(L, 1);
+       const char *msg = luaL_checkstring(L, 2);
+       msg_privmsg_server(luaL_optstring(L, 3, hostname), chan->name, msg), sendbuf_chan(chan);
+       return 0;
+}
+static int fn_channel_notice(lua_State *L)
+{
+       Channel *chan = ChannelRef::check(L, 1);
+       const char *msg = luaL_checkstring(L, 2);
+       msg_notice_server(luaL_optstring(L, 3, hostname), chan->name, msg), sendbuf_chan(chan);
+       return 0;
+}
 static int fn_channel_join(lua_State *L)
 {
        Client *cl = ClientRef::check(L, 1);
@@ -469,6 +483,8 @@ void admin_init(void)
                luaL_Reg funcs[] = {
                        {"client_privmsg", fn_client_privmsg},
                        {"client_notice", fn_client_notice},
+                       {"channel_privmsg", fn_channel_privmsg},
+                       {"channel_notice", fn_channel_notice},
                        {"channel_join", fn_channel_join},
                        {"channel_part", fn_channel_part},
                        {"channel_new", fn_channel_new},
index a9e4009..a381faf 100644 (file)
@@ -34,7 +34,7 @@ static void sendbuf_chan_caps(Channel *chan, unsigned positive, unsigned negativ
                if (!(~cl->caps & positive) && !(cl->caps & negative))
                        sendbuf(cl);
 }
-static void sendbuf_chan(Channel *chan) {
+void sendbuf_chan(Channel *chan) {
        sendbuf_chan_caps(chan, 0, 0);
 }
 static void sendbuf_list_sans_self_caps(Client *client, clientset &ls, int cookie, int positive, int negative) {
index 89d8fcf..324d13a 100644 (file)
@@ -7,6 +7,7 @@
 #include "net.hpp"
 #include "util.hpp"
 #define is_registered(cl) ((cl)->regstate == REG_REGISTERED)
+void sendbuf_chan(Channel *chan);
 void sendbuf_monitor(const char *nick, int cookie, int positive, int negative);
 const char *format_umodes(Client *cl);
 bool irc_parse_line(Client *client, char *p, char *end);