- Added `MAX_LINES_PER_POLL = 50` constant and per-poll line counting in `irc_feed()`: the bot now drops excess lines when a single poll iteration delivers more than 50 complete IRC messages, preventing burst flooding from overwhelming the bot or triggering IRC server excess flood disconnects.
- Added `poll_lines_left` counter to `Session` struct, reset at the start of each poll cycle in `main()` before calling `irc_feed()`.
- Changed `RateLimitEntry` to track by `user@host` instead of nick: the rate limiter now keys on the full userhost extracted from the IRC prefix (`nick!user@host`) rather than the nick alone, preventing trivial bypass via nick cycling. Added `userhost[128]` field replacing the old `nick[32]` field.
- Added `current_userhost[128]` global variable, parsed from the IRC message prefix in `irc_handle()` before dispatching to command handlers. Updated `rate_limit_check()` signature to accept the userhost parameter.
- Added violation tracking to `RateLimitEntry` with a `violations` counter: repeated rate limit hits from the same userhost increment the counter, enabling future escalating penalties (warnings at 3 violations, kick requests at 5).
- Increased `RATE_LIMIT_MAX` from 8 to 32, expanding the rate limit tracking buffer to handle more concurrent users without evicting entries.
- Added outgoing message throttle to `net_send()`: uses `clock_gettime(CLOCK_MONOTONIC)` timestamp tracking to enforce a minimum `OUTGOING_DELAY_MS = 100` millisecond delay between consecutive sends, preventing the bot from flooding the IRC server with rapid bursts.
- Added 200ms inter-line delay in `!gitlog` output (`cmd_gitlog.h`): each commit line is now separated by a 200ms `nanosleep()` to avoid triggering IRC server flood protection on multi-commit responses.
- Added 150ms inter-chunk delay in AI response delivery (`ai.h`): multi-chunk AI answers now have a 150ms pause between chunks to pace outgoing traffic.
- Added `AI_COOLDOWN_SECS = 5` constant: after an AI query completes, a 5-second cooldown prevents immediate re-submission, reducing unnecessary load. Added `last_ai_completion` timestamp tracked in `ai.h` and checked in `ai_ask()`.
- Added rate limiting to casual chat and greeting responses (`cmd_greeting_or_chat.h`): the `rate_limit_check()` call now gates hardcoded greeting matches (hi, hey, hello, etc.) in addition to AI-forwarded messages.
- Limited `tell_deliver()` to `TELL_DELIVER_MAX = 5` messages per nick per delivery: excess pending messages remain in the database for the next time the user speaks, preventing a single user from triggering a flood of delivery messages.
- Updated all 19 command header files to pass `current_userhost` to the updated `rate_limit_check()` signature.
2026.07.25 - Welcome message for new users, channel tracking docs. (0.41.2)
- Added a welcome message when users join a channel: `handle_join()` now sends `"Welcome, <nick>!"` to the channel for non-bot users. The bot's own joins are silently ignored to avoid echo loops.
- Added `src_nick` parameter to `handle_join()` to identify the joining user; the call site in `irc_handle()` was updated to pass `src_nick`.
- Added doc comments to `chans[]` (global channel tracking array) and `nchans` (count of tracked channels) in `irc.h`.
2026.07.25 - Decode Unicode escapes in !yt responses. (0.41.1)
- Fixed `!yt` displaying raw JSON Unicode escape sequences (e.g. `\u0027` instead of `'`) in video titles and channel names. YouTube's oEmbed API returns non-ASCII characters as `\uXXXX` escapes, which were previously passed through as-is.
- Added `yt_hex_digit()` to convert a hex character to its numeric value.
- Added `yt_codepoint_to_utf8()` to encode a Unicode code point as UTF-8 bytes (handles U+0000 through U+10FFFF, producing 1-4 bytes).
- Added `yt_decode_unicode_escapes()` to scan a string for `\uXXXX` sequences and replace each with the corresponding UTF-8 bytes in-place. Safe for in-place modification because UTF-8 output is always shorter than the 6-byte escape.
- Both title and author fields are now decoded after extraction from the JSON response.
- Added doc comments to all three new helper functions.
2026.07.25 - YouTube title lookup command, json_find docs. (0.41.0)
- Added `!yt <url>` command: fetches the title and channel name of a YouTube video using the YouTube oEmbed API (`https://www.youtube.com/oembed`). The video URL is percent-encoded via a new `yt_url_encode()` helper before being passed as a query parameter. The JSON response is parsed for `title` and `author_name` fields using the existing `json_find()` helper, and the result is formatted as `"Title — Channel"`.
- Added `WITH_YT` CMake feature toggle (ON by default) with compile definition `HAS_CMD_YT`.
- Added `!yt` to the `!help` command listing.
- Added comprehensive doc comments to `yt_url_encode()` and `cmd_yt()` in `cmd_yt.h`, and to `json_find()` in `zynk.c`.
- Updated README.md: added YouTube title lookup to the feature summary, features list, feature toggles table, minimal build command, and IRC commands utilities table.
- Added `irc_reply()`: a new IRC response helper that automatically prepends the sender's nick to channel messages (e.g. `"nick: pong!"`), while leaving private-message responses unmodified. This makes it clear which user the bot is addressing in busy channels.
- Converted all non-admin command handlers to use `irc_reply()` instead of raw `irc_msg()`: `!ping`, `!zynk`, `!weather`, `!forecast`, `!stock`, `!calc`, `!time`, `!seen`, `!tell`, `!gitlog`, `!changelog`, `!ai`, `!uptime`, `!version`, `!help`, greeting/chat responses, and the `"Not implemented..."` fallback for unknown `!commands`.
- Converted AI async responses (`ai_check_completion()`) to use `irc_reply()`, so AI answers delivered after the original query also show the requesting user's nick.
- Converted AI error messages in `ai_ask()` (rate-limit busy, fork failure, start failure) to use `irc_reply()`.
- Removed redundant manual nick prefixes from commands that already embedded the sender's nick in their response text: `!ping` (`"nick: pong!"`), `!calc` (`"nick: result"`), `!time` (`"nick: 2026-07-24 ..."`), `!uptime` (`"nick: up 3d ..."`), and greeting/chat responses (`"Hi, nick!"` → `"nick: Hi!"`).
- Admin commands (`!quit`, `!reload`, `!restart`, `!rebuild`, `!code`) are intentionally excluded - these are privileged operations where the nick prefix adds no value.
- Added `secure_state_open()`: hardened file open with O_CLOEXEC, O_NOFOLLOW, mode 0600, regular-file and ownership checks. Prevents symlink attacks, TOCTOU races, and world-writable temp files.
- Replaced all `fopen()` calls for temp state files (`/tmp/zynk_reload`, `/tmp/zynk_code_restart`, `/tmp/zynk_make_err`, `/tmp/zynk_rebuild_err`) with `secure_state_open()` + `fdopen()` across hot reload, compile-restart, and rebuild paths.
- Hardened TLS initialization: enforces minimum TLS 1.2 (`SSL_CTX_set_min_proto_version`), disables compression (`SSL_OP_NO_COMPRESSION`), and checks the return value of `SSL_CTX_set_default_verify_paths()` instead of ignoring failures.
- Fixed `!quit`, `!reload`, `!restart` to require channel context - these commands now reject DM usage with a clear error instead of silently passing the op check.
2026.07.24 - Strip trailing space from wttr.in weather descriptions. (0.40.6)
- Fixed trailing space in weather descriptions from wttr.in (e.g. `"Partly Cloudy "` → `"Partly Cloudy"`), which caused a stray space before the closing parenthesis in `!forecast full` output (e.g. `(Partly Cloudy )` instead of `(Partly Cloudy)`). Applied the same fix to the non-full `cond` field used by `!forecast` and `!weather`.
- Added `full` keyword to `!forecast`: `!forecast frankfurt full` shows per-day detail lines with weather description, sunrise/sunset, and moonrise/moonset in 24-hour format, sent as separate IRC messages.
- Added `to_24h()` helper to convert wttr.in's 12-hour AM/PM astronomy times to 24-hour format.
- Fixed the missing first letter of weather descriptions in full mode (`"value": "` offset was 11 instead of 10).
- Startup message now includes the version: `[zynk 0.40.5] starting up`.
- Added doc comments to `to_24h()`, `find_day_obj()`, and other forecast helper functions.
- Fixed "Not implemented..." fallback to only trigger on `!` followed by a letter (e.g. `!foo`), so bare `!` or `!!!` no longer produce the message.
2026.07.23 - Raise AI code mode limit, simplify plan mode prompt. (0.40.4)
- Increased AI code mode response limit back to 2000 chars (was reduced to 1000 in 0.40.3, but code changes need more room).
- Simplified the AI plan mode system prompt further: removed the explicit "tell them you are in plan mode" instruction, keeping it to a short "You are in plan mode. Answer briefly." directive.
- Fixed `!gitlog` default count in README.md from 5 to 1 (matching the actual `GITLOG_COUNT` value set in 0.38.2).
- Refactored CMake feature configuration: merged the two separate `foreach` loops (one for building `_cmd_defs` and one for printing status) into a single loop, removing redundant iteration. Improved the status banner formatting for clearer feature configuration output.
- Reduced AI code mode response limit from 2000 to 1000 chars to keep IRC replies concise.
- Increased AI plan mode response limit from 800 to 1000 chars, giving slightly more room for explanations.
2026.07.23 - Show commit date/time in !gitlog output. (0.40.2)
-`!gitlog` now shows the commit date and time in `[YYYY-MM-DD HH:MM:SS]` format at the beginning of each commit line (e.g. `[2026-07-22 14:30:15] 184d4c4 Fix whitespace...`).
2026.07.23 - Fix !zynk key-value timestamps to use localtime. (0.40.1)
- Fixed `!zynk key = value` storing UTC timestamps instead of localtime: `db_set()` and the `zynk` table default used `datetime('now')` which returns UTC, causing `!zynk <key>` to display a timestamp offset by the server's timezone difference. Changed to `datetime('now','localtime')` so timestamps match the system's local time.
- Also fixed `db_rotate_history()` (used by AI query context) and the `tell` table default to use localtime.
2026.07.23 - Commit links for !gitlog, full changelog link for !changelog, CMake, multi-file refactor. (0.40.0)
-`!gitlog` now shows a link to each commit in the repository (e.g. `184d4c4 Fix whitespace... - https://...`), using the git remote URL converted from SSH/SCP to HTTPS.
-`!changelog` now shows a "Full changelog: <url>" link to CHANGELOG.md in the repository as the last message.
- Removed `full` keyword from `!gitlog` and `!changelog` (previously showed full commit messages and complete changelog entries).
- Switched the build system from Make to CMake with feature toggles (`-DWITH_<FEATURE>=ON/OFF`).
- Refactored a single-file codebase into dedicated header files: each command now lives in its own `cmd_*.h` file, with separate modules for database (`db.h`), IRC protocol (`irc.h`), networking (`net.h`), TLS (`tls.h`), and AI (`ai.h`).
- Updated README.md to reflect the simplified `!gitlog` and `!changelog` syntax and the new CMake build instructions.
- Fixed `collapse_spaces()` to treat tabs, newlines, and carriage returns as whitespace (not just spaces), collapsing any run of mixed whitespace into a single space.
-`collapse_spaces()` now strips leading and trailing whitespace from output.
- Added `collapse_spaces()` call to `!ai` responses (after `strip_ai_phrases()`).
- Added `collapse_spaces()` call to `!changelog full` entries before sending.
- Fixed `!gitlog full` output still containing multiple spaces from git's tab-delimited commit fields.
-`reload_do()` now accepts an `exec_new` parameter: when 0 (`!reload`/`!restart`), the child inherits the socket fd and SSL context directly and continues the event loop without reconnecting; when 1 (`!rebuild`/`!code`), the old fork+exec path is used.
-`!reload` and `!restart` now keep the bot's IRC session alive (no nick collision, no rejoin, no lost voice). `!rebuild`/`!code` still do a clean QUIT+exec since the binary changed.
- Added `strip_opencode_header()`: removes the opencode header line (e.g. `> plan · big-pickle`) and any trailing blank lines from AI responses before sending to IRC.
- Pipeline order: format strip → header strip → phrase strip, so ANSI codes are cleaned up first and the `> ` prefix is reliably detected.
- Added optional `full` keyword to `!gitlog` and `!changelog`: `!gitlog 5 full` shows full commit messages (author, date, body), `!changelog 5 full` shows the complete entry text including bullet points.
-`!gitlog` full mode collapses multiple spaces and strips leading whitespace from each commit block for cleaner IRC output.
- Changed `!rebuild` to skip `git pull` by default; pass `pull` to pull before rebuilding (e.g. `!rebuild pull`).
- Changed the default count `GITLOG_COUNT` for `!gitlog` from 5 to 1 and `CHANGELOG_COUNT` for `!changelog` from 5 to 1.
- Reduced `GITLOG_MAX` from 10 to 5.
- Updated `!help` text to reflect new `[full]` and `[pull]` arguments.
- Updated README.md with `full` option for `!gitlog`/`!changelog` and `pull` option for `!rebuild`.
- Added `!changelog [count]` command: displays the latest changelog entries from `CHANGELOG.md`. Defaults to five entries (`CHANGELOG_COUNT`), accepts 1-10 as count. Each entry title (date line) is sent as a separate IRC message with a 200ms delay to avoid IRC server flood protection.
- Added `!rebuild` command (ops only, channels): runs `git pull`, `make clean`, and `make` in sequence, then triggers a hot reload if all steps succeed. If any step fails, the error output from the build is reported to the channel.
- Updated `!help` to list `!rebuild`.
- Updated README.md with `!rebuild` documentation in the Admin (Ops Only) section.
- Fixed `!seen` command storing UTC timestamps instead of local time: `seen_update()` used `datetime('now')` which returns UTC, causing `!seen <nick>` to display a time offset by the server's timezone difference (e.g., 16:00 instead of 18:00 on a UTC+2 system). Changed to `datetime('now','localtime')` so seen timestamps match the system's local time.
- Added `!gitlog [count]` command: displays recent git commits of the zynk project using `git log --oneline`. Defaults to 5 commits (`GITLOG_COUNT`), accepts 1-20 as count. Each commit is sent as a separate IRC message.
-`!time` now outputs date and time only (`YYYY-MM-DD HH:MM:SS`) without the timezone abbreviation, keeping IRC responses shorter and cleaner.
- Removed 60 lines of dead timezone abbreviation-matching code from `tz_format()` (previously mapped 45 IANA timezone names to abbreviations like CEST, EDT, JST, etc.).
- Updated README.md output format to reflect the change.
- Added `tzdata` to README.md requirements as optional (without it, `!time` falls back to 45 built-in timezones).
- Rewrote `!time` to try the system `localtime_r()` first, then fall back to a built-in timezone table with 45 IANA zones and simplified DST rules when the system can't resolve timezones (e.g. no `tzdata` installed). This means `!time Australia/Sydney` now shows the correct AEST / AEDT even on minimal systems.
- Added `pi()` function support to `!calc`: bc -l does not define `pi()` on all systems, so `cmd_calc` now prepends a `pi()` definition before evaluating expressions. `!calc pi()`, `!calc pi()*2`, `!calc pi()^2` etc. all work.
- Fixed `!time` command: `setenv("TZ",...) + localtime()` was not reliably converting to the requested timezone. Replaced with `TZ=... date` via `popen()`, which handles all IANA timezone names correctly (e.g. `!time Australia/Sydney` now shows 11:15 AEST instead of UTC).
- Fixed `!calc` command: the expression was never piped to `bc`'s stdin, causing empty output and a "no result" error for every expression. Added a second pipe to feed the expression into `bc` before reading the result.
- 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`.
- Fixed `!forecast` showing all days as Sunday on musl libc (Alpine Linux): `strptime` on musl does not compute `tm_wday`, so added `mktime()` to normalize the struct before formatting.
- Fixed hot reload: after TLS session restore, the bot now re-sends PASS/NICK/USER to re-register with the IRC server, fixing the issue where channels were never re-joined after `!reload` or `!restart`.
- Added hot reload: `!reload` and `!restart` commands (ops) save TLS session state, fork a new process with the inherited socket, and resume without dropping from IRC.
- Added `!stock <SYMBOL>[,SYMBOL...]` command to fetch real-time stock quotes from Yahoo Finance (up to 3 symbols).
- Added auto-compile and restart on `!code` changes: when the AI code change response is received, the bot runs `make` and reloads on success.
- Added User-Agent header to curl requests to avoid being blocked by servers that reject the default curl agent.
- Increased curl read buffer from 2 KiB to 32 KiB to handle larger API responses.
- Improved `!forecast` JSON parsing: returns a descriptive error message on parse failure instead of silently returning nothing.
- Increased AI_TIMEOUT from 240s to 600s and AI_REPLY_MAX from 400 to 2048 chars for longer AI interactions.