aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--degesch.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/degesch.c b/degesch.c
index 1d7bf96..34ee64c 100644
--- a/degesch.c
+++ b/degesch.c
@@ -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;
}
}