2
0
Fork 0
forked from zynk/zynk

Collapse double spaces in !forecast and !stock responses

Add collapse_spaces() utility that reduces runs of whitespace to a
single space. Applied to fetch_forecast() output and the !stock
response buffer before sending to IRC, fixing double spaces that
appeared when wttr.in returned an empty weather condition string
(e.g. "15°C  / Sun 20 Jul" instead of "15°C / Sun 20 Jul").

Bump version to 0.34.2.
This commit is contained in:
Johannes Findeisen 2026-07-19 19:54:36 +02:00
commit 335d35a7b8
2 changed files with 19 additions and 1 deletions

View file

@ -1,3 +1,8 @@
2026.07.19 – Collapsed double spaces in `!forecast` and `!stock` responses
- Collapsed double spaces in `!forecast` and `!stock` responses (e.g., when weather condition is empty).
- Version bumped to 0.34.2.
2026.07.19 – Fix !weather returning HTML.
- Fixed `!weather` command returning `<!DOCTYPE html>` instead of weather data: wttr.in now returns HTML when it detects a browser User-Agent, so replaced the fake Firefox UA string with `zynk/VERSION`.

15
zynk.c
View file

@ -29,7 +29,7 @@ int asprintf(char **, const char *, ...);
/* ---- constants ---- */
#define VERSION "0.34.1"
#define VERSION "0.34.2"
#define DEFAULT_SERVER "irc.libera.chat"
#define OPENCODE_BIN "/usr/bin/opencode"
#define CLR_RESET "\033[0m"
@ -1384,6 +1384,17 @@ static void normalize_city(const char *in, char *display, size_t dsz, char *url,
}
}
static void collapse_spaces(char *s) {
char *r = s, *w = s;
int space = 0;
while (*r) {
if (*r == ' ') { if (!space) *w++ = ' '; space = 1; }
else { *w++ = *r; space = 0; }
r++;
}
*w = 0;
}
/* ---- curl helper ---- */
/*
@ -1516,6 +1527,7 @@ static char *fetch_forecast(const char *city_url, const char *city_display) {
if (ndays == 1) { if (asprintf(&out, "Forecast for %s: %s", city_display, line[0]) < 0) out = NULL; }
else if (ndays == 2) { if (asprintf(&out, "Forecast for %s: %s / %s", city_display, line[0], line[1]) < 0) out = NULL; }
else { if (asprintf(&out, "Forecast for %s: %s / %s / %s", city_display, line[0], line[1], line[2]) < 0) out = NULL; }
if (out) collapse_spaces(out);
return out;
}
@ -2296,6 +2308,7 @@ static int cmd_stock(Session *s, const char *msg, const char *reply_target, cons
free(json);
}
if (!buf[0]) snprintf(buf, sizeof buf, "Stock: could not fetch data");
collapse_spaces(buf);
irc_msg(s, reply_target, buf);
log_stamp(); fprintf(stderr, CLR_MAGENTA "STOCK %s from %s:" CLR_RESET " %s\n", reply_target, src_nick, buf);
return 1;