summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-11 01:16:09 +0500
committerilotterytea <iltsu@alright.party>2025-04-11 01:16:09 +0500
commit32506ce7fcc9990961779b1b00a32a31fa985b45 (patch)
tree2fbf9e562a6e1b972febfa2dd74f4feb0cb27396
parent9b386ebe6a81412c43bc5705ec820941d21da2f5 (diff)
feat: !spam in lua
-rw-r--r--bot/src/commands/command.cpp2
-rw-r--r--bot/src/modules/spam.hpp54
-rw-r--r--luamods/spam.lua77
3 files changed, 77 insertions, 56 deletions
diff --git a/bot/src/commands/command.cpp b/bot/src/commands/command.cpp
index 73ea90d..4ec8e59 100644
--- a/bot/src/commands/command.cpp
+++ b/bot/src/commands/command.cpp
@@ -20,7 +20,6 @@
#include "../modules/mcsrv.hpp"
#include "../modules/notify.hpp"
#include "../modules/settings.hpp"
-#include "../modules/spam.hpp"
#include "../modules/timer.hpp"
#include "../modules/user.hpp"
#include "../utils/chrono.hpp"
@@ -38,7 +37,6 @@ namespace bot {
this->add_command(std::make_unique<mod::CustomCommand>());
this->add_command(std::make_unique<mod::Timer>());
this->add_command(std::make_unique<mod::Help>());
- this->add_command(std::make_unique<mod::Spam>());
this->add_command(std::make_unique<mod::Settings>());
this->add_command(std::make_unique<mod::User>());
this->add_command(std::make_unique<mod::MinecraftServerCheck>());
diff --git a/bot/src/modules/spam.hpp b/bot/src/modules/spam.hpp
deleted file mode 100644
index bc2c7f3..0000000
--- a/bot/src/modules/spam.hpp
+++ /dev/null
@@ -1,54 +0,0 @@
-#pragma once
-
-#include <exception>
-#include <string>
-#include <vector>
-
-#include "../bundle.hpp"
-#include "../commands/command.hpp"
-#include "../commands/response_error.hpp"
-
-namespace bot {
- namespace mod {
- class Spam : public command::Command {
- std::string get_name() const override { return "spam"; }
-
- schemas::PermissionLevel get_permission_level() const override {
- return schemas::PermissionLevel::MODERATOR;
- }
-
- int get_delay_seconds() const override { return 10; }
-
- command::Response run(const InstanceBundle &bundle,
- const command::Request &request) const override {
- if (!request.message.has_value()) {
- throw ResponseException<ResponseError::NOT_ENOUGH_ARGUMENTS>(
- request, bundle.localization, command::MESSAGE);
- }
-
- std::vector<std::string> parts =
- utils::string::split_text(request.message.value(), ' ');
-
- int count = SPAM_DEFAULT_COUNT;
- std::string message = request.message.value();
-
- try {
- count = std::stoi(parts[0]);
-
- if (count > SPAM_MAX_COUNT) count = SPAM_MAX_COUNT;
- message = utils::string::join_vector(
- {parts.begin() + 1, parts.end()}, ' ');
- } catch (std::exception &e) {
- }
-
- std::vector<std::string> output;
-
- for (int i = 0; i < count; i++) {
- output.push_back(message);
- }
-
- return command::Response(output);
- }
- };
- }
-}
diff --git a/luamods/spam.lua b/luamods/spam.lua
new file mode 100644
index 0000000..ac5a70c
--- /dev/null
+++ b/luamods/spam.lua
@@ -0,0 +1,77 @@
+local lines = {
+ english = {
+ ["no_message"] = "{sender.alias_name}: Message must be provided.",
+ },
+ russian = {
+ ["no_message"] = "{sender.alias_name}: Сообщение должно быть предоставлено.",
+ },
+}
+
+return {
+ name = "spam",
+ description = [[
+> It is recommended to give the bot moderator rights in the chat room. This will speed up the sending of messages.
+
+The `!spam` command gives users the ability to repeat a given message a certain number of times in a chat room.
+This feature can be useful for highlighting important information.
+
+## Syntax
+`!spam [amount] [message...]`
+
++ `[amount]` (optional) - A number that specified how many times the message should be repeated.
++ `[message...]` - The text of the message to be repeated.
+
+## Usage
+
++ `!spam forsen`
++ `!spam 100 forsen forsen forsen`
+
+## Responses
+
+```
+forsen forsen forsen
+forsen forsen forsen
+forsen forsen forsen
+forsen forsen forsen
+forsen forsen forsen
+forsen forsen forsen
+forsen forsen forsen
+forsen forsen forsen
+forsen forsen forsen
+forsen forsen forsen
+...
+]],
+ delay_sec = 10,
+ options = {},
+ subcommands = {},
+ aliases = {},
+ minimal_rights = "moderator",
+ handle = function(request)
+ if request.message == nil then
+ return l10n_custom_formatted_line_request(request, lines, "no_message", {})
+ end
+
+ local parts = str_split(request.message, " ")
+
+ local max_count = 20
+ local count = tonumber(parts[1])
+
+ if count == nil then
+ count = 5
+ elseif count > max_count then
+ count = max_count
+ table.remove(parts, 1)
+ else
+ table.remove(parts, 1)
+ end
+
+ local msg = table.concat(parts, ' ')
+ local o = {}
+
+ for i = 1, count, 1 do
+ table.insert(o, msg)
+ end
+
+ return o
+ end
+}