feat: add !gitlog command to display recent git commits
Add !gitlog [count] IRC command that runs 'git log --oneline' and sends each commit as a separate PRIVMSG. Defaults to GITLOG_COUNT (5) commits when no argument is provided; accepts 1-20 as count. - Fork/exec pattern consistent with existing !calc command - Rate-limited per-nick like all other commands - Listed in !help output - Added git to README.md requirements - Documented in README.md utilities section - Added changelog entry for v0.36.0
This commit is contained in:
parent
cce110f7f5
commit
01a51c17e5
3 changed files with 71 additions and 2 deletions
|
|
@ -1,3 +1,10 @@
|
|||
2026.07.20 – Add !gitlog command.
|
||||
|
||||
- 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.
|
||||
- Updated `!help` to list `!gitlog`.
|
||||
- Updated README.md with `!gitlog` documentation and `git` as a requirement.
|
||||
- Version bumped to 0.36.0.
|
||||
|
||||
2026.07.20 – Remove timezone abbreviation from !time response.
|
||||
|
||||
- `!time` now outputs date and time only (`YYYY-MM-DD HH:MM:SS`) without the timezone abbreviation, keeping IRC responses shorter and cleaner.
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ A single-file IRC bot in C. Features a key-value store backed by SQLite3, weathe
|
|||
- `libsqlite3` (loaded at runtime via `dlopen`)
|
||||
- `curl` (for weather, forecast, and stock lookups)
|
||||
- `bc` (for the calculator command)
|
||||
- `git` (for the gitlog command)
|
||||
- `date` (for timezone-aware time lookups)
|
||||
- `tzdata` (optional — without it, `!time` falls back to 45 built-in timezones)
|
||||
- `opencode` (for AI queries)
|
||||
|
|
@ -107,6 +108,7 @@ make CC=clang CFLAGS="-O2 -Wall -Wextra"
|
|||
| `!time [timezone]` | Show current time (see below) |
|
||||
| `!seen <nick>` | Check when a user was last seen |
|
||||
| `!tell <nick> <message>` | Leave a message for an offline user |
|
||||
| `!gitlog [count]` | Show recent git commits (default: 5, max: 20) |
|
||||
|
||||
#### Time (`!time`)
|
||||
|
||||
|
|
|
|||
64
zynk.c
64
zynk.c
|
|
@ -29,7 +29,7 @@ int asprintf(char **, const char *, ...);
|
|||
|
||||
/* ---- constants ---- */
|
||||
|
||||
#define VERSION "0.35.6"
|
||||
#define VERSION "0.36.0"
|
||||
#define DEFAULT_SERVER "irc.libera.chat"
|
||||
#define OPENCODE_BIN "/usr/bin/opencode"
|
||||
#define CLR_RESET "\033[0m"
|
||||
|
|
@ -52,6 +52,7 @@ enum {
|
|||
RATE_LIMIT_WINDOW = 10,
|
||||
RATE_LIMIT_MAX = 8,
|
||||
MAX_HISTORY = 100,
|
||||
GITLOG_COUNT = 5,
|
||||
};
|
||||
|
||||
/* ---- IRC session ---- */
|
||||
|
|
@ -2303,7 +2304,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 <SYMBOL>, !calc <expr>, !time [tz], !seen <nick>, !tell <nick> <msg>, !ai <question>, !code <change> (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], !ai <question>, !code <change> (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;
|
||||
|
|
@ -3008,6 +3009,64 @@ static int cmd_tell(Session *s, const char *msg, const char *reply_target, const
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int cmd_gitlog(Session *s, const char *msg, const char *reply_target, const char *src_nick) {
|
||||
if (strncmp(msg, "!gitlog", 7) != 0) return 0;
|
||||
if (msg[7] != ' ' && msg[7] != '\0') return 0;
|
||||
if (rate_limit_check(src_nick) < 0) return 1;
|
||||
int count = GITLOG_COUNT;
|
||||
const char *rest = msg[7] == ' ' ? msg + 8 : "";
|
||||
while (*rest == ' ') rest++;
|
||||
if (*rest) {
|
||||
count = atoi(rest);
|
||||
if (count <= 0) count = GITLOG_COUNT;
|
||||
if (count > 20) count = 20;
|
||||
}
|
||||
int out_pipe[2];
|
||||
if (pipe(out_pipe) < 0) { irc_msg(s, reply_target, "gitlog: internal error"); return 1; }
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) { close(out_pipe[0]); close(out_pipe[1]); irc_msg(s, reply_target, "gitlog: fork failed"); return 1; }
|
||||
if (pid == 0) {
|
||||
close(out_pipe[0]);
|
||||
dup2(out_pipe[1], STDOUT_FILENO);
|
||||
close(out_pipe[1]);
|
||||
int dn = open("/dev/null", O_WRONLY);
|
||||
if (dn >= 0) { dup2(dn, STDERR_FILENO); close(dn); }
|
||||
char cnt[8];
|
||||
snprintf(cnt, sizeof cnt, "%d", count);
|
||||
execlp("git", "git", "log", "--oneline", "-n", cnt, (char *)NULL);
|
||||
_exit(127);
|
||||
}
|
||||
close(out_pipe[1]);
|
||||
char buf[4096], tmp[512];
|
||||
size_t len = 0;
|
||||
ssize_t n;
|
||||
while ((n = read(out_pipe[0], tmp, sizeof tmp - 1)) > 0) {
|
||||
size_t avail = sizeof buf - 1 - len;
|
||||
if (avail > 0) {
|
||||
size_t copy = (size_t)n < avail ? (size_t)n : avail;
|
||||
memcpy(buf + len, tmp, copy);
|
||||
len += copy;
|
||||
}
|
||||
}
|
||||
close(out_pipe[0]);
|
||||
int status;
|
||||
waitpid(pid, &status, 0);
|
||||
while (len > 0 && (buf[len-1] == '\n' || buf[len-1] == '\r')) len--;
|
||||
buf[len] = 0;
|
||||
if (len == 0) {
|
||||
irc_msg(s, reply_target, "gitlog: no commits found");
|
||||
return 1;
|
||||
}
|
||||
char *line = strtok(buf, "\n");
|
||||
while (line) {
|
||||
while (*line == ' ') line++;
|
||||
if (*line) irc_msg(s, reply_target, line);
|
||||
line = strtok(NULL, "\n");
|
||||
}
|
||||
log_stamp(); fprintf(stderr, CLR_YELLOW "GITLOG %s from %s (count=%d)" CLR_RESET "\n", reply_target, src_nick, count);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* cmd_greeting_or_chat - Handle informal greetings and chat messages.
|
||||
*
|
||||
|
|
@ -3109,6 +3168,7 @@ static void handle_privmsg(Session *s, const char *params, const char *src_nick)
|
|||
if (cmd_time(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_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_reload(s, msg, reply_target, src_nick, tgt)) return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue