summaryrefslogtreecommitdiff
path: root/commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'commands.c')
-rw-r--r--commands.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/commands.c b/commands.c
index fdae58b..33ffd21 100644
--- a/commands.c
+++ b/commands.c
@@ -182,6 +182,58 @@ static struct command_def spam_command_def = {
.summary = STRING("Repeats a message to a target <n> times"),
};
+int clear_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;
+ }
+
+ struct channel_info *channel = get_table_index(channel_list, argv[1]);
+ if (!channel) {
+ privmsg(STRING("1HC000000"), to, 1, (struct string[]){STRING("That channel doesn't seem to exist, so is thereby already cleared.")});
+ return 0;
+ }
+
+ for (uint64_t i = 0; i < channel->user_list.len; i++) {
+ // TODO: Proper kick function, will prob come as a part of my next HaxServ rewrite
+
+ SEND(STRING(":1HC000000 KICK "));
+ SEND(argv[1]);
+ SEND(STRING(" "));
+ SEND(channel->user_list.array[i].name);
+ SEND(STRING(" :\n"));
+
+ if (client_connected) {
+ SENDCLIENT(STRING(":"));
+ SENDCLIENT(nick);
+ SENDCLIENT(STRING("!"));
+ SENDCLIENT(nick);
+ SENDCLIENT(STRING("@"));
+ SENDCLIENT(hostmask);
+ SENDCLIENT(STRING(" KICK "));
+ SENDCLIENT(argv[1]);
+ SENDCLIENT(STRING(" "));
+
+ struct user_info *user = get_table_index(user_list, channel->user_list.array[i].name);
+ if (user)
+ SENDCLIENT(user->nick);
+ else
+ SENDCLIENT(user_list.array[i].name);
+
+ SENDCLIENT(STRING(" :\r\n"));
+ }
+ }
+ clear_table(&(channel->user_list));
+
+ return 0;
+}
+static struct command_def clear_command_def = {
+ .func = clear_command,
+ .privs = STRING("NetAdmin"),
+ .local_only = 0,
+ .summary = STRING("Clears a channel"),
+};
+
int init_user_commands(void) {
srandom(time(NULL));
@@ -192,6 +244,7 @@ int init_user_commands(void) {
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);
+ set_table_index(&user_commands, STRING("clear"), &clear_command_def);
return 0;
}