commit fc3864dce7535304804f68335e11d4bd6438bbce
parent a7ddefde1336dee5486a94618a8018baee5fba7e
Author: hhvn <dev@hhvn.uk>
Date: Thu, 2 Dec 2021 23:03:18 +0000
commands.c: improve /part behaviour
Diffstat:
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/commands.c b/commands.c
@@ -118,19 +118,28 @@ command_join(struct Server *server, char *str) {
static void
command_part(struct Server *server, char *str) {
- char *channel, *chantypes, msg[512];
+ char *channel = NULL, *reason = NULL;
+ char *chantypes, msg[512];
+
+ chantypes = support_get(server, "CHANTYPES");
+
+ if (str) {
+ if (strchr(chantypes, *str))
+ channel = strtok_r(str, " ", &reason);
+ else
+ reason = str;
+ }
- channel = str ? str : selected.channel ? selected.channel->name : NULL;
if (!channel) {
- ui_error("/part requires argument", NULL);
- return;
+ if (selected.channel) {
+ channel = selected.channel->name;
+ } else {
+ ui_error("/part requires argument", NULL);
+ return;
+ }
}
- chantypes = support_get(server, "CHANTYPES");
- if (strchr(chantypes, *str))
- snprintf(msg, sizeof(msg), "PART %s\r\n", str);
- else
- snprintf(msg, sizeof(msg), "PART %c%s\r\n", chantypes ? *chantypes : '#', str);
+ snprintf(msg, sizeof(msg), "PART %s :%s\r\n", channel, reason ? reason : config_gets("misc.partmessage"));
ircprintf(server, "%s", msg);
handle_expect(server, Expect_part, channel);