degesch: add a #N format specifier

Fixes RPL_TOPICWHOTIME with some servers.
This commit is contained in:
Přemysl Eric Janouch 2015-06-29 08:54:00 +02:00
parent 134e19adf0
commit 2b240b6631
1 changed files with 34 additions and 20 deletions

View File

@ -2060,6 +2060,7 @@ attribute_printer_update (struct attribute_printer *self)
// #S inserts a string from the server with unknown encoding
// #m inserts a mIRC-formatted string (auto-resets at boundaries)
// #n cuts the nickname from a string and automatically colours it
// #N is like #n but also appends userhost, if present
//
// #a inserts named attributes (auto-resets)
// #r resets terminal attributes
@ -2217,6 +2218,26 @@ formatter_parse_nick (struct formatter *self, char *s)
FORMATTER_ADD_ITEM (self, FG_COLOR, .color = -1);
}
static void
formatter_parse_nick_full (struct formatter *self, char *s)
{
formatter_parse_nick (self, s);
const char *userhost;
if (!(userhost = irc_find_userhost (s)))
return;
FORMATTER_ADD_TEXT (self, " (");
FORMATTER_ADD_ITEM (self, ATTR, .attribute = ATTR_USERHOST);
char *x = irc_to_utf8 (self->ctx, userhost);
FORMATTER_ADD_TEXT (self, x);
free (x);
FORMATTER_ADD_RESET (self);
FORMATTER_ADD_TEXT (self, ")");
}
static const char *
formatter_parse_field (struct formatter *self,
const char *field, struct str *buf, va_list *ap)
@ -2253,6 +2274,9 @@ restart:
case 'n':
formatter_parse_nick (self, (s = va_arg (*ap, char *)));
break;
case 'N':
formatter_parse_nick_full (self, (s = va_arg (*ap, char *)));
break;
case 'a':
FORMATTER_ADD_ITEM (self, ATTR, .attribute = va_arg (*ap, int));
@ -3976,8 +4000,6 @@ irc_cut_nickname (const char *prefix)
return xstrndup (prefix, strcspn (prefix, "!@"));
}
// XXX: shouldn't we rather return "" on failure? Or just make a wrapper
// for logging purposes, to be more resilient?
static const char *
irc_find_userhost (const char *prefix)
{
@ -4390,10 +4412,8 @@ irc_handle_join (struct server *s, const struct irc_message *msg)
// Finally log the message
if (buffer)
{
log_server (s, buffer, 0, "#a-->#r #n (#a#S#r) #a#s#r #S",
ATTR_JOIN, msg->prefix,
ATTR_USERHOST, irc_find_userhost (msg->prefix),
ATTR_JOIN, "has joined", channel_name);
log_server (s, buffer, 0, "#a-->#r #N #a#s#r #S",
ATTR_JOIN, msg->prefix, ATTR_JOIN, "has joined", channel_name);
}
}
@ -4432,10 +4452,8 @@ irc_handle_kick (struct server *s, const struct irc_message *msg)
{
struct formatter f;
formatter_init (&f, s->ctx, s);
formatter_add (&f, "#a<--#r #n (#a#S#r) #a#s#r #n",
ATTR_PART, msg->prefix,
ATTR_USERHOST, irc_find_userhost (msg->prefix),
ATTR_PART, "has kicked", target);
formatter_add (&f, "#a<--#r #N #a#s#r #n",
ATTR_PART, msg->prefix, ATTR_PART, "has kicked", target);
if (message)
formatter_add (&f, " (#m)", message);
log_formatter (s->ctx, buffer, 0, &f);
@ -4689,10 +4707,8 @@ irc_handle_part (struct server *s, const struct irc_message *msg)
{
struct formatter f;
formatter_init (&f, s->ctx, s);
formatter_add (&f, "#a<--#r #n (#a#s#r) #a#s#r #S",
ATTR_PART, msg->prefix,
ATTR_USERHOST, irc_find_userhost (msg->prefix),
ATTR_PART, "has left", channel_name);
formatter_add (&f, "#a<--#r #N #a#s#r #S",
ATTR_PART, msg->prefix, ATTR_PART, "has left", channel_name);
if (message)
formatter_add (&f, " (#m)", message);
log_formatter (s->ctx, buffer, 0, &f);
@ -4839,9 +4855,8 @@ log_quit (struct server *s,
{
struct formatter f;
formatter_init (&f, s->ctx, s);
formatter_add (&f, "#a<--#r #n (#a#S#r) #a#s#r",
ATTR_PART, prefix, ATTR_USERHOST, irc_find_userhost (prefix),
ATTR_PART, "has quit");
formatter_add (&f, "#a<--#r #N #a#s#r",
ATTR_PART, prefix, ATTR_PART, "has quit");
if (reason)
formatter_add (&f, " (#m)", reason);
log_formatter (s->ctx, buffer, 0, &f);
@ -5272,9 +5287,8 @@ irc_handle_rpl_topicwhotime (struct server *s, const struct irc_message *msg)
if (buffer)
{
log_server_status (s, buffer, "Topic set by #n (#a#S#r) on #&s",
who, ATTR_USERHOST, irc_find_userhost (who),
make_time_string (changed));
log_server_status (s, buffer, "Topic set by #N on #&s",
who, make_time_string (changed));
}
}