2
0
Fork 0
forked from zynk/zynk

Nick-prefixed channel replies for all non-admin commands. (0.40.8)

- Added irc_reply(): 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.
- Converted all non-admin command handlers to use irc_reply() instead of
  raw irc_msg(): !ping, !zynk, !weather, !forecast, !stock, !calc,
  !time, !seen, !tell, !gitlog, !changelog, !ai, !uptime, !version,
  !help, greeting/chat responses, and the 'Not implemented...' fallback.
- Converted AI async responses (ai_check_completion()) to use irc_reply(),
  so AI answers delivered after the original query also show the nick.
- Converted AI error messages in ai_ask() (rate-limit busy, fork failure,
  start failure) to use irc_reply().
- Removed redundant manual nick prefixes from commands that already
  embedded the sender's nick in their response text: !ping, !calc,
  !time, !uptime, and greeting/chat responses.
- Admin commands (!quit, !reload, !restart, !rebuild, !code) are
  intentionally excluded - these are privileged operations where the
  nick prefix adds no value.
- The tell_deliver() function retains its own existing format.
This commit is contained in:
Johannes Findeisen 2026-07-24 04:03:04 +02:00
commit feccad5853
21 changed files with 95 additions and 78 deletions

14
ai.h
View file

@ -234,17 +234,17 @@ void ai_child_task(Session *s, long long id, const char *agent) {
void ai_ask(Session *s, const char *question, const char *reply_target, const char *src_nick, const char *agent) {
if (rate_limit_check(src_nick, reply_target) < 0) return;
if (pending_ai_pid > 0) {
irc_msg(s, reply_target, "Already processing an AI query, please wait.");
irc_reply(s, reply_target, src_nick, "Already processing an AI query, please wait.");
return;
}
db_update_lastq(question);
long long id = 0;
if (ai_start(question, reply_target, src_nick, &id) != 0) {
irc_msg(s, reply_target, "Error starting AI query");
irc_reply(s, reply_target, src_nick, "Error starting AI query");
return;
}
pid_t pid = fork();
if (pid == -1) { ai_reset(id); irc_msg(s, reply_target, "Error forking"); return; }
if (pid == -1) { ai_reset(id); irc_reply(s, reply_target, src_nick, "Error forking"); return; }
if (pid == 0) { ai_child_task(s, id, agent); }
pending_ai_pid = pid;
pending_ai_id = id;
@ -294,7 +294,7 @@ void ai_check_completion(Session *s) {
while (pos < alen) {
size_t end = pos + AI_CHUNK_MAX;
if (end >= alen) {
irc_msg(s, target, answer + pos);
irc_reply(s, target, nick, answer + pos);
chunks++;
break;
}
@ -302,7 +302,7 @@ void ai_check_completion(Session *s) {
if (end <= pos) end = pos + AI_CHUNK_MAX;
char save = answer[end];
answer[end] = 0;
irc_msg(s, target, answer + pos);
irc_reply(s, target, nick, answer + pos);
answer[end] = save;
pos = end + 1;
chunks++;
@ -327,11 +327,11 @@ void ai_check_completion(Session *s) {
if (target) {
char msg[96];
snprintf(msg, sizeof msg, "AI query timed out after %d seconds.", AI_TIMEOUT);
irc_msg(s, target, msg);
irc_reply(s, target, nick, msg);
log_stamp(); fprintf(stderr, CLR_RED "AI done PID %d from %s: timed out for %s" CLR_RESET "\n", done_pid, nick ? nick : "?", target);
}
} else if (target) {
irc_msg(s, target, "AI query failed.");
irc_reply(s, target, nick, "AI query failed.");
log_stamp(); fprintf(stderr, CLR_RED "AI done PID %d from %s: failed for %s" CLR_RESET "\n", done_pid, nick ? nick : "?", target);
}
free(target);