degesch: factor out send_message_to_target()
And check that we're actually connected.
This commit is contained in:
parent
953bc72e2b
commit
51415c1db6
26
degesch.c
26
degesch.c
@ -2329,6 +2329,22 @@ process_user_command (struct app_context *ctx, char *command)
|
|||||||
"%s: %s", "No such command", name);
|
"%s: %s", "No such command", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
static void
|
||||||
send_message_to_current_buffer (struct app_context *ctx, char *message)
|
send_message_to_current_buffer (struct app_context *ctx, char *message)
|
||||||
{
|
{
|
||||||
@ -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");
|
buffer_send_error (ctx, buffer, "This buffer is not a channel");
|
||||||
break;
|
break;
|
||||||
case BUFFER_CHANNEL:
|
case BUFFER_CHANNEL:
|
||||||
// TODO: autosplit
|
send_message_to_target (ctx, buffer->channel->name, message, buffer);
|
||||||
irc_send (ctx, "PRIVMSG %s :%s", buffer->channel->name, message);
|
|
||||||
buffer_send (ctx, buffer, BUFFER_LINE_PRIVMSG, 0,
|
|
||||||
ctx->irc_nickname, NULL, "%s", message);
|
|
||||||
break;
|
break;
|
||||||
case BUFFER_PM:
|
case BUFFER_PM:
|
||||||
// TODO: autosplit
|
send_message_to_target (ctx, buffer->user->nickname, message, buffer);
|
||||||
irc_send (ctx, "PRIVMSG %s :%s", buffer->user->nickname, message);
|
|
||||||
buffer_send (ctx, buffer, BUFFER_LINE_PRIVMSG, 0,
|
|
||||||
ctx->irc_nickname, NULL, "%s", message);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user