hirc

IRC client
Log | Files | Refs

commit db33c44e48e502b16d9bc27b124067a236c02f2c
parent 46934e2612a3c71264943c3ee94c722065a654ef
Author: hhvn <dev@hhvn.uk>
Date:   Thu, 16 Dec 2021 16:13:42 +0000

s/commands.c s/config.c s/handle.c s/struct.h: /mode

Diffstat:
Msrc/commands.c | 35+++++++++++++++++++++++++++++++++++
Msrc/config.c | 2+-
Msrc/handle.c | 7+++++++
Msrc/struct.h | 1+
4 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/src/commands.c b/src/commands.c @@ -33,6 +33,7 @@ static void command_quit(struct Server *server, char *str); static void command_join(struct Server *server, char *str); static void command_part(struct Server *server, char *str); static void command_kick(struct Server *server, char *str); +static void command_mode(struct Server *server, char *str); static void command_ping(struct Server *server, char *str); static void command_quote(struct Server *server, char *str); static void command_connect(struct Server *server, char *str); @@ -78,6 +79,9 @@ struct Command commands[] = { {"kick", command_kick, 1, { "usage: /kick [channel] <nick> [reason]", "Kick nick from channel", NULL}}, + {"mode", command_mode, 1, { + "usage: /mode <channel> modes...", + "Set/unset channel modes", NULL}}, {"ping", command_ping, 1, { "usage: /ping message...", "Send a PING to server.", @@ -265,6 +269,37 @@ command_kick(struct Server *server, char *str) { } static void +command_mode(struct Server *server, char *str) { + char *channel, *modes; + char *s = NULL; + + if (str) + s = strtok_r(str, " ", &modes); + + if (s && strchr(support_get(server, "CHANTYPES"), *s)) { + channel = s; + } else { + if (selected.channel == NULL) { + ui_error("no channel selected", NULL); + return; + } + + channel = selected.channel->name; + if (modes) { + *(modes - 1) = ' '; + modes = s; + } + } + + if (modes) { + ircprintf(server, "MODE %s %s\r\n", channel, modes); + } else { + handle_expect(server, Expect_channelmodeis, channel); + ircprintf(server, "MODE %s\r\n", channel); + } +} + +static void command_ping(struct Server *server, char *str) { if (!str) { ui_error("/ping requires argument", NULL); diff --git a/src/config.c b/src/config.c @@ -697,7 +697,7 @@ struct Config config[] = { .description = { "Format of RPL_LISTEND (323) numeric", NULL}}, {"format.rpl.channelmodeis", 1, Val_string, - .str = "${2-}", + .str = "mode%{=}%{c:94}${3-}%{o}", .strhandle = config_redraws, .description = { "Format of RPL_CHANNELMODEIS (324) numeric", NULL}}, diff --git a/src/handle.c b/src/handle.c @@ -335,6 +335,13 @@ handle_RPL_CHANNELMODEIS(char *msg, char **params, struct Server *server, time_t free(chan->mode); chan->mode = strdup(*(params+4)); + + if (handle_expect_get(server, Expect_channelmodeis)) { + hist_add(chan->history, NULL, msg, params, Activity_status, timestamp, HIST_DFL); + handle_expect(server, Expect_channelmodeis, NULL); + } else { + hist_add(chan->history, NULL, msg, params, Activity_status, timestamp, HIST_LOG); + } } static void diff --git a/src/struct.h b/src/struct.h @@ -114,6 +114,7 @@ enum Expect { Expect_names, Expect_topic, Expect_topicwhotime, + Expect_channelmodeis, Expect_last, };