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'
This commit is contained in:
2026-05-01 00:51:51 +02:00
parent b03e4bedbe
commit a1c33e346d
+22 -5
View File
@@ -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: <me> <nick> :<channels> */
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: <me> <nick> <server> :<info> */
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: <me> <nick> :<text> */
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 */