From a2052f0362d66493d05aec9cbdd151bfc1011a5f Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Fri, 5 Dec 2025 00:31:28 +0500 Subject: feat: dynamic prefixes in custom commands --- bot/src/handlers.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'bot/src') diff --git a/bot/src/handlers.cpp b/bot/src/handlers.cpp index ea6094d..1382bc5 100644 --- a/bot/src/handlers.cpp +++ b/bot/src/handlers.cpp @@ -62,21 +62,34 @@ namespace bot::handlers { } std::string cid = parts[0]; + std::string cid_without_prefix = + "{prefix}" + + cid.substr(requester.channel_preferences.get_prefix().size(), + cid.size()); db::DatabaseRows cmds = conn->exec( - "SELECT message FROM custom_commands WHERE name = $1 AND (channel_id " - "= $2 OR is_global = TRUE)", - {cid, std::to_string(requester.channel.get_id())}); + "SELECT name, message FROM custom_commands WHERE (name = $1 OR name " + "LIKE $2) " + "AND (channel_id " + "= $3 OR is_global = TRUE)", + {cid, cid_without_prefix, std::to_string(requester.channel.get_id())}); if (cmds.empty()) { return std::nullopt; } + db::DatabaseRow cmd = cmds[0]; + std::string cmd_name = cmd.at("name"); + if (cmd_name.length() > 8 && cmd_name.substr(0, 8) == "{prefix}" && + cid.substr(0, requester.channel_preferences.get_prefix().size()) != + requester.channel_preferences.get_prefix()) { + return std::nullopt; + } + parts.erase(parts.begin()); std::string initial_message = utils::string::join_vector(parts, ' '); - db::DatabaseRow cmd = cmds[0]; std::string msg = cmd.at("message"); // parsing values -- cgit v1.2.3