From 84fd78f0a04fda71639f2233a8c271cd620878f3 Mon Sep 17 00:00:00 2001 From: hanez Date: Sat, 25 Jul 2026 03:16:17 +0200 Subject: [PATCH] Welcome message for new users, channel tracking docs. (0.41.2) - Added welcome message when users join a channel: handle_join() now sends "Welcome, !" to the channel for non-bot users. The bot's own joins are silently ignored to avoid echo loops. - Added src_nick parameter to handle_join() to identify the joining user; the call site in irc_handle() was updated to pass src_nick. - Added doc comments to chans[] (global channel tracking array) and nchans (count of tracked channels) in irc.h. - Bumped version to 0.41.2 in CMakeLists.txt. --- CHANGELOG.md | 6 ++++++ CMakeLists.txt | 2 +- irc.h | 37 ++++++++++++++++++++++++++++--------- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 194ab8e..59e9a9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +2026.07.25 - Welcome message for new users, channel tracking docs. (0.41.2) + +- Added a welcome message when users join a channel: `handle_join()` now sends `"Welcome, !"` to the channel for non-bot users. The bot's own joins are silently ignored to avoid echo loops. +- Added `src_nick` parameter to `handle_join()` to identify the joining user; the call site in `irc_handle()` was updated to pass `src_nick`. +- Added doc comments to `chans[]` (global channel tracking array) and `nchans` (count of tracked channels) in `irc.h`. + 2026.07.25 - Decode Unicode escapes in !yt responses. (0.41.1) - Fixed `!yt` displaying raw JSON Unicode escape sequences (e.g. `\u0027` instead of `'`) in video titles and channel names. YouTube's oEmbed API returns non-ASCII characters as `\uXXXX` escapes, which were previously passed through as-is. diff --git a/CMakeLists.txt b/CMakeLists.txt index f1c6a05..253debb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.13) -project(zynk VERSION 0.41.1 LANGUAGES C) +project(zynk VERSION 0.41.2 LANGUAGES C) # Prefer C99; the code is compatible with C99/C11 set(CMAKE_C_STANDARD 99) diff --git a/irc.h b/irc.h index eb6a94f..f56b638 100644 --- a/irc.h +++ b/irc.h @@ -25,7 +25,21 @@ int valid_irc_word(const char *s) { /* ---- channel op tracking ---- */ +/* + * chans - Array of tracked channel entries. + * + * Holds up to MAX_CHANS channel records, each containing the channel name + * and its list of operator nicks. Populated via chan_get_or_add() when JOIN + * messages or NAMREPLY (353) responses are received. + */ ChanEntry chans[MAX_CHANS]; + +/* + * nchans - Number of currently tracked channels. + * + * Tracks how many entries in the chans[] array are in use. Incremented by + * chan_get_or_add() when a new channel is registered. + */ int nchans; /* @@ -493,25 +507,30 @@ static void handle_mode(Session *s, const char *params) { } /* - * handle_join - Process JOIN messages to register new channels. + * handle_join - Process JOIN messages to register channels and welcome users. * - * When any user (including the bot) joins a channel, registers the channel - * in the tracking array via chan_get_or_add(). This ensures the channel - * exists in the ops tracking structure even before NAMREPLY arrives. + * When any user joins a channel, registers the channel in the tracking array + * via chan_get_or_add(). If the joining user is not the bot itself, sends a + * simple welcome message to the channel. * * Parameters: - * s - The IRC session. - * params - The raw IRC params (:#channel). + * s - The IRC session. + * params - The raw IRC params (:#channel). + * src_nick - The nick of the user who joined. * * Returns: void. */ -static void handle_join(Session *s, const char *params) { - (void)s; +static void handle_join(Session *s, const char *params, const char *src_nick) { const char *p = params; if (*p == ':') p++; char _chan[64]; if (sscanf(p, "%63s", _chan) == 1) chan_get_or_add(_chan); + if (src_nick && strcasecmp(src_nick, s->nick) != 0) { + char welcome[256]; + snprintf(welcome, sizeof welcome, "Welcome, %s! User zynk is an AI driven bot using OpenCode. You can ask the bot whatever you want... have fun! ;)", src_nick); + irc_msg(s, _chan, welcome); + } } /* @@ -730,7 +749,7 @@ static void irc_handle(Session *s, const char *raw) { if (strcmp(cmd_buf, "PRIVMSG") == 0) { handle_privmsg(s, params, src_nick); return; } if (strcmp(cmd_buf, "353") == 0) { handle_namreply(s, params); return; } if (strcmp(cmd_buf, "MODE") == 0) { handle_mode(s, params); return; } - if (strcmp(cmd_buf, "JOIN") == 0 && prefix) { handle_join(s, params); return; } + if (strcmp(cmd_buf, "JOIN") == 0 && prefix) { handle_join(s, params, src_nick); return; } if (strcmp(cmd_buf, "PART") == 0 && prefix) { handle_part(params, src_nick); return; } if (strcmp(cmd_buf, "KICK") == 0 && prefix) { handle_kick(params); return; } if (strcmp(cmd_buf, "QUIT") == 0 && prefix) { handle_quit_net(src_nick); return; }