diff options
author | Test_User <hax@andrewyu.org> | 2024-04-30 06:50:09 -0400 |
---|---|---|
committer | Test_User <hax@andrewyu.org> | 2024-04-30 06:50:09 -0400 |
commit | 73e340fff91d0bea73048556367ae7b42e42bc78 (patch) | |
tree | 95b3f28feee502eedda9565d05742a250ed33e6e /commands.c | |
parent | 4a864ccb247fa97b026e3ca372baa03114883f00 (diff) | |
download | coupserv-73e340fff91d0bea73048556367ae7b42e42bc78.tar.gz coupserv-73e340fff91d0bea73048556367ae7b42e42bc78.zip |
Echo, and fix a bug in the old spam command
Diffstat (limited to '')
-rw-r--r-- | commands.c | 39 |
1 files changed, 38 insertions, 1 deletions
@@ -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; } |