degesch: implement /me

This commit is contained in:
Přemysl Eric Janouch 2015-04-26 23:30:54 +02:00
parent 21b8e8e539
commit 5ad6d7cfbc
1 changed files with 37 additions and 5 deletions

View File

@ -3079,13 +3079,16 @@ struct send_autosplit_args
const char *target; ///< User or channel
const char *message; ///< A message to be autosplit
send_autosplit_logger_fn logger; ///< Logger for all resulting lines
const char *prefix; ///< E.g. "\x01ACTION"
const char *suffix; ///< E.g. "\x01"
};
static void
send_autosplit_message (struct app_context *ctx, struct send_autosplit_args a)
{
struct buffer *buffer = str_map_find (&ctx->irc_buffer_map, a.target);
int fixed_part = strlen (a.command) + 1 + strlen (a.target) + 1 + 1;
int fixed_part = strlen (a.command) + 1 + strlen (a.target) + 1 + 1
+ strlen (a.prefix) + strlen (a.suffix);
struct str_vector lines;
str_vector_init (&lines);
@ -3100,13 +3103,33 @@ send_autosplit_message (struct app_context *ctx, struct send_autosplit_args a)
for (size_t i = 0; i < lines.len; i++)
{
irc_send (ctx, "%s %s :%s", a.command, a.target, lines.vector[i]);
irc_send (ctx, "%s %s :%s%s%s", a.command, a.target,
a.prefix, lines.vector[i], a.suffix);
a.logger (ctx, &a, buffer, lines.vector[i]);
}
end:
str_vector_free (&lines);
}
static void
log_outcoming_action (struct app_context *ctx,
struct send_autosplit_args *a, struct buffer *buffer, const char *line)
{
(void) a;
if (buffer)
buffer_send (ctx, buffer, BUFFER_LINE_ACTION, 0,
.who = irc_to_utf8 (ctx, ctx->irc_user->nickname),
.text = irc_to_utf8 (ctx, line));
// This can only be sent from a user or channel buffer
}
#define SEND_AUTOSPLIT_ACTION(ctx, target, message) \
send_autosplit_message ((ctx), (struct send_autosplit_args) \
{ "PRIVMSG", (target), (message), log_outcoming_action, \
"\x01" "ACTION ", "\x01" })
static void
log_outcoming_privmsg (struct app_context *ctx,
struct send_autosplit_args *a, struct buffer *buffer, const char *line)
@ -3123,7 +3146,7 @@ log_outcoming_privmsg (struct app_context *ctx,
#define SEND_AUTOSPLIT_PRIVMSG(ctx, target, message) \
send_autosplit_message ((ctx), (struct send_autosplit_args) \
{ "PRIVMSG", (target), (message), log_outcoming_privmsg })
{ "PRIVMSG", (target), (message), log_outcoming_privmsg, "", "" })
static void
log_outcoming_notice (struct app_context *ctx,
@ -3141,7 +3164,7 @@ log_outcoming_notice (struct app_context *ctx,
#define SEND_AUTOSPLIT_NOTICE(ctx, target, message) \
send_autosplit_message ((ctx), (struct send_autosplit_args) \
{ "NOTICE", (target), (message), log_outcoming_notice })
{ "NOTICE", (target), (message), log_outcoming_notice, "", "" })
// --- User input handling -----------------------------------------------------
@ -3350,7 +3373,16 @@ handle_command_me (struct app_context *ctx, char *arguments)
if (!server_command_check (ctx, "send messages"))
return true;
// TODO
if (ctx->current_buffer->type == BUFFER_CHANNEL)
SEND_AUTOSPLIT_ACTION (ctx,
ctx->current_buffer->channel->name, arguments);
else if (ctx->current_buffer->type == BUFFER_PM)
SEND_AUTOSPLIT_ACTION (ctx,
ctx->current_buffer->user->nickname, arguments);
else
buffer_send_error (ctx, ctx->server_buffer,
"Can't do this from a server buffer (%s)",
"send CTCP actions");
return true;
}