diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a823c4..8bc0cd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +2026.07.20 – Add !rebuild command. + +- 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. +- Version bumped to 0.37.0. + 2026.07.20 – Fix !seen showing UTC instead of local time. - Fixed `!seen` command storing UTC timestamps instead of local time: `seen_update()` used `datetime('now')` which returns UTC, causing `!seen ` 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. diff --git a/README.md b/README.md index 891f040..67f4db7 100644 --- a/README.md +++ b/README.md @@ -249,6 +249,7 @@ The calculator uses `bc -l` (POSIX arbitrary-precision calculator with the math |---|---| | `!reload` | Hot reload (save TLS state, fork new process) | | `!restart` | Restart the bot | +| `!rebuild` | Git pull, rebuild, and restart (ops only, in channels) | | `!code ` | Make AI-powered code changes | ### Chat diff --git a/zynk.c b/zynk.c index 42bcc55..40a2a0d 100644 --- a/zynk.c +++ b/zynk.c @@ -29,7 +29,7 @@ int asprintf(char **, const char *, ...); /* ---- constants ---- */ -#define VERSION "0.36.1" +#define VERSION "0.37.0" #define DEFAULT_SERVER "irc.libera.chat" #define OPENCODE_BIN "/usr/bin/opencode" #define CLR_RESET "\033[0m" @@ -2305,7 +2305,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, !uptime, !weather [city], !forecast [city], !stock , !calc , !time [tz], !seen , !tell , !gitlog [count], !ai , !code (ops), !reload (ops), !restart (ops), !quit/!die (ops)"); + "Commands: !help, !version, !ping, !uptime, !weather [city], !forecast [city], !stock , !calc , !time [tz], !seen , !tell , !gitlog [count], !ai , !code (ops), !rebuild (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; @@ -3089,6 +3089,72 @@ static int cmd_gitlog(Session *s, const char *msg, const char *reply_target, con return 1; } +/* + * cmd_rebuild - Handle the "!rebuild" command. + * + * Requires channel op and must be used in a channel. Runs "git pull", + * "make clean", and "make" in sequence. If all steps succeed, triggers + * a hot reload via reload_do(). If any step fails, reports the error + * from the build output. Rate-limited. + * + * Returns: 1 if matched, 0 otherwise. + */ +static int cmd_rebuild(Session *s, const char *msg, const char *reply_target, const char *src_nick, const char *tgt) { + if (strcmp(msg, "!rebuild") != 0) return 0; + if (tgt[0] != '#') { + irc_msg(s, reply_target, "!rebuild can only be used in a channel"); + return 1; + } + if (!chan_is_op(tgt, src_nick)) { + irc_msg(s, reply_target, "You need op to rebuild"); + return 1; + } + if (rate_limit_check(src_nick) < 0) return 1; + irc_msg(s, reply_target, "Rebuilding..."); + log_stamp(); fprintf(stderr, CLR_GREEN "REBUILD from %s in %s" CLR_RESET "\n", src_nick, reply_target); + int status; + char errbuf[512]; + status = system("git pull 2>/tmp/zynk_rebuild_err"); + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { + char msg_buf[640]; + FILE *f = fopen("/tmp/zynk_rebuild_err", "r"); + if (f) { size_t n = fread(errbuf, 1, sizeof errbuf - 1, f); errbuf[n] = 0; fclose(f); char *nl = strchr(errbuf, '\n'); if (nl) *nl = 0; } + else snprintf(errbuf, sizeof errbuf, "unknown error"); + snprintf(msg_buf, sizeof msg_buf, "Rebuild failed (git pull): %s", errbuf); + irc_msg(s, reply_target, msg_buf); + log_stamp(); fprintf(stderr, CLR_RED "REBUILD git pull failed:" CLR_RESET " %s\n", errbuf); + return 1; + } + status = system("make clean 2>/tmp/zynk_rebuild_err"); + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { + char msg_buf[640]; + FILE *f = fopen("/tmp/zynk_rebuild_err", "r"); + if (f) { size_t n = fread(errbuf, 1, sizeof errbuf - 1, f); errbuf[n] = 0; fclose(f); char *nl = strchr(errbuf, '\n'); if (nl) *nl = 0; } + else snprintf(errbuf, sizeof errbuf, "unknown error"); + snprintf(msg_buf, sizeof msg_buf, "Rebuild failed (make clean): %s", errbuf); + irc_msg(s, reply_target, msg_buf); + log_stamp(); fprintf(stderr, CLR_RED "REBUILD make clean failed:" CLR_RESET " %s\n", errbuf); + return 1; + } + status = system("make 2>/tmp/zynk_rebuild_err"); + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { + irc_msg(s, reply_target, "Build successful, restarting..."); + log_stamp(); fprintf(stderr, CLR_GREEN "REBUILD successful, restarting..." CLR_RESET "\n"); + FILE *cf = fopen("/tmp/zynk_code_restart", "w"); + if (cf) { fprintf(cf, "%s\n", reply_target); fclose(cf); } + reload_do(s, reply_target); + } else { + FILE *f = fopen("/tmp/zynk_rebuild_err", "r"); + if (f) { size_t n = fread(errbuf, 1, sizeof errbuf - 1, f); errbuf[n] = 0; fclose(f); char *nl = strchr(errbuf, '\n'); if (nl) *nl = 0; } + else snprintf(errbuf, sizeof errbuf, "unknown error"); + char msg_buf[640]; + snprintf(msg_buf, sizeof msg_buf, "Rebuild failed (make): %s", errbuf); + irc_msg(s, reply_target, msg_buf); + log_stamp(); fprintf(stderr, CLR_RED "REBUILD make failed:" CLR_RESET " %s\n", errbuf); + } + return 1; +} + /* * cmd_greeting_or_chat - Handle informal greetings and chat messages. * @@ -3193,6 +3259,7 @@ static void handle_privmsg(Session *s, const char *params, const char *src_nick) if (cmd_gitlog(s, msg, reply_target, src_nick)) return; if (cmd_ai(s, msg, reply_target, src_nick)) return; if (cmd_code(s, msg, reply_target, src_nick, tgt)) return; + if (cmd_rebuild(s, msg, reply_target, src_nick, tgt)) return; if (cmd_reload(s, msg, reply_target, src_nick, tgt)) return; if (cmd_restart(s, msg, reply_target, src_nick, tgt)) return; cmd_greeting_or_chat(s, msg, reply_target, src_nick);