diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-19 22:20:03 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-19 22:26:30 +0200 |
commit | 51415c1db6550534a4aefb8ec8405b21599819e0 (patch) | |
tree | 040d3206f263c5e2cc957f51e2069b7d11f31cda | |
parent | 953bc72e2b4696d4f89e8335426950a56a0b639f (diff) | |
download | xK-51415c1db6550534a4aefb8ec8405b21599819e0.tar.gz xK-51415c1db6550534a4aefb8ec8405b21599819e0.tar.xz xK-51415c1db6550534a4aefb8ec8405b21599819e0.zip |
degesch: factor out send_message_to_target()
And check that we're actually connected.
-rw-r--r-- | degesch.c | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -2330,6 +2330,22 @@ process_user_command (struct app_context *ctx, char *command) } static void +send_message_to_target (struct app_context *ctx, + const char *target, char *message, struct buffer *buffer) +{ + if (ctx->irc_fd == -1) + { + buffer_send_error (ctx, buffer, "Not connected"); + return; + } + + // TODO: autosplit + irc_send (ctx, "PRIVMSG %s :%s", target, message); + buffer_send (ctx, buffer, BUFFER_LINE_PRIVMSG, 0, + ctx->irc_nickname, NULL, "%s", message); +} + +static void send_message_to_current_buffer (struct app_context *ctx, char *message) { struct buffer *buffer = ctx->current_buffer; @@ -2342,16 +2358,10 @@ send_message_to_current_buffer (struct app_context *ctx, char *message) buffer_send_error (ctx, buffer, "This buffer is not a channel"); break; case BUFFER_CHANNEL: - // TODO: autosplit - irc_send (ctx, "PRIVMSG %s :%s", buffer->channel->name, message); - buffer_send (ctx, buffer, BUFFER_LINE_PRIVMSG, 0, - ctx->irc_nickname, NULL, "%s", message); + send_message_to_target (ctx, buffer->channel->name, message, buffer); break; case BUFFER_PM: - // TODO: autosplit - irc_send (ctx, "PRIVMSG %s :%s", buffer->user->nickname, message); - buffer_send (ctx, buffer, BUFFER_LINE_PRIVMSG, 0, - ctx->irc_nickname, NULL, "%s", message); + send_message_to_target (ctx, buffer->user->nickname, message, buffer); break; } } |