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"):
|
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,11 +495,12 @@ 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
|
||||||
|
|
||||||
now = time.time()
|
with _cooldown_lock:
|
||||||
if now - _last_response_time < _AGENT_COOLDOWN:
|
now = time.time()
|
||||||
log(f"Cooldown active, ignoring trigger from {source_nick}")
|
if now - _last_response_time < _AGENT_COOLDOWN:
|
||||||
return
|
log(f"Cooldown active, ignoring trigger from {source_nick}")
|
||||||
_last_response_time = now
|
return
|
||||||
|
_last_response_time = now
|
||||||
|
|
||||||
question = extract_question(text) if not is_dm else text
|
question = extract_question(text) if not is_dm else text
|
||||||
log(f"Triggered by {source_nick} in {channel}: {question[:80]}")
|
log(f"Triggered by {source_nick} in {channel}: {question[:80]}")
|
||||||
|
|||||||
Reference in New Issue
Block a user