degesch: add a #N format specifier
Fixes RPL_TOPICWHOTIME with some servers.
This commit is contained in:
parent
134e19adf0
commit
2b240b6631
54
degesch.c
54
degesch.c
|
@ -2060,6 +2060,7 @@ attribute_printer_update (struct attribute_printer *self)
|
||||||
// #S inserts a string from the server with unknown encoding
|
// #S inserts a string from the server with unknown encoding
|
||||||
// #m inserts a mIRC-formatted string (auto-resets at boundaries)
|
// #m inserts a mIRC-formatted string (auto-resets at boundaries)
|
||||||
// #n cuts the nickname from a string and automatically colours it
|
// #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)
|
// #a inserts named attributes (auto-resets)
|
||||||
// #r resets terminal attributes
|
// #r resets terminal attributes
|
||||||
|
@ -2217,6 +2218,26 @@ formatter_parse_nick (struct formatter *self, char *s)
|
||||||
FORMATTER_ADD_ITEM (self, FG_COLOR, .color = -1);
|
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 *
|
static const char *
|
||||||
formatter_parse_field (struct formatter *self,
|
formatter_parse_field (struct formatter *self,
|
||||||
const char *field, struct str *buf, va_list *ap)
|
const char *field, struct str *buf, va_list *ap)
|
||||||
|
@ -2253,6 +2274,9 @@ restart:
|
||||||
case 'n':
|
case 'n':
|
||||||
formatter_parse_nick (self, (s = va_arg (*ap, char *)));
|
formatter_parse_nick (self, (s = va_arg (*ap, char *)));
|
||||||
break;
|
break;
|
||||||
|
case 'N':
|
||||||
|
formatter_parse_nick_full (self, (s = va_arg (*ap, char *)));
|
||||||
|
break;
|
||||||
|
|
||||||
case 'a':
|
case 'a':
|
||||||
FORMATTER_ADD_ITEM (self, ATTR, .attribute = va_arg (*ap, int));
|
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, "!@"));
|
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 *
|
static const char *
|
||||||
irc_find_userhost (const char *prefix)
|
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
|
// Finally log the message
|
||||||
if (buffer)
|
if (buffer)
|
||||||
{
|
{
|
||||||
log_server (s, buffer, 0, "#a-->#r #n (#a#S#r) #a#s#r #S",
|
log_server (s, buffer, 0, "#a-->#r #N #a#s#r #S",
|
||||||
ATTR_JOIN, msg->prefix,
|
ATTR_JOIN, msg->prefix, ATTR_JOIN, "has joined", channel_name);
|
||||||
ATTR_USERHOST, irc_find_userhost (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;
|
struct formatter f;
|
||||||
formatter_init (&f, s->ctx, s);
|
formatter_init (&f, s->ctx, s);
|
||||||
formatter_add (&f, "#a<--#r #n (#a#S#r) #a#s#r #n",
|
formatter_add (&f, "#a<--#r #N #a#s#r #n",
|
||||||
ATTR_PART, msg->prefix,
|
ATTR_PART, msg->prefix, ATTR_PART, "has kicked", target);
|
||||||
ATTR_USERHOST, irc_find_userhost (msg->prefix),
|
|
||||||
ATTR_PART, "has kicked", target);
|
|
||||||
if (message)
|
if (message)
|
||||||
formatter_add (&f, " (#m)", message);
|
formatter_add (&f, " (#m)", message);
|
||||||
log_formatter (s->ctx, buffer, 0, &f);
|
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;
|
struct formatter f;
|
||||||
formatter_init (&f, s->ctx, s);
|
formatter_init (&f, s->ctx, s);
|
||||||
formatter_add (&f, "#a<--#r #n (#a#s#r) #a#s#r #S",
|
formatter_add (&f, "#a<--#r #N #a#s#r #S",
|
||||||
ATTR_PART, msg->prefix,
|
ATTR_PART, msg->prefix, ATTR_PART, "has left", channel_name);
|
||||||
ATTR_USERHOST, irc_find_userhost (msg->prefix),
|
|
||||||
ATTR_PART, "has left", channel_name);
|
|
||||||
if (message)
|
if (message)
|
||||||
formatter_add (&f, " (#m)", message);
|
formatter_add (&f, " (#m)", message);
|
||||||
log_formatter (s->ctx, buffer, 0, &f);
|
log_formatter (s->ctx, buffer, 0, &f);
|
||||||
|
@ -4839,9 +4855,8 @@ log_quit (struct server *s,
|
||||||
{
|
{
|
||||||
struct formatter f;
|
struct formatter f;
|
||||||
formatter_init (&f, s->ctx, s);
|
formatter_init (&f, s->ctx, s);
|
||||||
formatter_add (&f, "#a<--#r #n (#a#S#r) #a#s#r",
|
formatter_add (&f, "#a<--#r #N #a#s#r",
|
||||||
ATTR_PART, prefix, ATTR_USERHOST, irc_find_userhost (prefix),
|
ATTR_PART, prefix, ATTR_PART, "has quit");
|
||||||
ATTR_PART, "has quit");
|
|
||||||
if (reason)
|
if (reason)
|
||||||
formatter_add (&f, " (#m)", reason);
|
formatter_add (&f, " (#m)", reason);
|
||||||
log_formatter (s->ctx, buffer, 0, &f);
|
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)
|
if (buffer)
|
||||||
{
|
{
|
||||||
log_server_status (s, buffer, "Topic set by #n (#a#S#r) on #&s",
|
log_server_status (s, buffer, "Topic set by #N on #&s",
|
||||||
who, ATTR_USERHOST, irc_find_userhost (who),
|
who, make_time_string (changed));
|
||||||
make_time_string (changed));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue