diff --git a/CHANGELOG.md b/CHANGELOG.md index 99d80c9..7e93f9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,3 +9,4 @@ - Fixed IRC op cache bugs around nick changes and long NAMES entries. - Added !version command to report the bot's version via IRC. - Fixed the malformed VERSION macro definition to ensure successful builds. +- Added !help command to list available bot commands. diff --git a/README.md b/README.md index 0d3d567..0288350 100644 --- a/README.md +++ b/README.md @@ -60,17 +60,18 @@ make CC=clang CFLAGS="-O2 -Wall -Wextra" ## IRC Commands -| Command | Description | -|---|---| -| `zynk ` | Look up a stored value | +| Command | Description | +|------------------------|-----------------------------------| +| `zynk ` | Look up a stored value | | `zynk = ` | Store a value (key is lowercased) | -| `!ping` | Responds with `pong` | -| `!weather [city]` | Current weather (default: Berlin) | -| `!forecast [city]` | 3-day forecast (default: Berlin) | -| `!ai ` | Ask the AI a question | -| `!quit` / `!die` | Shut down the bot | -| `: hi` | Greeting response | -| `: ` | Ask the bot anything (AI) | +| `!ping` | Responds with `pong` | +| `!version` | Show the program version in IRC | +| `!weather [city]` | Current weather (default: Berlin) | +| `!forecast [city]` | 3-day forecast (default: Berlin) | +| `!ai ` | Ask the AI a question | +| `!quit` / `!die` | Shut down the bot | +| `: hi` | Greeting response | +| `: ` | Ask the bot anything (AI) | ## Installation diff --git a/zynk.c b/zynk.c index 8d2cb1f..c890740 100644 --- a/zynk.c +++ b/zynk.c @@ -29,7 +29,7 @@ int asprintf(char **, const char *, ...); /* ---- constants ---- */ -#define VERSION "0.30" +#define VERSION "0.31" #define DEFAULT_SERVER "irc.libera.chat" #define OPENCODE_BIN "/home/hanez/bin/opencode" #define CLR_RESET "\033[0m" @@ -1112,6 +1112,18 @@ static int cmd_version(Session *s, const char *msg, const char *reply_target, co return 1; } +static int cmd_help(Session *s, const char *msg, const char *reply_target, const char *src_nick) { + if (strncmp(msg, "!help", 5) != 0) return 0; + if (msg[5] != ' ' && msg[5] != '\0') return 0; + if (rate_limit_check(src_nick) < 0) return 1; + char buf[512]; + snprintf(buf, sizeof buf, + "Commands: !help, !version, !ping, !weather [city], !forecast [city], !ai , !code (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; +} + static int cmd_quit(Session *s, const char *msg, const char *reply_target, const char *src_nick, const char *tgt) { if (strcmp(msg, "!quit") != 0 && strcmp(msg, "!die") != 0) return 0; if (tgt[0] == '#' && !chan_is_op(tgt, src_nick)) { @@ -1269,6 +1281,7 @@ static void handle_privmsg(Session *s, const char *params, const char *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_version(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; if (cmd_forecast(s, msg, reply_target, src_nick)) return;