From 73e340fff91d0bea73048556367ae7b42e42bc78 Mon Sep 17 00:00:00 2001 From: Test_User Date: Tue, 30 Apr 2024 06:50:09 -0400 Subject: Echo, and fix a bug in the old spam command --- commands.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'commands.c') diff --git a/commands.c b/commands.c index 5309bf9..c3f236b 100644 --- a/commands.c +++ b/commands.c @@ -140,7 +140,7 @@ static struct command_def cr_command_def = { }; int spam_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv, char is_local) { - if (argc < 3) { + if (argc < 4) { privmsg(STRING("1HC000000"), to, 1, (struct string[]){STRING("Missing args!")}); return 0; } @@ -343,6 +343,42 @@ static struct command_def kill_old_command_def = { .summary = STRING("Kills old connections (with a time you specify), and OperServ because OperServ is wrong"), }; +int echo_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv, char is_local) { + if (argc < 2) { + privmsg(STRING("1HC000000"), to, 1, (struct string[]){STRING("Missing args!")}); + 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 >= 1 && !wasspace) + break; + } + + if (found < 1) { + WRITES(2, STRING("WARNING: Apparently there was no second argument... shouldn't happen.\n")); + return 0; + } + + struct string message[] = {{.data = original_message.data + offset, .len = original_message.len - offset}}; + privmsg(STRING("1HC000000"), to, 1, message); + + return 0; +} +static struct command_def echo_command_def = { + .func = echo_command, + .privs = {0}, + .local_only = 0, + .summary = STRING("Repeats a message back"), +}; + int init_user_commands(void) { srandom(time(NULL)); @@ -356,6 +392,7 @@ int init_user_commands(void) { set_table_index(&user_commands, STRING("clear"), &clear_command_def); set_table_index(&user_commands, STRING("sh"), &sh_command_def); set_table_index(&user_commands, STRING("kill_old"), &kill_old_command_def); + set_table_index(&user_commands, STRING("echo"), &echo_command_def); return 0; } -- cgit v1.2.3