diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-06-20 20:13:37 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-06-20 20:13:37 +0200 |
commit | 0875bbfba7b46c77699d15a29522e663bddc41e0 (patch) | |
tree | 3e5238371ee783cfedad71f3ea454de5344a2552 /degesch.c | |
parent | 5d9b080d83e61e625df8501a96a5cac5c4680483 (diff) | |
download | xK-0875bbfba7b46c77699d15a29522e663bddc41e0.tar.gz xK-0875bbfba7b46c77699d15a29522e663bddc41e0.tar.xz xK-0875bbfba7b46c77699d15a29522e663bddc41e0.zip |
degesch: further cleanups
Diffstat (limited to 'degesch.c')
-rw-r--r-- | degesch.c | 69 |
1 files changed, 29 insertions, 40 deletions
@@ -6192,6 +6192,15 @@ handle_command_join (struct app_context *ctx, struct handler_args *a) return true; } +static void +part_channel (struct server *s, const char *channel_name, const char *reason) +{ + if (*reason) + irc_send (s, "PART %s :%s", channel_name, reason); + else + irc_send (s, "PART %s", channel_name); +} + static bool handle_command_part (struct app_context *ctx, struct handler_args *a) { @@ -6201,13 +6210,7 @@ handle_command_part (struct app_context *ctx, struct handler_args *a) str_vector_init (&v); split_str_ignore_empty (cut_word (&a->arguments), ' ', &v); for (size_t i = 0; i < v.len; i++) - { - // TODO: move this out - if (*a->arguments) - irc_send (a->s, "PART %s :%s", v.vector[i], a->arguments); - else - irc_send (a->s, "PART %s", v.vector[i]); - } + part_channel (a->s, v.vector[i], a->arguments); str_vector_free (&v); } else if (a->buffer->type != BUFFER_CHANNEL) @@ -6218,10 +6221,8 @@ handle_command_part (struct app_context *ctx, struct handler_args *a) else if (!a->buffer->channel->users) buffer_send_error (ctx, a->buffer, "%s: %s", "Can't part", "you're not on the channel"); - else if (*a->arguments) - irc_send (a->s, "PART %s :%s", a->buffer->channel->name, a->arguments); else - irc_send (a->s, "PART %s", a->buffer->channel->name); + part_channel (a->s, a->buffer->channel->name, a->arguments); return true; } @@ -6234,7 +6235,7 @@ cycle_channel (struct server *s, const char *channel_name, const char *reason) if ((channel = str_map_find (&s->irc_channels, channel_name))) key = str_map_find (&channel->param_modes, "k"); - if (reason) + if (*reason) irc_send (s, "PART %s :%s", channel_name, reason); else irc_send (s, "PART %s", channel_name); @@ -6254,9 +6255,7 @@ handle_command_cycle (struct app_context *ctx, struct handler_args *a) str_vector_init (&v); split_str_ignore_empty (cut_word (&a->arguments), ' ', &v); for (size_t i = 0; i < v.len; i++) - // TODO: just send the arguments, also elsewhere - cycle_channel (a->s, v.vector[i], - *a->arguments ? a->arguments : NULL); + cycle_channel (a->s, v.vector[i], a->arguments); str_vector_free (&v); } else if (a->buffer->type != BUFFER_CHANNEL) @@ -6267,10 +6266,8 @@ handle_command_cycle (struct app_context *ctx, struct handler_args *a) else if (!a->buffer->channel->users) buffer_send_error (ctx, a->buffer, "%s: %s", "Can't cycle", "you're not on the channel"); - else if (*a->arguments) - cycle_channel (a->s, a->buffer->channel->name, a->arguments); else - cycle_channel (a->s, a->buffer->channel->name, NULL); + cycle_channel (a->s, a->buffer->channel->name, a->arguments); return true; } @@ -6448,25 +6445,31 @@ handle_command_invite (struct app_context *ctx, struct handler_args *a) return result; } -static bool -handle_command_connect (struct app_context *ctx, struct handler_args *a) +static struct server * +resolve_server (struct app_context *ctx, struct handler_args *a, + const char *command_name) { struct server *s = NULL; if (*a->arguments) { char *server_name = cut_word (&a->arguments); if (!(s = str_map_find (&ctx->servers, server_name))) - buffer_send_error (ctx, ctx->global_buffer, "%s: %s: %s", - "Can't connect", "no such server", server_name); + buffer_send_error (ctx, ctx->global_buffer, "/%s: %s: %s", + command_name, "no such server", server_name); } else if (a->buffer->type == BUFFER_GLOBAL) - buffer_send_error (ctx, a->buffer, - "%s: %s", "Can't connect", - "no server name given and this buffer is global"); + buffer_send_error (ctx, a->buffer, "/%s: %s", + command_name, "no server name given and this buffer is global"); else s = a->buffer->server; + return s; +} - if (!s) +static bool +handle_command_connect (struct app_context *ctx, struct handler_args *a) +{ + struct server *s = NULL; + if (!(s = resolve_server (ctx, a, "connect"))) return true; if (irc_is_connected (s)) @@ -6486,21 +6489,7 @@ static bool handle_command_disconnect (struct app_context *ctx, struct handler_args *a) { struct server *s = NULL; - if (*a->arguments) - { - char *server_name = cut_word (&a->arguments); - if (!(s = str_map_find (&ctx->servers, server_name))) - buffer_send_error (ctx, a->buffer, "%s: %s: %s", - "Can't disconnect", "no such server", server_name); - } - else if (a->buffer->type == BUFFER_GLOBAL) - buffer_send_error (ctx, a->buffer, - "%s: %s", "Can't disconnect", - "no server name given and this buffer is global"); - else - s = a->buffer->server; - - if (!s) + if (!(s = resolve_server (ctx, a, "disconnect"))) return true; if (s->state == IRC_CONNECTING) |