summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bot/src/commands/command.cpp2
-rw-r--r--bot/src/constants.hpp4
-rw-r--r--bot/src/modules/spam.hpp54
-rw-r--r--docs/mod/spam.md2
-rw-r--r--docs/summary.md5
5 files changed, 61 insertions, 6 deletions
diff --git a/bot/src/commands/command.cpp b/bot/src/commands/command.cpp
index 8d75999..3f99d9e 100644
--- a/bot/src/commands/command.cpp
+++ b/bot/src/commands/command.cpp
@@ -17,6 +17,7 @@
#include "../modules/massping.hpp"
#include "../modules/notify.hpp"
#include "../modules/ping.hpp"
+#include "../modules/spam.hpp"
#include "../modules/timer.hpp"
#include "../utils/chrono.hpp"
#include "request.hpp"
@@ -34,6 +35,7 @@ namespace bot {
this->add_command(std::make_unique<mod::Timer>());
this->add_command(std::make_unique<mod::Help>());
this->add_command(std::make_unique<mod::Chatters>());
+ this->add_command(std::make_unique<mod::Spam>());
}
void CommandLoader::add_command(std::unique_ptr<Command> command) {
diff --git a/bot/src/constants.hpp b/bot/src/constants.hpp
index b72a4c6..5819913 100644
--- a/bot/src/constants.hpp
+++ b/bot/src/constants.hpp
@@ -12,4 +12,6 @@ const std::string DEFAULT_PREFIX = "!";
#endif
const auto START_TIME = std::chrono::steady_clock::now();
-#define MARKOV_RESPONSE_CHANCE 1 \ No newline at end of file
+#define MARKOV_RESPONSE_CHANCE 1
+#define SPAM_DEFAULT_COUNT 5
+#define SPAM_MAX_COUNT 30 \ No newline at end of file
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);
+ }
+ };
+ }
+}
diff --git a/docs/mod/spam.md b/docs/mod/spam.md
index 55370d3..423dbba 100644
--- a/docs/mod/spam.md
+++ b/docs/mod/spam.md
@@ -11,7 +11,7 @@ This feature can be useful for highlighting important information.
`!spam [amount] [message...]`
+ `[amount]` (optional) - A number that specified how many times the message should be repeated.\
-If not specified, the default value is 10. The maximum value is 100.
+If not specified, the default value is 5. The maximum value is 30.
+ `[message...]` - The text of the message to be repeated.
## Usage
diff --git a/docs/summary.md b/docs/summary.md
index 670d8f1..ea05c68 100644
--- a/docs/summary.md
+++ b/docs/summary.md
@@ -17,6 +17,7 @@
## Moderation stuff
+ [Mass ping](/wiki/mod/mass-ping)
++ [Spam](/wiki/mod/spam)
## Miscellaneous
@@ -36,10 +37,6 @@
+ [Emote usage leaderboard](/wiki/emotes/top)
+ [Emote set similarity check](/wiki/emotes/sim)
-## Moderation stuff
-
-+ [Spam](/wiki/mod/spam)
-
## User management
+ [User ban check](/wiki/user/ban-check)