2
0
Fork 0
forked from zynk/zynk

Full mode for !gitlog/!changelog, optional pull for !rebuild. (0.38.2)

- Added optional full keyword to !gitlog and !changelog for showing
  full commit messages and changelog entries instead of just headers.
- !gitlog full uses git log (without --oneline) and strips leading
  indentation from commit blocks, collapses multiple spaces.
- !changelog full collects full entry text with bullet points and
  shows the newest entries (first N in file, not last N).
- Added optional pull argument to !rebuild: !rebuild pull runs git
  pull before make clean/make, plain !rebuild only rebuilds.
- Added collapse_spaces() call in !gitlog oneline path to remove
  double spaces in compact output.
- Changed default GITLOG_COUNT and CHANGELOG_COUNT from 5 to 1.
- Reduced GITLOG_MAX from 10 to 5.
- Updated !help text to document [full] and [pull] options.
- Updated README.md with full option for !gitlog/!changelog and
  pull option for !rebuild.
- Added CHANGELOG.md entry for v0.38.2.
This commit is contained in:
Johannes Findeisen 2026-07-21 14:08:53 +02:00
commit 52b1627d69
3 changed files with 189 additions and 73 deletions

View file

@ -1,3 +1,14 @@
2026.07.21 – Full mode for !gitlog/!changelog, optional pull for !rebuild. (0.38.2)
- 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`.
- Version bumped to 0.38.2.
2026.07.21 – Exempt ops from rate limiting. (0.38.1) 2026.07.21 – Exempt ops from rate limiting. (0.38.1)
- Op users in channels are now exempt from rate limiting: `rate_limit_check()` calls `chan_is_op()` and allows ops through immediately. - Op users in channels are now exempt from rate limiting: `rate_limit_check()` calls `chan_is_op()` and allows ops through immediately.

View file

@ -103,13 +103,13 @@ make CC=clang CFLAGS="-O2 -Wall -Wextra"
### Utilities ### Utilities
| Command | Description | | Command | Description |
|--------------------------|-----------------------------------------------| |-----------------------------|---------------------------------------------------------------------------------|
| `!calc <expression>` | Evaluate math (see below) | | `!calc <expression>` | Evaluate math (see below) |
| `!time [timezone]` | Show current time (see below) | | `!time [timezone]` | Show current time (see below) |
| `!seen <nick>` | Check when a user was last seen | | `!seen <nick>` | Check when a user was last seen |
| `!tell <nick> <message>` | Leave a message for an offline user | | `!tell <nick> <message>` | Leave a message for an offline user |
| `!gitlog [count]` | Show recent git commits (default: 5, max: 10) | | `!gitlog [count] [full]` | Show recent git commits (default: 1, max: 5; `full` shows full commit messages) |
| `!changelog [count]` | Show changelog entries (default: 5, max: 10) | | `!changelog [count] [full]` | Show changelog entries (default: 1, max: 10; `full` shows full entry text) |
#### Time (`!time`) #### Time (`!time`)
@ -247,10 +247,10 @@ The calculator uses `bc -l` (POSIX arbitrary-precision calculator with the math
### Admin (Ops Only) ### Admin (Ops Only)
| Command | Description | | Command | Description |
|-----------------------|--------------------------------------------------------| |-----------------------|-------------------------------------------------------------------------------------|
| `!reload` | Hot reload (save TLS state, fork new process) | | `!reload` | Hot reload (save TLS state, fork new process) |
| `!restart` | Restart the bot | | `!restart` | Restart the bot |
| `!rebuild` | Git pull, rebuild, and restart (ops only, in channels) | | `!rebuild [pull]` | Rebuild and restart (ops only, in channels; `pull` runs Git pull before rebuilding) |
| `!code <instruction>` | Make AI-powered code changes | | `!code <instruction>` | Make AI-powered code changes |
### Chat ### Chat

133
zynk.c
View file

@ -28,7 +28,7 @@ int asprintf(char **, const char *, ...);
/* ---- constants ---- */ /* ---- constants ---- */
#define VERSION "0.38.1" #define VERSION "0.38.2"
#define DEFAULT_SERVER "irc.libera.chat" #define DEFAULT_SERVER "irc.libera.chat"
#define OPENCODE_BIN "/usr/bin/opencode" #define OPENCODE_BIN "/usr/bin/opencode"
#define CLR_RESET "\033[0m" #define CLR_RESET "\033[0m"
@ -50,9 +50,9 @@ enum {
RATE_LIMIT_WINDOW = 10, RATE_LIMIT_WINDOW = 10,
RATE_LIMIT_MAX = 8, RATE_LIMIT_MAX = 8,
MAX_HISTORY = 100, MAX_HISTORY = 100,
GITLOG_COUNT = 5, GITLOG_COUNT = 1,
GITLOG_MAX = 10, GITLOG_MAX = 5,
CHANGELOG_COUNT = 5, CHANGELOG_COUNT = 1,
CHANGELOG_MAX = 10, CHANGELOG_MAX = 10,
}; };
@ -2311,7 +2311,7 @@ static int cmd_help(Session *s, const char *msg, const char *reply_target, const
if (rate_limit_check(src_nick, reply_target) < 0) return 1; if (rate_limit_check(src_nick, reply_target) < 0) return 1;
char buf[512]; char buf[512];
snprintf(buf, sizeof buf, snprintf(buf, sizeof buf,
"Commands: !help, !version, !ping, !uptime, !weather [city], !forecast [city], !stock <SYMBOL>, !calc <expr>, !time [tz], !seen <nick>, !tell <nick> <msg>, !gitlog [count], !changelog [count], !ai <question>, !code <change> (ops), !rebuild (ops), !reload (ops), !restart (ops), !quit/!die (ops)"); "Commands: !help, !version, !ping, !uptime, !weather [city], !forecast [city], !stock <SYMBOL>, !calc <expr>, !time [tz], !seen <nick>, !tell <nick> <msg>, !gitlog [count] [full], !changelog [count] [full], !ai <question>, !code <change> (ops), !rebuild [pull] (ops), !reload (ops), !restart (ops), !quit/!die (ops)");
irc_msg(s, reply_target, buf); irc_msg(s, reply_target, buf);
log_stamp(); fprintf(stderr, CLR_CYAN "HELP from %s in %s" CLR_RESET "\n", src_nick, reply_target); log_stamp(); fprintf(stderr, CLR_CYAN "HELP from %s in %s" CLR_RESET "\n", src_nick, reply_target);
return 1; return 1;
@ -3042,12 +3042,19 @@ static int cmd_gitlog(Session *s, const char *msg, const char *reply_target, con
if (msg[7] != ' ' && msg[7] != '\0') return 0; if (msg[7] != ' ' && msg[7] != '\0') return 0;
if (rate_limit_check(src_nick, reply_target) < 0) return 1; if (rate_limit_check(src_nick, reply_target) < 0) return 1;
int count = GITLOG_COUNT; int count = GITLOG_COUNT;
int full = 0;
const char *rest = msg[7] == ' ' ? msg + 8 : ""; const char *rest = msg[7] == ' ' ? msg + 8 : "";
while (*rest == ' ') rest++; while (*rest == ' ') rest++;
if (*rest) { if (*rest) {
if (isdigit((unsigned char)*rest)) {
count = atoi(rest); count = atoi(rest);
if (count <= 0) count = GITLOG_COUNT; if (count <= 0) count = GITLOG_COUNT;
if (count > GITLOG_MAX) count = GITLOG_MAX; if (count > GITLOG_MAX) count = GITLOG_MAX;
while (*rest && isdigit((unsigned char)*rest)) rest++;
while (*rest == ' ') rest++;
}
if (strncasecmp(rest, "full", 4) == 0 && (rest[4] == '\0' || rest[4] == ' '))
full = 1;
} }
int out_pipe[2]; int out_pipe[2];
if (pipe(out_pipe) < 0) { irc_msg(s, reply_target, "gitlog: internal error"); return 1; } if (pipe(out_pipe) < 0) { irc_msg(s, reply_target, "gitlog: internal error"); return 1; }
@ -3061,11 +3068,14 @@ static int cmd_gitlog(Session *s, const char *msg, const char *reply_target, con
if (dn >= 0) { dup2(dn, STDERR_FILENO); close(dn); } if (dn >= 0) { dup2(dn, STDERR_FILENO); close(dn); }
char cnt[8]; char cnt[8];
snprintf(cnt, sizeof cnt, "%d", count); snprintf(cnt, sizeof cnt, "%d", count);
if (full)
execlp("git", "git", "log", "-n", cnt, (char *)NULL);
else
execlp("git", "git", "log", "--oneline", "-n", cnt, (char *)NULL); execlp("git", "git", "log", "--oneline", "-n", cnt, (char *)NULL);
_exit(127); _exit(127);
} }
close(out_pipe[1]); close(out_pipe[1]);
char buf[4096], tmp[512]; char buf[8192], tmp[512];
size_t len = 0; size_t len = 0;
ssize_t n; ssize_t n;
while ((n = read(out_pipe[0], tmp, sizeof tmp - 1)) > 0) { while ((n = read(out_pipe[0], tmp, sizeof tmp - 1)) > 0) {
@ -3085,13 +3095,39 @@ static int cmd_gitlog(Session *s, const char *msg, const char *reply_target, con
irc_msg(s, reply_target, "gitlog: no commits found"); irc_msg(s, reply_target, "gitlog: no commits found");
return 1; return 1;
} }
if (full) {
struct timespec ts_msg = { .tv_sec = 0, .tv_nsec = 200000000 };
char *p = buf;
while (*p) {
char *end = strstr(p, "\n\n");
size_t elen = end ? (size_t)(end - p) : strlen(p);
while (elen > 0 && (p[elen-1] == '\n' || p[elen-1] == '\r')) elen--;
if (elen > 0) {
p[elen] = 0;
char *out = p;
char *src = p;
while (*src) {
while (*src == ' ') src++;
while (*src && *src != '\n') *out++ = *src++;
if (*src == '\n') *out++ = *src++;
}
*out = 0;
collapse_spaces(p);
irc_msg(s, reply_target, p);
nanosleep(&ts_msg, NULL);
}
if (end) p = end + 2; else break;
}
} else {
char *line = strtok(buf, "\n"); char *line = strtok(buf, "\n");
while (line) { while (line) {
while (*line == ' ') line++; while (*line == ' ') line++;
collapse_spaces(line);
if (*line) irc_msg(s, reply_target, line); if (*line) irc_msg(s, reply_target, line);
line = strtok(NULL, "\n"); line = strtok(NULL, "\n");
} }
log_stamp(); fprintf(stderr, CLR_YELLOW "GITLOG %s from %s (count=%d)" CLR_RESET "\n", reply_target, src_nick, count); }
log_stamp(); fprintf(stderr, CLR_YELLOW "GITLOG %s from %s (count=%d%s)" CLR_RESET "\n", reply_target, src_nick, count, full ? ", full" : "");
return 1; return 1;
} }
@ -3110,17 +3146,25 @@ static int cmd_changelog(Session *s, const char *msg, const char *reply_target,
if (msg[10] != ' ' && msg[10] != '\0') return 0; if (msg[10] != ' ' && msg[10] != '\0') return 0;
if (rate_limit_check(src_nick, reply_target) < 0) return 1; if (rate_limit_check(src_nick, reply_target) < 0) return 1;
int count = CHANGELOG_COUNT; int count = CHANGELOG_COUNT;
int full = 0;
const char *rest = msg[10] == ' ' ? msg + 11 : ""; const char *rest = msg[10] == ' ' ? msg + 11 : "";
while (*rest == ' ') rest++; while (*rest == ' ') rest++;
if (*rest) { if (*rest) {
if (isdigit((unsigned char)*rest)) {
count = atoi(rest); count = atoi(rest);
if (count <= 0) count = CHANGELOG_COUNT; if (count <= 0) count = CHANGELOG_COUNT;
if (count > CHANGELOG_MAX) count = CHANGELOG_MAX; if (count > CHANGELOG_MAX) count = CHANGELOG_MAX;
while (*rest && isdigit((unsigned char)*rest)) rest++;
while (*rest == ' ') rest++;
}
if (strncasecmp(rest, "full", 4) == 0 && (rest[4] == '\0' || rest[4] == ' '))
full = 1;
} }
FILE *f = fopen("CHANGELOG.md", "r"); FILE *f = fopen("CHANGELOG.md", "r");
if (!f) { irc_msg(s, reply_target, "changelog: CHANGELOG.md not found"); return 1; } if (!f) { irc_msg(s, reply_target, "changelog: CHANGELOG.md not found"); return 1; }
char *line = NULL; char *line = NULL;
size_t cap = 0; size_t cap = 0;
if (!full) {
const char *headers[256]; const char *headers[256];
int total = 0; int total = 0;
while (getline(&line, &cap, f) != -1) { while (getline(&line, &cap, f) != -1) {
@ -3146,21 +3190,80 @@ static int cmd_changelog(Session *s, const char *msg, const char *reply_target,
for (int i = showed; i < total; i++) free((void *)headers[i]); for (int i = showed; i < total; i++) free((void *)headers[i]);
if (total == 0) { irc_msg(s, reply_target, "changelog: no entries found"); return 1; } if (total == 0) { irc_msg(s, reply_target, "changelog: no entries found"); return 1; }
log_stamp(); fprintf(stderr, CLR_YELLOW "CHANGELOG %s from %s (count=%d, showed=%d)" CLR_RESET "\n", reply_target, src_nick, count, showed); log_stamp(); fprintf(stderr, CLR_YELLOW "CHANGELOG %s from %s (count=%d, showed=%d)" CLR_RESET "\n", reply_target, src_nick, count, showed);
} else {
char *entries[256];
int total = 0;
int showed = 0;
size_t entry_cap = 0;
size_t entry_len = 0;
char *entry = NULL;
struct timespec ts_msg = { .tv_sec = 0, .tv_nsec = 200000000 };
while (getline(&line, &cap, f) != -1) {
size_t len = strlen(line);
while (len > 0 && (line[len-1] == '\n' || line[len-1] == '\r')) line[--len] = 0;
int is_header = (len > 10 && isdigit((unsigned char)line[0]) && isdigit((unsigned char)line[1]) &&
isdigit((unsigned char)line[2]) && isdigit((unsigned char)line[3]) &&
line[4] == '.' && isdigit((unsigned char)line[5]) && isdigit((unsigned char)line[6]) &&
line[7] == '.' && isdigit((unsigned char)line[8]) && isdigit((unsigned char)line[9]) &&
line[10] == ' ');
if (is_header) {
if (entry) {
while (entry_len > 0 && (entry[entry_len-1] == '\n' || entry[entry_len-1] == '\r')) entry[--entry_len] = 0;
entries[total++] = entry;
entry = NULL; entry_len = 0; entry_cap = 0;
}
entry_cap = len + 256;
entry = malloc(entry_cap);
memcpy(entry, line, len);
entry_len = len;
entry[entry_len] = 0;
} else if (entry) {
if (entry_len + len + 2 > entry_cap) {
entry_cap = entry_len + len + 256;
entry = realloc(entry, entry_cap);
}
if (entry_len > 0 && line[0]) entry[entry_len++] = '\n';
if (line[0]) {
memcpy(entry + entry_len, line, len);
entry_len += len;
}
entry[entry_len] = 0;
}
}
if (entry) {
while (entry_len > 0 && (entry[entry_len-1] == '\n' || entry[entry_len-1] == '\r')) entry[--entry_len] = 0;
entries[total++] = entry;
}
free(line);
fclose(f);
if (total == 0) { irc_msg(s, reply_target, "changelog: no entries found"); return 1; }
int showed_n = count < total ? count : total;
for (int i = 0; i < showed_n; i++) {
irc_msg(s, reply_target, entries[i]);
showed++;
free(entries[i]);
if (i + 1 < showed_n) nanosleep(&ts_msg, NULL);
}
for (int i = showed_n; i < total; i++) free(entries[i]);
log_stamp(); fprintf(stderr, CLR_YELLOW "CHANGELOG %s from %s (count=%d, showed=%d, full)" CLR_RESET "\n", reply_target, src_nick, count, showed);
}
return 1; return 1;
} }
/* /*
* cmd_rebuild - Handle the "!rebuild" command. * cmd_rebuild - Handle the "!rebuild" command.
* *
* Requires channel op and must be used in a channel. Runs "git pull", * Requires channel op and must be used in a channel. Optionally runs
* "make clean", and "make" in sequence. If all steps succeed, triggers * "git pull" if the argument "pull" is provided (e.g. "!rebuild pull").
* a hot reload via reload_do(). If any step fails, reports the error * Always runs "make clean" and "make" in sequence. If all steps succeed,
* from the build output. Rate-limited. * 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. * 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) { 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; int do_pull = (strcmp(msg, "!rebuild pull") == 0);
if (strcmp(msg, "!rebuild") != 0 && !do_pull) return 0;
if (tgt[0] != '#') { if (tgt[0] != '#') {
irc_msg(s, reply_target, "!rebuild can only be used in a channel"); irc_msg(s, reply_target, "!rebuild can only be used in a channel");
return 1; return 1;
@ -3170,10 +3273,11 @@ static int cmd_rebuild(Session *s, const char *msg, const char *reply_target, co
return 1; return 1;
} }
if (rate_limit_check(src_nick, reply_target) < 0) return 1; if (rate_limit_check(src_nick, reply_target) < 0) return 1;
irc_msg(s, reply_target, "Rebuilding..."); irc_msg(s, reply_target, do_pull ? "Pulling and rebuilding..." : "Rebuilding...");
log_stamp(); fprintf(stderr, CLR_GREEN "REBUILD from %s in %s" CLR_RESET "\n", src_nick, reply_target); log_stamp(); fprintf(stderr, CLR_GREEN "REBUILD from %s in %s (pull=%d)" CLR_RESET "\n", src_nick, reply_target, do_pull);
int status; int status;
char errbuf[512]; char errbuf[512];
if (do_pull) {
status = system("git pull 2>/tmp/zynk_rebuild_err"); status = system("git pull 2>/tmp/zynk_rebuild_err");
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
char msg_buf[640]; char msg_buf[640];
@ -3185,6 +3289,7 @@ static int cmd_rebuild(Session *s, const char *msg, const char *reply_target, co
log_stamp(); fprintf(stderr, CLR_RED "REBUILD git pull failed:" CLR_RESET " %s\n", errbuf); log_stamp(); fprintf(stderr, CLR_RED "REBUILD git pull failed:" CLR_RESET " %s\n", errbuf);
return 1; return 1;
} }
}
status = system("make clean 2>/tmp/zynk_rebuild_err"); status = system("make clean 2>/tmp/zynk_rebuild_err");
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
char msg_buf[640]; char msg_buf[640];