Fix thread safety on cooldown lock, IRC line split to 380 chars

This commit is contained in:
2026-04-08 01:50:03 +00:00
parent deca7228c7
commit d838fe08cf

View File

@@ -263,9 +263,9 @@ class IRCClient:
for line in text.split("\n"): for line in text.split("\n"):
line = line.strip() line = line.strip()
if line: if line:
while len(line) > 400: while len(line) > 380:
self.send(f"PRIVMSG {target} :{line[:400]}") self.send(f"PRIVMSG {target} :{line[:380]}")
line = line[400:] line = line[380:]
self.send(f"PRIVMSG {target} :{line}") self.send(f"PRIVMSG {target} :{line}")
def set_bot_mode(self): def set_bot_mode(self):
@@ -477,6 +477,7 @@ def extract_question(text):
_last_response_time = 0 _last_response_time = 0
_AGENT_COOLDOWN = 10 _AGENT_COOLDOWN = 10
_cooldown_lock = threading.Lock()
def handle_message(irc, source_nick, target, text): def handle_message(irc, source_nick, target, text):
@@ -494,6 +495,7 @@ def handle_message(irc, source_nick, target, text):
if not is_dm and not should_trigger(text): if not is_dm and not should_trigger(text):
return return
with _cooldown_lock:
now = time.time() now = time.time()
if now - _last_response_time < _AGENT_COOLDOWN: if now - _last_response_time < _AGENT_COOLDOWN:
log(f"Cooldown active, ignoring trigger from {source_nick}") log(f"Cooldown active, ignoring trigger from {source_nick}")