From 6b89f774abdd2f12b7b33933a8c1a72a39394b0a Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 8 May 2024 23:39:17 +0500 Subject: feat: handler for custom commands --- src/handlers.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/handlers.cpp b/src/handlers.cpp index 0eec2b0..a7d768d 100644 --- a/src/handlers.cpp +++ b/src/handlers.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "bundle.hpp" @@ -50,5 +51,26 @@ namespace bot::handlers { bundle.irc_client.say(message.source.login, line); } } + + pqxx::work work(conn); + pqxx::result channels = + work.exec("SELECT id FROM channels WHERE alias_id = " + + std::to_string(message.source.id)); + + if (!channels.empty()) { + int channel_id = channels[0][0].as(); + pqxx::result cmds = + work.exec("SELECT message FROM custom_commands WHERE name = '" + + message.message + "' AND channel_id = '" + + std::to_string(channel_id) + "'"); + + if (!cmds.empty()) { + std::string msg = cmds[0][0].as(); + + bundle.irc_client.say(message.source.login, msg); + } + } + + work.commit(); } } -- cgit v1.2.3