From a1c33e346d4c36223faead5ab013ec59ffcd6176 Mon Sep 17 00:00:00 2001 From: Anders Holck Date: Fri, 1 May 2026 00:51:51 +0200 Subject: [PATCH] Fix WHOIS parsing (312/313/319), skip URL-only messages, suppress LLM refusals - Find ':' before null-terminating in WHOIS handlers - Add 313 (IRC Operator) handler - Skip messages that are just URLs from translation - Suppress LLM responses starting with 'I cannot'/'I can't' --- main.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 5ea9416..29dbb7b 100644 --- a/main.c +++ b/main.c @@ -194,6 +194,12 @@ static int needs_translation(const char *text) for (const char *p = text; *p; p++) if (*p == ' ') words++; if (words < 1 && strlen(text) < 6) return 0; + /* Skip messages that are just URLs */ + if (strncmp(text, "http://", 7) == 0 || strncmp(text, "https://", 8) == 0) { + /* If no space after URL, it's just a link */ + const char *sp = strchr(text, ' '); + if (!sp) return 0; + } /* Pre-filter: if text contains common words from skip languages, skip */ static const struct { const char *lang; const char *words[33]; } lang_words[] = { @@ -1007,23 +1013,23 @@ static void handle_line(char *line) wprintf(WL_STATUS, "*** %s is %s@%s (%s)\n", wnick, wuser, whost, real); } else if (strcmp(cmd, "319") == 0 && params) { /* RPL_WHOISCHANNELS: : */ + char *chans = strchr(params, ':'); + if (chans) chans++; char *p = params; char *sp = strchr(p, ' '); if (sp) p = sp + 1; char *wnick = p; sp = strchr(p, ' '); if (sp) *sp = '\0'; - char *chans = strchr(params, ':'); - if (chans) chans++; wprintf(WL_STATUS, "*** %s on channels: %s\n", wnick, chans ? chans : ""); } else if (strcmp(cmd, "312") == 0 && params) { /* RPL_WHOISSERVER: : */ + char *info = strchr(params, ':'); + if (info) info++; char *p = params; char *sp = strchr(p, ' '); if (sp) p = sp + 1; char *wnick = p; sp = strchr(p, ' '); if (sp) { *sp = '\0'; p = sp + 1; } char *server = p; sp = strchr(p, ' '); if (sp) *sp = '\0'; - char *info = strchr(params, ':'); - if (info) info++; wprintf(WL_STATUS, "*** %s on irc via server %s (%s)\n", wnick, server, info ? info : ""); } else if (strcmp(cmd, "317") == 0 && params) { @@ -1049,6 +1055,15 @@ static void handle_line(char *line) char *text = strchr(params, ':'); if (text) text++; wprintf(WL_STATUS, "*** %s %s\n", wnick, text ? text : ""); + } else if (strcmp(cmd, "313") == 0 && params) { + /* RPL_WHOISOPERATOR: : */ + char *text = strchr(params, ':'); + if (text) text++; + char *p = params; + char *sp = strchr(p, ' '); if (sp) p = sp + 1; + char *wnick = p; + sp = strchr(p, ' '); if (sp) *sp = '\0'; + wprintf(WL_STATUS, "*** %s %s\n", wnick, text ? text : "is an IRC Operator"); } else if (strcmp(cmd, "318") == 0 && params) { /* RPL_ENDOFWHOIS — suppress or show subtle */ wprintf(WL_STATUS, "*** End of WHOIS\n"); @@ -1574,7 +1589,9 @@ int main(int argc, char *argv[]) /* Also check old SKIP response */ if (strcasecmp(english, "SKIP") == 0 || - strncasecmp(english, "SKIP", 4) == 0) + strncasecmp(english, "SKIP", 4) == 0 || + strncasecmp(english, "I cannot", 8) == 0 || + strncasecmp(english, "I can't", 7) == 0) suppress = 1; /* Suppress if English translation matches original */