Add luaC2SendMsg

This commit is contained in:
Mm2PL 2023-01-30 20:40:40 +01:00
parent 714f961f59
commit 82593a585b
No known key found for this signature in database
GPG key ID: 94AC9B80EFA15ED9

View file

@ -217,11 +217,32 @@ int luaC2RegisterCommand(lua_State *L)
return 0; 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 // NOLINTNEXTLINE
static const luaL_Reg C2LIB[] = { static const luaL_Reg C2LIB[] = {
{"system_msg", luaC2SystemMsg}, {"system_msg", luaC2SystemMsg},
{"register_command", luaC2RegisterCommand}, {"register_command", luaC2RegisterCommand},
{"send_msg", luaC2SendMsg},
{nullptr, nullptr}, {nullptr, nullptr},
}; };
} }