Fix thread safety on cooldown lock, IRC line split to 380 chars
This commit is contained in:
@@ -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]}")
|
||||
|
||||
Reference in New Issue
Block a user