diff options
| -rw-r--r-- | bot/src/handlers.cpp | 22 | ||||
| -rw-r--r-- | migrations/2024-05-11T02-53-05_init/up.sql | 4 |
2 files changed, 15 insertions, 11 deletions
diff --git a/bot/src/handlers.cpp b/bot/src/handlers.cpp index f473063..508c912 100644 --- a/bot/src/handlers.cpp +++ b/bot/src/handlers.cpp @@ -61,17 +61,20 @@ namespace bot::handlers { return std::nullopt; } + std::string prefix = requester.channel_preferences.get_prefix(); std::string cid = parts[0]; - std::string cid_without_prefix = - "{prefix}" + - cid.substr(requester.channel_preferences.get_prefix().size(), - cid.size()); + std::string cid_without_prefix = cid; + + if (cid.size() > prefix.size() && cid.substr(0, prefix.size()) == prefix) { + cid_without_prefix = "{prefix}" + cid.substr(prefix.size(), cid.size()); + } db::DatabaseRows cmds = conn->exec( - "SELECT cc.name, cc.message FROM custom_commands cc " + "SELECT cc.name, cc.message, cca.name AS alias_name FROM " + "custom_commands cc " "LEFT JOIN custom_command_aliases cca ON cca.command_id = cc.id " - "WHERE (cc.name = $1 OR cc.name " - "LIKE $2 OR cca.name = $3 OR cca.name LIKE $4) " + "WHERE (BINARY cc.name = $1 OR BINARY cc.name = $2 " + "OR BINARY cca.name = $3 OR BINARY cca.name = $4) " "AND (cc.channel_id " "= $5 OR cc.is_global = TRUE)", {cid, cid_without_prefix, cid, cid_without_prefix, @@ -82,9 +85,10 @@ namespace bot::handlers { } db::DatabaseRow cmd = cmds[0]; - std::string cmd_name = cmd.at("name"); + std::string cmd_name = + cmd.at("alias_name").empty() ? cmd.at("name") : cmd.at("alias_name"); if (cmd_name.length() > 8 && cmd_name.substr(0, 8) == "{prefix}" && - cid.substr(0, requester.channel_preferences.get_prefix().size()) != + cmd_name.substr(0, requester.channel_preferences.get_prefix().size()) != requester.channel_preferences.get_prefix()) { return std::nullopt; } diff --git a/migrations/2024-05-11T02-53-05_init/up.sql b/migrations/2024-05-11T02-53-05_init/up.sql index b33f1e4..6764a14 100644 --- a/migrations/2024-05-11T02-53-05_init/up.sql +++ b/migrations/2024-05-11T02-53-05_init/up.sql @@ -61,14 +61,14 @@ CREATE TABLE IF NOT EXISTS event_subscriptions ( CREATE TABLE IF NOT EXISTS custom_commands ( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, channel_id INTEGER NOT NULL REFERENCES channels(id) ON DELETE CASCADE, - name TEXT NOT NULL, + name TEXT NOT NULL CHARACTER SET utf8mb4 COLLATE utf8mb4_bin, message TEXT NOT NULL ); CREATE TABLE IF NOT EXISTS custom_command_aliases ( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, command_id INTEGER NOT NULL REFERENCES custom_commands(id) ON DELETE CASCADE, - name TEXT NOT NULL, + name TEXT NOT NULL CHARACTER SET utf8mb4 COLLATE utf8mb4_bin, CONSTRAINT unique_command_alias UNIQUE (command_id, name) ); |
