diff options
author | June McEnroe <june@causal.agency> | 2021-06-20 19:46:07 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2021-06-20 19:46:07 -0400 |
commit | 06c5342cfe158e2dbce8dd3bbbb07e757d6c219e (patch) | |
tree | d78a423682d0ae65cdcc1c6f3c5ab5dcc789958f | |
parent | Fix MOTD buffer reallocation (diff) | |
download | litterbox-06c5342cfe158e2dbce8dd3bbbb07e757d6c219e.tar.gz litterbox-06c5342cfe158e2dbce8dd3bbbb07e757d6c219e.zip |
Tighten action handling
Don't match actions in notices. Match empty "\1ACTION\1" actions. Don't truncate at the first '\1'.
Diffstat (limited to '')
-rw-r--r-- | litterbox.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/litterbox.c b/litterbox.c index 48e5b60..707a0a0 100644 --- a/litterbox.c +++ b/litterbox.c @@ -432,6 +432,23 @@ static void insertEvent( dbRun(stmt); } +static enum Type messageType(struct Message *msg) { + if (msg->cmd[0] == 'N') return Notice; + if (strncmp(msg->params[1], "\1ACTION", 7)) return Privmsg; + if (msg->params[1][7] == ' ') { + msg->params[1] += 8; + } else if (msg->params[1][7] == '\1') { + msg->params[1] += 7; + } else { + return Privmsg; + } + size_t len = strlen(msg->params[1]); + if (msg->params[1][len - 1] == '\1') { + msg->params[1][len - 1] = '\0'; + } + return Action; +} + static void handlePrivmsg(struct Message *msg) { require(msg, true, 2); @@ -440,14 +457,7 @@ static void handlePrivmsg(struct Message *msg) { if (statusmsg) context += strspn(context, statusmsg); if (strchr(chanTypes, context[0])) query = false; if (!strcmp(context, self)) context = msg->nick; - - enum Type type = (!strcmp(msg->cmd, "NOTICE") ? Notice : Privmsg); - char *message = msg->params[1]; - if (!strncmp(message, "\1ACTION ", 8)) { - message += 8; - message[strcspn(message, "\1")] = '\0'; - type = Action; - } + enum Type type = messageType(msg); bool selfMessage = !strcmp(msg->nick, msg->params[0]); if (query && searchQuery && type == Privmsg) { @@ -460,7 +470,7 @@ static void handlePrivmsg(struct Message *msg) { insertContext(context, query); insertName(msg); - insertEvent(msg, type, context, NULL, message); + insertEvent(msg, type, context, NULL, msg->params[1]); } static void insertTopic( |