diff options
| author | ilotterytea <iltsu@alright.party> | 2025-07-03 18:04:24 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-07-03 18:04:24 +0500 |
| commit | 1e8f182b083679b06d8e30fe52b1ed1130a19287 (patch) | |
| tree | b14bb841d07bc2ef87820e43fb00c19783cfc167 | |
| parent | 406e08a3a1f42a014affc35bb399a32ff9cbff96 (diff) | |
feat: global commands
| -rw-r--r-- | luamods/cmd.lua | 29 | ||||
| -rw-r--r-- | migrations/2025-07-04T09-50-32_globalcommands/down.sql | 2 | ||||
| -rw-r--r-- | migrations/2025-07-04T09-50-32_globalcommands/up.sql | 2 |
3 files changed, 31 insertions, 2 deletions
diff --git a/luamods/cmd.lua b/luamods/cmd.lua index 4826f5a..a7676ce 100644 --- a/luamods/cmd.lua +++ b/luamods/cmd.lua @@ -2,6 +2,7 @@ local lines = { english = { ["no_subcommand"] = "{sender.alias_name}: No subcommand provided. Use '{channel.prefix}help cmd' for more info.", ["no_message"] = "{sender.alias_name}: No message provided.", + ["not_enough_rights"] = "{sender.alias_name}: You do not have enough rights to perform this command.", ["command_list"] = "{sender.alias_name}: %s", ["namesake"] = "{sender.alias_name}: A command with the same name already exists.", ["new_cmd"] = "{sender.alias_name}: Created a new command! Use %s to run it.", @@ -15,12 +16,15 @@ local lines = { ["alias_command"] = "{sender.alias_name}: Successfully created alias %s for %s command.", ["no_cmd_alias"] = "{sender.alias_name}: There is no command with alias %s", ["delalias_command"] = "{sender.alias_name}: Successfully removed alias %s from %s command.", + ["setglobal_command"] = "{sender.alias_name}: Command %s is now available in all chats.", + ["delglobal_command"] = "{sender.alias_name}: Command %s is now available only in this chat.", ["view_command"] = "{sender.alias_name}: ID %s | %s | Aliases: %s | %s", }, russian = { ["no_subcommand"] = "{sender.alias_name}: Нет подкоманды. Используйте '{channel.prefix}help cmd', чтобы получить больше информации.", ["no_message"] = "{sender.alias_name}: Сообщение не предоставлено.", + ["not_enough_rights"] = "{sender.alias_name}: У вас недостаточно прав для выполнения этой команды.", ["command_list"] = "{sender.alias_name}: %s", ["namesake"] = "{sender.alias_name}: Команда с таким же именем уже существует.", ["new_cmd"] = "{sender.alias_name}: Создана новая команда! Используйте %s для её запуска.", @@ -34,6 +38,8 @@ local lines = { ["alias_command"] = "{sender.alias_name}: Успешно привязал алиас %s к команде %s", ["no_cmd_alias"] = "{sender.alias_name}: Нет команд с алиасом %s", ["delalias_command"] = "{sender.alias_name}: Успешно удалил алиас %s от команды %s", + ["setglobal_command"] = "{sender.alias_name}: Команда %s доступна во всех чатах.", + ["delglobal_command"] = "{sender.alias_name}: Команда %s доступна только в этом чате.", ["view_command"] = "{sender.alias_name}: ID %s | %s | Алиасы: %s | %s", }, } @@ -124,7 +130,7 @@ The `!cmd` command gives the ability to create their own chat commands. ]], delay_sec = 1, options = {}, - subcommands = { "new", "delete", "edit", "rename", "alias", "delalias", "view", "list" }, + subcommands = { "new", "delete", "edit", "rename", "alias", "delalias", "view", "list", "setglobal" }, aliases = { "scmd" }, minimal_rights = "moderator", handle = function(request) @@ -154,7 +160,7 @@ The `!cmd` command gives the ability to create their own chat commands. table.remove(parts, 1) local cmds = db_query( - 'SELECT id, name, message FROM custom_commands WHERE name = $1 AND channel_id = $2', + 'SELECT id, name, message, is_global FROM custom_commands WHERE name = $1 AND channel_id = $2', { name, request.channel.id }) if scid == "new" then @@ -256,6 +262,25 @@ The `!cmd` command gives the ability to create their own chat commands. { cmd_alias[1].id }) return l10n_custom_formatted_line_request(request, lines, "delalias_command", { old_alias, name }) + elseif scid == "setglobal" then + local cfg = bot_config() + if cfg == nil or cfg.owner == nil or request.sender.alias_id ~= cfg.owner.id then + return l10n_custom_formatted_line_request(request, lines, "not_enough_rights", {}) + end + + local line_id = "" + local query = "" + if cmd.is_global == "1" then + line_id = "delglobal_command" + query = "UPDATE custom_commands SET is_global = FALSE WHERE id = $1" + else + line_id = "setglobal_command" + query = "UPDATE custom_commands SET is_global = TRUE WHERE id = $1" + end + + db_execute(query, { cmd.id }) + + return l10n_custom_formatted_line_request(request, lines, line_id, { name }) elseif scid == "view" then local aliases_db = db_query('SELECT name FROM custom_command_aliases WHERE command_id = $1', { cmd.id }) diff --git a/migrations/2025-07-04T09-50-32_globalcommands/down.sql b/migrations/2025-07-04T09-50-32_globalcommands/down.sql new file mode 100644 index 0000000..deb876e --- /dev/null +++ b/migrations/2025-07-04T09-50-32_globalcommands/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in 'up.sql' +ALTER TABLE custom_commands DROP COLUMN is_global;
\ No newline at end of file diff --git a/migrations/2025-07-04T09-50-32_globalcommands/up.sql b/migrations/2025-07-04T09-50-32_globalcommands/up.sql new file mode 100644 index 0000000..f6ae919 --- /dev/null +++ b/migrations/2025-07-04T09-50-32_globalcommands/up.sql @@ -0,0 +1,2 @@ +-- Your SQL goes here +ALTER TABLE custom_commands ADD COLUMN is_global BOOLEAN NOT NULL DEFAULT FALSE;
\ No newline at end of file |
