From f2ab9f393779830ae45e1c66ef2d136879fa5ac6 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sun, 17 May 2015 16:25:52 +0200 Subject: degesch: implement /cycle --- degesch.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/degesch.c b/degesch.c index d064812..da80577 100644 --- a/degesch.c +++ b/degesch.c @@ -5226,6 +5226,41 @@ handle_command_part (struct app_context *ctx, char *arguments) return true; } +static bool +handle_command_cycle (struct app_context *ctx, char *arguments) +{ + if (!server_command_check (ctx, "cycle", true)) + return true; + + struct server *s = ctx->current_buffer->server; + if (*arguments) + { + // TODO: check if the arguments are in the form of "channel(,channel)*" + char *channels = cut_word (&arguments); + if (*arguments) + irc_send (s, "PART %s :%s", channels, arguments); + else + irc_send (s, "PART %s", channels); + // TODO: send the key if known + irc_send (s, "JOIN %s", channels); + } + else if (ctx->current_buffer->type != BUFFER_CHANNEL) + buffer_send_error (ctx, ctx->current_buffer, + "%s: %s", "Can't cycle", + "no argument given and this buffer is not a channel"); + // TODO: have a better way of checking if we're on the channel + else if (!ctx->current_buffer->channel->users) + buffer_send_error (ctx, ctx->current_buffer, + "%s: %s", "Can't cycle", "you're not on the channel"); + else + { + irc_send (s, "PART %s", ctx->current_buffer->channel->name); + // TODO: send the key if known + irc_send (s, "JOIN %s", ctx->current_buffer->channel->name); + } + return true; +} + static bool handle_command_connect (struct app_context *ctx, char *arguments) { @@ -5377,7 +5412,9 @@ g_command_handlers[] = { "part", "Leave channels", "[[,...]] [reason]", handle_command_part }, - NOT_IMPLEMENTED (cycle) + { "cycle", "Rejoin channels", + "[[,...]] [reason]", + handle_command_cycle }, NOT_IMPLEMENTED (mode) NOT_IMPLEMENTED (topic) -- cgit v1.2.3-70-g09d2