diff options
Diffstat (limited to '')
-rw-r--r-- | commands.c | 36 |
1 files changed, 25 insertions, 11 deletions
@@ -28,24 +28,38 @@ #include <stdint.h> #include <stdlib.h> +#include <string.h> #include "types.h" #include "table.h" #include "commands.h" #include "network.h" #include "tls.h" +#include "config.h" struct table user_commands = {0}; int help_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv) { for (uint64_t i = 0; i < user_commands.len; i++) { - SEND(STRING(":1HC000000 PRIVMSG ")); - SEND(to); - SEND(STRING(" :" "\x03" "04")); - SEND(user_commands.array[i].name); - SEND(STRING("\x0F" " ")); struct command_def *def = user_commands.array[i].ptr; - SEND(def->summary); + + uint64_t len = command_prefix.len; + len += user_commands.array[i].name.len; + len += 2; + len += def->summary.len; + + char data[len]; + struct string message = {.data = data, .len = len}; + uint64_t offset = 0; + memcpy(&(message.data[offset]), command_prefix.data, command_prefix.len); + offset += command_prefix.len; + memcpy(&(message.data[offset]), user_commands.array[i].name.data, user_commands.array[i].name.len); + offset += user_commands.array[i].name.len; + memcpy(&(message.data[offset]), "\x0F" " ", 2); + offset += 2; + memcpy(&(message.data[offset]), def->summary.data, def->summary.len); + + PRIVMSG(STRING("1HC000000"), to, message); } return 0; @@ -54,7 +68,7 @@ static struct command_def help_command_def = { .func = help_command, .privs = {0}, .local_only = 0, - .summary = STRING("Shows a list of commands, or, when I write it up, help about a specific command\n"), + .summary = STRING("Shows a list of commands, or, when I write it up, help about a specific command"), }; int raw_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv) { @@ -69,9 +83,9 @@ int raw_command(struct string sender, struct string original_message, struct str } static struct command_def raw_command_def = { .func = raw_command, - .privs = STRING("NetAdmin"), + .privs = STRING("NetAdmin"), // TODO: Make this configurable elsewhere .local_only = 0, - .summary = STRING("Sends a raw message to the server\n"), + .summary = STRING("Sends a raw message to the server"), }; static struct pref_type_suff { @@ -108,7 +122,7 @@ static struct command_def sus_command_def = { .func = sus_command, .privs = {0}, .local_only = 0, - .summary = STRING("You seem a bit sus today\n"), + .summary = STRING("You seem a bit sus today"), }; int cr_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv) { @@ -127,7 +141,7 @@ static struct command_def cr_command_def = { .func = cr_command, .privs = {0}, .local_only = 0, - .summary = STRING("Join the crux side\n"), + .summary = STRING("Join the crux side"), }; int init_user_commands(void) { |