aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillermo Serrahima <dev@vylion.com>2026-02-04 12:35:14 +0100
committerGuillermo Serrahima <dev@vylion.com>2026-02-04 12:35:14 +0100
commitd85b8fbbf0c2baf7c79c344b74115f8c319262b1 (patch)
tree5d13acadf2fe398d0022faa70b587b3363ecb7aa
parente45e87106a51a17c2b19f7c8704b5a0ef436597d (diff)
downloadvelascobot2-main.tar.xz
velascobot2-main.zip
TweaksHEADmain
-rw-r--r--main.py4
-rw-r--r--velascobot2/parrot.py6
2 files changed, 7 insertions, 3 deletions
diff --git a/main.py b/main.py
index 37c5d12..98c9fe6 100644
--- a/main.py
+++ b/main.py
@@ -20,7 +20,7 @@ def load_config(config_path: Path | None) -> dict:
def run_bot(bot: Bot) -> None:
asyncio.run(bot.wake_up())
- bot.app.run_polling(poll_interval=1.0)
+ bot.app.run_polling(poll_interval=0.5)
assert "@" + bot.app.bot.username == bot.messenger.username
@@ -52,7 +52,7 @@ def main(config: Path | None, token: str | None) -> None:
reply = cfg.get("messenger", {}).get("reply", 0.1)
repeat = cfg.get("messenger", {}).get("repeat", 0.05)
wake_up = cfg.get("messenger", {}).get("wake_up", False)
- mute_time = cfg.get("messenger", {}).get("mute_time", 60)
+ mute_time = cfg.get("messenger", {}).get("mute_time", 120)
max_len = cfg.get("messenger", {}).get("max_len", 50)
motd_chats = cfg.get("bot", {}).get("motd_chats", [])
diff --git a/velascobot2/parrot.py b/velascobot2/parrot.py
index be99e20..3e1db94 100644
--- a/velascobot2/parrot.py
+++ b/velascobot2/parrot.py
@@ -73,6 +73,8 @@ class Parrot:
key = _normalize_key(w1, w2)
weighted_next_words = self.db.get_next_words(chat_id, key)
w3 = self.choose_word(weighted_next_words)
+ if w3 is None:
+ raise Exception(f"Got a nonexistent word. Generated text so far: {' '.join(words)}. Dropping text")
words.append(w3)
w1, w2 = w2, w3
return " ".join(words)
@@ -81,7 +83,9 @@ class Parrot:
weighted_graphics = self.db.get_graphics(chat_id)
return self.choose_graphic(weighted_graphics)
- def choose_word(self, weighted_words: list[tuple[str, int]]) -> str:
+ def choose_word(self, weighted_words: list[tuple[str, int]]) -> str | None:
+ if len(weighted_words) == 0:
+ return None
words, weights = zip(*weighted_words)
return random.choices(words, weights=weights)[0]