From 4edfc14ef7a0ee70d67f7dba2b0c02e968e002d0 Mon Sep 17 00:00:00 2001 From: Egor Date: Thu, 12 Feb 2026 01:21:56 +0200 Subject: [PATCH] admin: let lua send PRIVMSG to channels --- src/admin.cpp | 16 ++++++++++++++++ src/irc.cpp | 2 +- src/irc.hpp | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/admin.cpp b/src/admin.cpp index 9cdd0a2..1a9acb2 100644 --- a/src/admin.cpp +++ b/src/admin.cpp @@ -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}, diff --git a/src/irc.cpp b/src/irc.cpp index a9e4009..a381faf 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -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) { diff --git a/src/irc.hpp b/src/irc.hpp index 89d8fcf..324d13a 100644 --- a/src/irc.hpp +++ b/src/irc.hpp @@ -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); -- 2.56.0