diff --git a/CHANGELOG.md b/CHANGELOG.md index c8459d6..c860393 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 `` 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`. diff --git a/zynk.c b/zynk.c index 37b5160..9fb0144 100644 --- a/zynk.c +++ b/zynk.c @@ -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;