2
0
Fork 0
forked from zynk/zynk

Added function to make changes to calc.c itself and increased the timeout by adding a constant AI_TIMEOUT to the enum.

This commit is contained in:
Johannes Findeisen 2026-07-14 22:07:18 +02:00
commit 56a733ddfa

36
calc.c
View file

@ -38,7 +38,8 @@ enum {
RBUF_SZ = 16384,
DEF_PORT = 6697,
POLL_MS = 100,
AI_REPLY_MAX = 2048,
AI_REPLY_MAX = 2048,
AI_TIMEOUT = 240,
MAX_CHANS = 32,
MAX_CHAN_OPS = 64,
RATE_LIMIT_WINDOW = 10,
@ -731,7 +732,7 @@ static volatile long long pending_ai_id;
static void ai_child_task(Session *s, long long id) {
signal(SIGALRM, SIG_DFL);
alarm(35);
alarm(AI_TIMEOUT);
/* Don't call tls_cleanup() — SSL_shutdown would send a close_notify on
* the shared fd, breaking the parent's connection. Just release our
* fd reference; the kernel will close it on exit. */
@ -881,7 +882,7 @@ static void ai_check_completion(Session *s) {
}
if (WIFSIGNALED(wstatus) && WTERMSIG(wstatus) == SIGALRM) {
if (target) {
irc_msg(s, target, "AI query timed out after 35 seconds.");
irc_msg(s, target, "AI query timed out after AI_TIMEOUT seconds.");
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) {
@ -1098,6 +1099,34 @@ static int cmd_ai(Session *s, const char *msg, const char *reply_target, const c
return 1;
}
static int cmd_code(Session *s, const char *msg, const char *reply_target, const char *src_nick, const char *tgt) {
if (strncmp(msg, "!code", 5) != 0) return 0;
if (msg[5] != ' ' && msg[5] != '\0') return 0;
if (tgt[0] != '#') {
irc_msg(s, reply_target, "!code can only be used in a channel");
return 1;
}
if (!chan_is_op(tgt, src_nick)) {
irc_msg(s, reply_target, "You need to be a channel op to use !code");
return 1;
}
const char *rest = msg[5] == ' ' ? msg + 6 : "";
while (*rest == ' ') rest++;
if (!*rest) {
irc_msg(s, reply_target, "Usage: !code <instruction for code change>");
return 1;
}
char question[2048];
snprintf(question, sizeof question,
"[CODE CHANGE REQUEST from op %s in %s] %s", src_nick, tgt, rest);
char *end = question + strlen(question);
while (end > question && end[-1] == ' ') end--;
*end = 0;
ai_ask(s, question, reply_target, src_nick);
log_stamp(); fprintf(stderr, CLR_RED "CODE %s from %s (op in %s):" CLR_RESET " %s\n", reply_target, src_nick, tgt, rest);
return 1;
}
static void cmd_greeting_or_chat(Session *s, const char *msg, const char *reply_target, const char *src_nick) {
int nicklen = strlen(s->nick);
const char *cmd = msg;
@ -1155,6 +1184,7 @@ static void handle_privmsg(Session *s, const char *params, const char *src_nick)
if (cmd_weather(s, msg, reply_target, src_nick)) return;
if (cmd_forecast(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;
cmd_greeting_or_chat(s, msg, reply_target, src_nick);
}