summaryrefslogtreecommitdiff
path: root/commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'commands.c')
-rw-r--r--commands.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/commands.c b/commands.c
index 1928281..b379445 100644
--- a/commands.c
+++ b/commands.c
@@ -36,6 +36,9 @@
#include "network.h"
#include "tls.h"
#include "config.h"
+#include "utils.h"
+
+#define MAX_SPAM_COUNT 65536
struct table user_commands = {0};
@@ -135,6 +138,51 @@ static struct command_def cr_command_def = {
.summary = STRING("Join the crux side"),
};
+int spam_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv) {
+ if (argc < 3) {
+ privmsg(STRING("1HC000000"), to, 1, (struct string[]){STRING("Missing args!")});
+ return 0;
+ }
+
+ char err;
+ uint64_t count = str_to_unsigned(argv[2], &err);
+ if (err || count > MAX_SPAM_COUNT) {
+ privmsg(STRING("1HC000000"), to, 1, (struct string[]){STRING("Unknown number or number exceeds limit.")});
+ return 0;
+ }
+
+ char wasspace = 1;
+ uint64_t offset = 0;
+ char found = 0;
+ for (; offset < original_message.len; offset++) {
+ if (original_message.data[offset] == ' ' && !wasspace)
+ found++;
+
+ wasspace = (original_message.data[offset] == ' ');
+
+ if (found >= 3 && !wasspace)
+ break;
+ }
+
+ if (found < 3) {
+ WRITES(2, STRING("WARNING: Apparently there was no third argument... shouldn't happen.\n"));
+ return 0;
+ }
+
+ struct string message[] = {{.data = original_message.data + offset, .len = original_message.len - offset}};
+
+ for (uint64_t i = 0; i < count; i++)
+ privmsg(STRING("1HC000000"), argv[1], 1, message);
+
+ return 0;
+}
+static struct command_def spam_command_def = {
+ .func = spam_command,
+ .privs = STRING("NetAdmin"),
+ .local_only = 0,
+ .summary = STRING("Repeats a message to a target <n> times"),
+};
+
int init_user_commands(void) {
srandom(time(NULL));
@@ -144,6 +192,7 @@ int init_user_commands(void) {
set_table_index(&user_commands, STRING("sus"), &sus_command_def);
set_table_index(&user_commands, STRING("cr"), &cr_command_def);
set_table_index(&user_commands, STRING("help"), &help_command_def);
+ set_table_index(&user_commands, STRING("spam"), &spam_command_def);
return 0;
}