diff options
| author | ilotterytea <iltsu@alright.party> | 2024-12-14 13:16:33 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2024-12-14 13:16:33 +0500 |
| commit | 6504ce844023f188dfb5350cd8ad34bfc94f5ac0 (patch) | |
| tree | 3ce68cdf13097d415127de6a2664fe1e2e51d50b /bot/src/modules/spam.hpp | |
| parent | d7b419837f58be4c75dfab756ffac025ed8fc962 (diff) | |
feat: spam command
Diffstat (limited to 'bot/src/modules/spam.hpp')
| -rw-r--r-- | bot/src/modules/spam.hpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/bot/src/modules/spam.hpp b/bot/src/modules/spam.hpp new file mode 100644 index 0000000..bc2c7f3 --- /dev/null +++ b/bot/src/modules/spam.hpp @@ -0,0 +1,54 @@ +#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); + } + }; + } +} |
