From 82593a585b417f63e51c6be13598827d2dc5c9a5 Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Mon, 30 Jan 2023 20:40:40 +0100 Subject: [PATCH] Add luaC2SendMsg --- src/controllers/plugins/PluginController.cpp | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/controllers/plugins/PluginController.cpp b/src/controllers/plugins/PluginController.cpp index a613901e7..98f180191 100644 --- a/src/controllers/plugins/PluginController.cpp +++ b/src/controllers/plugins/PluginController.cpp @@ -217,11 +217,32 @@ int luaC2RegisterCommand(lua_State *L) return 0; } +int luaC2SendMsg(lua_State *L) +{ + const char *channel = luaL_optstring(L, 1, NULL); + const char *text = luaL_optstring(L, 2, NULL); + lua_pop(L, 2); + + const auto chn = getApp()->twitch->getChannelOrEmpty(channel); + if (chn->isEmpty()) + { + qCDebug(chatterinoLua) << "send_msg: no channel" << channel; + lua_pushboolean(L, C_FALSE); + return 1; + } + QString message = text; + message = message.replace('\n', ' '); + QString outText = getApp()->commands->execCommand(message, chn, false); + chn->sendMessage(outText); + lua_pushboolean(L, C_TRUE); + return 1; +} // NOLINTNEXTLINE static const luaL_Reg C2LIB[] = { {"system_msg", luaC2SystemMsg}, {"register_command", luaC2RegisterCommand}, + {"send_msg", luaC2SendMsg}, {nullptr, nullptr}, }; }