From d838fe08cf4f10028660f9bcbbdf7968845a657e Mon Sep 17 00:00:00 2001 From: ansible Date: Wed, 8 Apr 2026 01:50:03 +0000 Subject: [PATCH] Fix thread safety on cooldown lock, IRC line split to 380 chars --- agent/agent.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/agent/agent.py b/agent/agent.py index 718885e..dd8a5ed 100644 --- a/agent/agent.py +++ b/agent/agent.py @@ -263,9 +263,9 @@ class IRCClient: for line in text.split("\n"): line = line.strip() if line: - while len(line) > 400: - self.send(f"PRIVMSG {target} :{line[:400]}") - line = line[400:] + while len(line) > 380: + self.send(f"PRIVMSG {target} :{line[:380]}") + line = line[380:] self.send(f"PRIVMSG {target} :{line}") def set_bot_mode(self): @@ -477,6 +477,7 @@ def extract_question(text): _last_response_time = 0 _AGENT_COOLDOWN = 10 +_cooldown_lock = threading.Lock() def handle_message(irc, source_nick, target, text): @@ -494,11 +495,12 @@ def handle_message(irc, source_nick, target, text): if not is_dm and not should_trigger(text): return - now = time.time() - if now - _last_response_time < _AGENT_COOLDOWN: - log(f"Cooldown active, ignoring trigger from {source_nick}") - return - _last_response_time = now + with _cooldown_lock: + now = time.time() + if now - _last_response_time < _AGENT_COOLDOWN: + log(f"Cooldown active, ignoring trigger from {source_nick}") + return + _last_response_time = now question = extract_question(text) if not is_dm else text log(f"Triggered by {source_nick} in {channel}: {question[:80]}")