From 5d308750e145d327af9f84d84a1f5f335e82f7d6 Mon Sep 17 00:00:00 2001 From: hanez Date: Sun, 19 Jul 2026 02:06:32 +0200 Subject: [PATCH] Add !uptime command, remove !hello, bump to v0.34.0 (0.34.0) --- CHANGELOG.md | 11 ++++++++++- zynk.c | 41 ++++++++++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0be2b10..1de8256 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ -2026.07.19 – Hot reload re-registration fix. +2026.07.19 – Uptime command, remove !hello. + +- Added `!uptime` command: displays bot uptime in a human-readable format (days/hours/minutes/seconds). +- Removed `!hello` command. +- Version bumped to 0.34.0. + +2026.07.19 – Hot reload re-registration fix, !hello, docs. - 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 `!hello` command: responds with a greeting and the user's nick. +- Added atomic build target in Makefile: compiles to a temp file and moves into place to avoid partial binaries on failure. +- Added comprehensive doc comments to all major functions in zynk.c. - Version bumped to 0.33.1. 2026.07.19 – Hot reload, stock quotes, and auto-recompile. diff --git a/zynk.c b/zynk.c index ba2c8bc..69de811 100644 --- a/zynk.c +++ b/zynk.c @@ -29,7 +29,7 @@ int asprintf(char **, const char *, ...); /* ---- constants ---- */ -#define VERSION "0.33.1" +#define VERSION "0.34.0" #define DEFAULT_SERVER "irc.libera.chat" #define OPENCODE_BIN "/usr/bin/opencode" #define CLR_RESET "\033[0m" @@ -1136,6 +1136,7 @@ static void reload_do(Session *s, const char *reply_target) { /* ---- signal handling ---- */ static volatile sig_atomic_t running = 1; +static time_t start_time; /* * handle_sigterm - Signal handler for SIGINT and SIGTERM. @@ -2062,16 +2063,6 @@ static int cmd_ping(Session *s, const char *msg, const char *reply_target, const return 1; } -static int cmd_hello(Session *s, const char *msg, const char *reply_target, const char *src_nick) { - if (strncmp(msg, "!hello", 6) != 0) return 0; - if (msg[6] != ' ' && msg[6] != '\0') return 0; - if (rate_limit_check(src_nick) < 0) return 1; - char buf[96]; snprintf(buf, sizeof buf, "hello, %s!", src_nick); - irc_msg(s, reply_target, buf); - log_stamp(); fprintf(stderr, CLR_YELLOW "HELLO from %s in %s" CLR_RESET "\n", src_nick, reply_target); - return 1; -} - /* * cmd_version - Handle the "!version" command. * @@ -2105,7 +2096,7 @@ static int cmd_help(Session *s, const char *msg, const char *reply_target, const if (rate_limit_check(src_nick) < 0) return 1; char buf[512]; snprintf(buf, sizeof buf, - "Commands: !help, !version, !ping, !hello, !weather [city], !forecast [city], !stock [,SYMBOL...], !ai , !code (ops), !reload (ops), !restart (ops), !quit/!die (ops)"); + "Commands: !help, !version, !ping, !uptime, !weather [city], !forecast [city], !stock [,SYMBOL...], !ai , !code (ops), !reload (ops), !restart (ops), !quit/!die (ops)"); irc_msg(s, reply_target, buf); log_stamp(); fprintf(stderr, CLR_CYAN "HELP from %s in %s" CLR_RESET "\n", src_nick, reply_target); return 1; @@ -2386,6 +2377,29 @@ static int cmd_code(Session *s, const char *msg, const char *reply_target, const * * Returns: 1 if matched, 0 otherwise. */ +static int cmd_uptime(Session *s, const char *msg, const char *reply_target, const char *src_nick) { + if (strncmp(msg, "!uptime", 7) != 0) return 0; + if (msg[7] != ' ' && msg[7] != '\0') return 0; + if (rate_limit_check(src_nick) < 0) return 1; + time_t diff = time(NULL) - start_time; + long days = diff / 86400; + long hours = (diff % 86400) / 3600; + long mins = (diff % 3600) / 60; + long secs = diff % 60; + char buf[128]; + if (days > 0) + snprintf(buf, sizeof buf, "%s: up %ldd %ldh %ldm %lds", src_nick, days, hours, mins, secs); + else if (hours > 0) + snprintf(buf, sizeof buf, "%s: up %ldh %ldm %lds", src_nick, hours, mins, secs); + else if (mins > 0) + snprintf(buf, sizeof buf, "%s: up %ldm %lds", src_nick, mins, secs); + else + snprintf(buf, sizeof buf, "%s: up %lds", src_nick, secs); + irc_msg(s, reply_target, buf); + log_stamp(); fprintf(stderr, CLR_YELLOW "UPTIME from %s in %s" CLR_RESET "\n", src_nick, reply_target); + return 1; +} + static int cmd_reload(Session *s, const char *msg, const char *reply_target, const char *src_nick, const char *tgt) { if (strcmp(msg, "!reload") != 0) return 0; if (tgt[0] == '#' && !chan_is_op(tgt, src_nick)) { @@ -2505,8 +2519,8 @@ static void handle_privmsg(Session *s, const char *params, const char *src_nick) const char *reply_target = (tgt[0] == '#') ? tgt : src_nick; if (cmd_zynk(s, msg, reply_target, src_nick, tgt)) return; if (cmd_ping(s, msg, reply_target, src_nick)) return; - if (cmd_hello(s, msg, reply_target, src_nick)) return; if (cmd_version(s, msg, reply_target, src_nick)) return; + if (cmd_uptime(s, msg, reply_target, src_nick)) return; if (cmd_help(s, msg, reply_target, src_nick)) return; if (cmd_quit(s, msg, reply_target, src_nick, tgt)) return; if (cmd_weather(s, msg, reply_target, src_nick)) return; @@ -3048,6 +3062,7 @@ int main(int argc, char **argv) { sqlite_cleanup(); return 1; } + start_time = time(NULL); Session s; memset(&s, 0, sizeof s); snprintf(s.host, sizeof s.host, "%s", sv);