Add !changelog command, reduce GITLOG_MAX and CHANGELOG_MAX (0.38.0)
- Added !changelog [count] command: displays the latest changelog entries from CHANGELOG.md. Defaults to 5 entries (CHANGELOG_COUNT), accepts 1-10 as count. Each entry title is sent as a separate IRC message with a 200ms delay to avoid IRC server flood protection. - Reduced GITLOG_MAX and CHANGELOG_MAX from 20 to 10. - Rewrote cmd_changelog to use getline() for robust line reading and isdigit() checks for reliable date pattern detection. - Updated !help to list !changelog. - Updated README.md with !changelog documentation and corrected max values. - Added CHANGELOG.md entry for v0.38.0. - Version bumped to 0.38.0.
This commit is contained in:
parent
caa70ee448
commit
e254b64745
3 changed files with 200 additions and 134 deletions
|
|
@ -1,3 +1,11 @@
|
||||||
|
2026.07.20 – Add !changelog command.
|
||||||
|
|
||||||
|
- Added `!changelog [count]` command: displays the latest changelog entries from `CHANGELOG.md`. Defaults to 5 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.
|
||||||
|
- Reduced `GITLOG_MAX` and `CHANGELOG_MAX` from 20 to 10.
|
||||||
|
- Updated `!help` to list `!changelog`.
|
||||||
|
- Updated README.md with `!changelog` documentation and corrected max values.
|
||||||
|
- Version bumped to 0.38.0.
|
||||||
|
|
||||||
2026.07.20 – Add !rebuild command.
|
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.
|
- 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.
|
||||||
|
|
|
||||||
39
README.md
39
README.md
|
|
@ -54,7 +54,7 @@ make CC=clang CFLAGS="-O2 -Wall -Wextra"
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Option | Description |
|
| Option | Description |
|
||||||
|---|---|
|
|------------------|--------------------------------------------------------|
|
||||||
| `-ssl` | Enable TLS (auto-enabled on ports 6697/7000) |
|
| `-ssl` | Enable TLS (auto-enabled on ports 6697/7000) |
|
||||||
| `-noverify` | Skip TLS certificate verification |
|
| `-noverify` | Skip TLS certificate verification |
|
||||||
| `-server <host>` | IRC server (default: `irc.libera.chat`) |
|
| `-server <host>` | IRC server (default: `irc.libera.chat`) |
|
||||||
|
|
@ -76,7 +76,7 @@ make CC=clang CFLAGS="-O2 -Wall -Wextra"
|
||||||
### General
|
### General
|
||||||
|
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
|---|---|
|
|------------------|------------------------------|
|
||||||
| `!help` | List all available commands |
|
| `!help` | List all available commands |
|
||||||
| `!version` | Show the bot version |
|
| `!version` | Show the bot version |
|
||||||
| `!ping` | Responds with `pong` |
|
| `!ping` | Responds with `pong` |
|
||||||
|
|
@ -86,7 +86,7 @@ make CC=clang CFLAGS="-O2 -Wall -Wextra"
|
||||||
### Key-Value Store
|
### Key-Value Store
|
||||||
|
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
|---|---|
|
|-------------------------|-----------------------------------------------|
|
||||||
| `zynk <key>` | Look up a stored value |
|
| `zynk <key>` | Look up a stored value |
|
||||||
| `zynk <key> = <value>` | Store a value (key is lowercased) |
|
| `zynk <key> = <value>` | Store a value (key is lowercased) |
|
||||||
| `zynk! <key> = <value>` | Overwrite an existing value (ops in channels) |
|
| `zynk! <key> = <value>` | Overwrite an existing value (ops in channels) |
|
||||||
|
|
@ -95,7 +95,7 @@ make CC=clang CFLAGS="-O2 -Wall -Wextra"
|
||||||
### Weather & Finance
|
### Weather & Finance
|
||||||
|
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
|---|---|
|
|-------------------------------|---------------------------------------------------------|
|
||||||
| `!weather [city]` | Current weather (default: Berlin) |
|
| `!weather [city]` | Current weather (default: Berlin) |
|
||||||
| `!forecast [city]` | 3-day forecast (default: Berlin) |
|
| `!forecast [city]` | 3-day forecast (default: Berlin) |
|
||||||
| `!stock <SYMBOL>[,SYMBOL...]` | Stock quotes, up to 3 symbols (e.g. `!stock AAPL,MSFT`) |
|
| `!stock <SYMBOL>[,SYMBOL...]` | Stock quotes, up to 3 symbols (e.g. `!stock AAPL,MSFT`) |
|
||||||
|
|
@ -103,12 +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: 20) |
|
| `!gitlog [count]` | Show recent git commits (default: 5, max: 10) |
|
||||||
|
| `!changelog [count]` | Show changelog entries (default: 5, max: 10) |
|
||||||
|
|
||||||
#### Time (`!time`)
|
#### Time (`!time`)
|
||||||
|
|
||||||
|
|
@ -119,7 +120,7 @@ Shows the current date and time. Without arguments, displays the bot's local tim
|
||||||
**Examples:**
|
**Examples:**
|
||||||
|
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
|---|---|
|
|--------------------------|-------------------------|
|
||||||
| `!time` | Bot's local time |
|
| `!time` | Bot's local time |
|
||||||
| `!time UTC` | Current UTC time |
|
| `!time UTC` | Current UTC time |
|
||||||
| `!time US/Eastern` | US Eastern time |
|
| `!time US/Eastern` | US Eastern time |
|
||||||
|
|
@ -134,7 +135,7 @@ If the system has `tzdata` installed, any IANA/Olson timezone name works. Otherw
|
||||||
**Built-in timezones (no tzdata required):**
|
**Built-in timezones (no tzdata required):**
|
||||||
|
|
||||||
| Timezone | Region | Offset | DST |
|
| Timezone | Region | Offset | DST |
|
||||||
|---|---|---|---|
|
|---------------------------------------|-------------------|----------------|-----|
|
||||||
| `UTC` / `GMT` | Global | +0 | No |
|
| `UTC` / `GMT` | Global | +0 | No |
|
||||||
| `EST` / `CST` / `MST` / `PST` / `HST` | US (fixed) | -5 to -10 | No |
|
| `EST` / `CST` / `MST` / `PST` / `HST` | US (fixed) | -5 to -10 | No |
|
||||||
| `US/Eastern` | US Eastern | -5 / -4 | Yes |
|
| `US/Eastern` | US Eastern | -5 / -4 | Yes |
|
||||||
|
|
@ -183,7 +184,7 @@ The calculator uses `bc -l` (POSIX arbitrary-precision calculator with the math
|
||||||
**Basic arithmetic:**
|
**Basic arithmetic:**
|
||||||
|
|
||||||
| Expression | Result |
|
| Expression | Result |
|
||||||
|---|---|
|
|----------------|--------------------------|
|
||||||
| `!calc 2+2` | `4` |
|
| `!calc 2+2` | `4` |
|
||||||
| `!calc 100-37` | `63` |
|
| `!calc 100-37` | `63` |
|
||||||
| `!calc 6*7` | `42` |
|
| `!calc 6*7` | `42` |
|
||||||
|
|
@ -193,21 +194,21 @@ The calculator uses `bc -l` (POSIX arbitrary-precision calculator with the math
|
||||||
**Parentheses for grouping:**
|
**Parentheses for grouping:**
|
||||||
|
|
||||||
| Expression | Result |
|
| Expression | Result |
|
||||||
|---|---|
|
|--------------------|--------|
|
||||||
| `!calc (3+7)*2` | `20` |
|
| `!calc (3+7)*2` | `20` |
|
||||||
| `!calc (100-50)/5` | `10` |
|
| `!calc (100-50)/5` | `10` |
|
||||||
|
|
||||||
**Powers:**
|
**Powers:**
|
||||||
|
|
||||||
| Expression | Result |
|
| Expression | Result |
|
||||||
|---|---|
|
|--------------|--------|
|
||||||
| `!calc 2^10` | `1024` |
|
| `!calc 2^10` | `1024` |
|
||||||
| `!calc 3^3` | `27` |
|
| `!calc 3^3` | `27` |
|
||||||
|
|
||||||
**Constants:**
|
**Constants:**
|
||||||
|
|
||||||
| Expression | Description |
|
| Expression | Description |
|
||||||
|---|---|
|
|----------------|--------------------------------|
|
||||||
| `!calc pi()` | Pi (3.14159...) |
|
| `!calc pi()` | Pi (3.14159...) |
|
||||||
| `!calc pi()*2` | Circumference of a unit circle |
|
| `!calc pi()*2` | Circumference of a unit circle |
|
||||||
| `!calc pi()^2` | Pi squared |
|
| `!calc pi()^2` | Pi squared |
|
||||||
|
|
@ -215,7 +216,7 @@ The calculator uses `bc -l` (POSIX arbitrary-precision calculator with the math
|
||||||
**Math library functions** (enabled by `-l`):
|
**Math library functions** (enabled by `-l`):
|
||||||
|
|
||||||
| Expression | Description |
|
| Expression | Description |
|
||||||
|---|---|
|
|----------------|--------------------------|
|
||||||
| `!calc s(1)` | Sine of 1 (radians) |
|
| `!calc s(1)` | Sine of 1 (radians) |
|
||||||
| `!calc c(0)` | Cosine of 0 |
|
| `!calc c(0)` | Cosine of 0 |
|
||||||
| `!calc a(1)` | Arctangent of 1 |
|
| `!calc a(1)` | Arctangent of 1 |
|
||||||
|
|
@ -225,20 +226,20 @@ The calculator uses `bc -l` (POSIX arbitrary-precision calculator with the math
|
||||||
**Scale (decimal places):**
|
**Scale (decimal places):**
|
||||||
|
|
||||||
| Expression | Description |
|
| Expression | Description |
|
||||||
|---|---|
|
|----------------------|-------------|
|
||||||
| `!calc scale=4; 1/3` | `0.3333` |
|
| `!calc scale=4; 1/3` | `0.3333` |
|
||||||
|
|
||||||
**Variables and multi-statement:**
|
**Variables and multi-statement:**
|
||||||
|
|
||||||
| Expression | Description |
|
| Expression | Description |
|
||||||
|---|---|
|
|------------------|----------------------------|
|
||||||
| `!calc x=5; x*2` | `10` |
|
| `!calc x=5; x*2` | `10` |
|
||||||
| `!calc 2+2; 3*3` | `4` (first line of output) |
|
| `!calc 2+2; 3*3` | `4` (first line of output) |
|
||||||
|
|
||||||
### AI
|
### AI
|
||||||
|
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
|---|---|
|
|-----------------------|------------------------------------------------------------|
|
||||||
| `!ai <question>` | Ask the AI a question (plan mode, read-only) |
|
| `!ai <question>` | Ask the AI a question (plan mode, read-only) |
|
||||||
| `!code <instruction>` | AI code change with auto-recompile (ops only, in channels) |
|
| `!code <instruction>` | AI code change with auto-recompile (ops only, in channels) |
|
||||||
| `<nick>: <question>` | Address the bot by nick to ask the AI |
|
| `<nick>: <question>` | Address the bot by nick to ask the AI |
|
||||||
|
|
@ -246,7 +247,7 @@ 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` | Git pull, rebuild, and restart (ops only, in channels) |
|
||||||
|
|
@ -255,7 +256,7 @@ The calculator uses `bc -l` (POSIX arbitrary-precision calculator with the math
|
||||||
### Chat
|
### Chat
|
||||||
|
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
|---|---|
|
|------------------------|-------------------------|
|
||||||
| `<nick>: hi/hello/hey` | Greeting response |
|
| `<nick>: hi/hello/hey` | Greeting response |
|
||||||
| `<nick>: bye` | Farewell response |
|
| `<nick>: bye` | Farewell response |
|
||||||
| `<nick>: <anything>` | AI-powered conversation |
|
| `<nick>: <anything>` | AI-powered conversation |
|
||||||
|
|
@ -271,7 +272,7 @@ Data is stored in `zynk.db` (SQLite3) in the working directory. The bot creates
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
`zynk` uses a single `poll()` loop with a 100ms timeout. AI queries fork a child process that runs the `opencode` CLI; the parent picks up the result on the next poll iteration. SQLite3 is loaded at runtime via `dlopen` to avoid a compile-time dependency. The bot supports hot reload: `!reload` and `!restart` save TLS session state, fork a new process with the inherited socket, and resume without dropping from IRC.
|
`zynk` uses a single `poll()` loop with a 100 ms timeout. AI queries fork a child process that runs the `opencode` CLI; the parent picks up the result on the next poll iteration. SQLite3 is loaded at runtime via `dlopen` to avoid a compile-time dependency. The bot supports hot reload: `!reload` and `!restart` save TLS session state, fork a new process with the inherited socket, and resume without dropping from IRC.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
||||||
63
zynk.c
63
zynk.c
|
|
@ -29,7 +29,7 @@ int asprintf(char **, const char *, ...);
|
||||||
|
|
||||||
/* ---- constants ---- */
|
/* ---- constants ---- */
|
||||||
|
|
||||||
#define VERSION "0.37.0"
|
#define VERSION "0.38.0"
|
||||||
#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"
|
||||||
|
|
@ -53,7 +53,9 @@ enum {
|
||||||
RATE_LIMIT_MAX = 8,
|
RATE_LIMIT_MAX = 8,
|
||||||
MAX_HISTORY = 100,
|
MAX_HISTORY = 100,
|
||||||
GITLOG_COUNT = 5,
|
GITLOG_COUNT = 5,
|
||||||
GITLOG_MAX = 20,
|
GITLOG_MAX = 10,
|
||||||
|
CHANGELOG_COUNT = 5,
|
||||||
|
CHANGELOG_MAX = 10,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ---- IRC session ---- */
|
/* ---- IRC session ---- */
|
||||||
|
|
@ -2305,7 +2307,7 @@ static int cmd_help(Session *s, const char *msg, const char *reply_target, const
|
||||||
if (rate_limit_check(src_nick) < 0) return 1;
|
if (rate_limit_check(src_nick) < 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], !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], !changelog [count], !ai <question>, !code <change> (ops), !rebuild (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;
|
||||||
|
|
@ -3089,6 +3091,60 @@ static int cmd_gitlog(Session *s, const char *msg, const char *reply_target, con
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* cmd_changelog - Handle the "!changelog" command.
|
||||||
|
*
|
||||||
|
* Reads CHANGELOG.md from the project root and displays the last N date/title
|
||||||
|
* lines (default: CHANGELOG_COUNT). Lines starting with a date (YYYY.MM.DD)
|
||||||
|
* are treated as entries. Accepts an optional count argument (1–CHANGELOG_MAX).
|
||||||
|
* Rate-limited.
|
||||||
|
*
|
||||||
|
* Returns: 1 if the command was matched, 0 otherwise.
|
||||||
|
*/
|
||||||
|
static int cmd_changelog(Session *s, const char *msg, const char *reply_target, const char *src_nick) {
|
||||||
|
if (strncmp(msg, "!changelog", 10) != 0) return 0;
|
||||||
|
if (msg[10] != ' ' && msg[10] != '\0') return 0;
|
||||||
|
if (rate_limit_check(src_nick) < 0) return 1;
|
||||||
|
int count = CHANGELOG_COUNT;
|
||||||
|
const char *rest = msg[10] == ' ' ? msg + 11 : "";
|
||||||
|
while (*rest == ' ') rest++;
|
||||||
|
if (*rest) {
|
||||||
|
count = atoi(rest);
|
||||||
|
if (count <= 0) count = CHANGELOG_COUNT;
|
||||||
|
if (count > CHANGELOG_MAX) count = CHANGELOG_MAX;
|
||||||
|
}
|
||||||
|
FILE *f = fopen("CHANGELOG.md", "r");
|
||||||
|
if (!f) { irc_msg(s, reply_target, "changelog: CHANGELOG.md not found"); return 1; }
|
||||||
|
char *line = NULL;
|
||||||
|
size_t cap = 0;
|
||||||
|
const char *headers[256];
|
||||||
|
int total = 0;
|
||||||
|
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;
|
||||||
|
if (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 (total < 256) headers[total++] = strdup(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(line);
|
||||||
|
fclose(f);
|
||||||
|
int showed = count < total ? count : total;
|
||||||
|
struct timespec ts_msg = { .tv_sec = 0, .tv_nsec = 200000000 };
|
||||||
|
for (int i = 0; i < showed; i++) {
|
||||||
|
irc_msg(s, reply_target, headers[i]);
|
||||||
|
free((void *)headers[i]);
|
||||||
|
if (i + 1 < showed) nanosleep(&ts_msg, NULL);
|
||||||
|
}
|
||||||
|
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; }
|
||||||
|
log_stamp(); fprintf(stderr, CLR_YELLOW "CHANGELOG %s from %s (count=%d, showed=%d)" CLR_RESET "\n", reply_target, src_nick, count, showed);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* cmd_rebuild - Handle the "!rebuild" command.
|
* cmd_rebuild - Handle the "!rebuild" command.
|
||||||
*
|
*
|
||||||
|
|
@ -3257,6 +3313,7 @@ static void handle_privmsg(Session *s, const char *params, const char *src_nick)
|
||||||
if (cmd_seen(s, msg, reply_target, src_nick)) return;
|
if (cmd_seen(s, msg, reply_target, src_nick)) return;
|
||||||
if (cmd_tell(s, msg, reply_target, src_nick)) return;
|
if (cmd_tell(s, msg, reply_target, src_nick)) return;
|
||||||
if (cmd_gitlog(s, msg, reply_target, src_nick)) return;
|
if (cmd_gitlog(s, msg, reply_target, src_nick)) return;
|
||||||
|
if (cmd_changelog(s, msg, reply_target, src_nick)) return;
|
||||||
if (cmd_ai(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_code(s, msg, reply_target, src_nick, tgt)) return;
|
||||||
if (cmd_rebuild(s, msg, reply_target, src_nick, tgt)) return;
|
if (cmd_rebuild(s, msg, reply_target, src_nick, tgt)) return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue