diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d246d8..dc7298b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +24.07.24 - Reduced MAX_HISTORY, moved LOAD_FUNC macro, added irc_reply docs. (0.40.9) + +- Reduced `MAX_HISTORY` from 100 to 12 to decrease AI context memory usage. +- Moved `LOAD_FUNC` macro from `zynk.h` to `db.h` for better code organization (closer to its usage in sqlite_init_lib). +- Added comprehensive doc comment to `irc_reply()` function describing its nick-prefixing behavior for channel messages. +- Reordered includes in `zynk.c` to alphabetical order. + 26.07.24 - Nick-prefixed channel replies for all non-admin commands. (0.40.8) - Added `irc_reply()`: a new IRC response helper that automatically prepends the sender's nick to channel messages (e.g. `"nick: pong!"`), while leaving private-message responses unmodified. This makes it clear which user the bot is addressing in busy channels. diff --git a/CMakeLists.txt b/CMakeLists.txt index 548f376..6421747 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.13) -project(zynk VERSION 0.40.8 LANGUAGES C) +project(zynk VERSION 0.40.9 LANGUAGES C) # Prefer C99; the code is compatible with C99/C11 set(CMAKE_C_STANDARD 99) diff --git a/db.h b/db.h index 30730da..f0fc61e 100644 --- a/db.h +++ b/db.h @@ -22,6 +22,12 @@ int (*db_bind_int64)(void*,int,long long); long long (*db_last_rowid)(void*); void *db_handle; +#define LOAD_FUNC(var, name) do { \ + union { void *p; typeof(var) f; } _u; \ + _u.p = dlsym(sqlite_lib, name); \ + var = _u.f; \ +} while(0) + /* * sqlite_init_lib - Dynamically load libsqlite3 and resolve function symbols. * diff --git a/irc.h b/irc.h index b2a2035..65d5e3b 100644 --- a/irc.h +++ b/irc.h @@ -242,6 +242,23 @@ void irc_msg(Session *s, const char *t, const char *txt) { free(clean); } +/* + * irc_reply - Send a PRIVMSG with an automatic nick prefix for channels. + * + * Wraps irc_msg() to provide consistent addressing in channel conversations. + * When the target is a channel (starts with '#'), prepends "nick: " to the + * message so other users can see which user the bot is replying to. When the + * target is a private message (does not start with '#'), sends the text as-is + * without a prefix. Handles NULL and empty text safely. + * + * Parameters: + * s - The IRC session. + * target - The target channel name or nick. + * nick - The nick of the user who triggered the response. + * txt - The message text to send. + * + * Returns: void. + */ void irc_reply(Session *s, const char *target, const char *nick, const char *txt) { if (target && target[0] == '#' && nick && *nick) { char prefixed[2048]; diff --git a/zynk.c b/zynk.c index 9471424..9c37492 100644 --- a/zynk.c +++ b/zynk.c @@ -4,10 +4,10 @@ * Licensed under the terms of the MIT License. */ -#include "zynk.h" -#include "net.h" #include "ai.h" +#include "net.h" #include "tls.h" +#include "zynk.h" int tls_verify = 1; diff --git a/zynk.h b/zynk.h index a907515..b9db843 100644 --- a/zynk.h +++ b/zynk.h @@ -47,7 +47,7 @@ enum { MAX_CHAN_OPS = 64, RATE_LIMIT_WINDOW = 10, RATE_LIMIT_MAX = 8, - MAX_HISTORY = 100, + MAX_HISTORY = 12, GITLOG_COUNT = 1, GITLOG_MAX = 10, CHANGELOG_COUNT = 1, @@ -86,12 +86,6 @@ extern void (*db_free)(void*); extern int (*db_bind_int64)(void*,int,long long); extern long long (*db_last_rowid)(void*); -#define LOAD_FUNC(var, name) do { \ - union { void *p; typeof(var) f; } _u; \ - _u.p = dlsym(sqlite_lib, name); \ - var = _u.f; \ -} while(0) - #define SQLITE_OK 0 #define SQLITE_ERROR 1 #define SQLITE_DONE 101