summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bot/src/handlers.cpp21
-rw-r--r--luamods/cmd.lua1
2 files changed, 18 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
diff --git a/luamods/cmd.lua b/luamods/cmd.lua
index a7676ce..514ec8b 100644
--- a/luamods/cmd.lua
+++ b/luamods/cmd.lua
@@ -62,6 +62,7 @@ The `!cmd` command gives the ability to create their own chat commands.
+ `[name]` - The name for new custom command. It should be unique for your chat.
**A prefix must be specified if you want a prefixed command, e.g. `!sub`, `!server`.**
+You can use `{prefix}` *(dynamic prefix)*, for example `{prefix}sub, {prefix}server`. It will be replaced with the current prefix in the chat.
+ `[message]` - Text that will be sent when the custom command is invoked.
### Delete the custom command