diff options
Diffstat (limited to 'bot/src/handlers.cpp')
| -rw-r--r-- | bot/src/handlers.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
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 |
