diff options
-rw-r--r-- | degesch.c | 79 |
1 files changed, 77 insertions, 2 deletions
@@ -1988,6 +1988,77 @@ handle_command_quit (struct app_context *ctx, char *arguments) } static void +handle_command_join (struct app_context *ctx, char *arguments) +{ + if (ctx->current_buffer->type == BUFFER_GLOBAL) + { + buffer_send_error (ctx, ctx->current_buffer, + "Can't join from a global buffer"); + return; + } + + if (ctx->irc_fd == -1) + { + buffer_send_error (ctx, ctx->server_buffer, "Not connected"); + return; + } + + if (*arguments) + // TODO: check if the arguments are in the form of + // "channel(,channel)* key(,key)*" + irc_send (ctx, "JOIN %s", arguments); + else + { + if (ctx->current_buffer->type != BUFFER_CHANNEL) + buffer_send_error (ctx, ctx->current_buffer, + "%s: %s", "Can't join", + "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 join", + "you already are on the channel"); + else + // TODO: send the key if known + irc_send (ctx, "JOIN %s", ctx->current_buffer->channel->name); + } +} + +static void +handle_command_part (struct app_context *ctx, char *arguments) +{ + if (ctx->current_buffer->type == BUFFER_GLOBAL) + { + buffer_send_error (ctx, ctx->current_buffer, + "Can't part from a global buffer"); + return; + } + + if (ctx->irc_fd == -1) + { + buffer_send_error (ctx, ctx->server_buffer, "Not connected"); + return; + } + + if (*arguments) + // TODO: check if the arguments are in the form of "channel(,channel)*" + irc_send (ctx, "PART %s", arguments); + else + { + if (ctx->current_buffer->type != BUFFER_CHANNEL) + buffer_send_error (ctx, ctx->current_buffer, + "%s: %s", "Can't part", + "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 join", "you're not on the channel"); + else + irc_send (ctx, "PART %s", ctx->current_buffer->channel->name); + } +} + +static void handle_command_quote (struct app_context *ctx, char *arguments) { irc_send (ctx, arguments); @@ -2014,9 +2085,13 @@ g_command_handlers[] = { "notice", NULL, "", "" }, { "ctcp", NULL, "", "" }, { "me", NULL, "", "" }, +#endif - { "join", NULL, "", "" }, - { "part", NULL, "", "" }, + { "join", handle_command_join, "Join channels", + "[channel...]" }, + { "part", handle_command_part, "Leave channels", + "[channel...]" }, +#if 0 { "cycle", NULL, "", "" }, { "mode", NULL, "", "" }, |