From c3b8b4ee862263f41269abdc1b0312f3394a512b Mon Sep 17 00:00:00 2001 From: david Date: Wed, 11 Mar 2026 20:48:50 -0300 Subject: asked claude to fix a bug i caused --- .gitignore | 2 ++ bot.py | 34 +++++++++++++++++++++++++--------- main.py | 3 +-- 3 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f2818a9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +files +env diff --git a/bot.py b/bot.py index d32ea22..39ad29f 100644 --- a/bot.py +++ b/bot.py @@ -94,12 +94,16 @@ def load_longterm() -> list[str]: return [] def build_payload(sys_prompt: str, user_input: str, rebuild: bool = False) -> str: + global vector_db_ready + should_rebuild = rebuild or not vector_db_ready # always rebuild on first ever message + if should_rebuild: + vector_db_ready = True return json.dumps({ "system_prompt": sys_prompt, "user_input": user_input, "shortterm": load_shortterm(), "longterm": load_longterm(), - "rebuild_vectors": rebuild, + "rebuild_vectors": should_rebuild, }) async def call_main(payload: str) -> tuple[bool, str]: @@ -130,6 +134,13 @@ async def handle_error(error_msg: str, notify_channel=None, notify_user=None): except Exception: pass +async def keep_typing(channel, stop_event): + while not stop_event.is_set(): + await channel.typing() + await asyncio.sleep(8) # refresh every 8s before discord's 10s timeout + +vector_db_ready = False # gets set to True after first rebuild so we don't keep rebuilding + saved_media_urls = set() with MEDIA_FILE.open("r", encoding="utf-8") as f: @@ -172,14 +183,16 @@ async def random_dm(): "It should sound like something faggot-chan would post when she's bored — chaotic, funny, and full of personality (at least 20 words)." "keep in mind this is a dm so make it a bit personal" ) + stop_typing = asyncio.Event() + asyncio.create_task(keep_typing(victim.dm_channel or await victim.create_dm(), stop_typing)) ok, result = await call_main(payload) + stop_typing.set() if not ok: await handle_error(result, notify_user=victim) continue try: #sends the dm dm = await victim.create_dm() - async with dm.typing(): - await dm.send(result) + await dm.send(result) dm_sent = True log_message(f"[{timestamp()}]Faggot-chan sent a random dm to {victim}: {result}") print(f"[{timestamp()}] random dm to {victim}: {result}") @@ -206,8 +219,7 @@ async def random_message(): if not ok: await handle_error(result, notify_channel=channel) continue - async with channel.typing(): - await channel.send(result) + await channel.send(result) log_message(f"[{timestamp()}] random message: {result}") print(f"[{timestamp()}] random message: {result}") @@ -337,13 +349,15 @@ async def on_message(message): else: user_input = f"{message.author} said in DM: {message.content}" payload = build_payload(system_prompt, user_input, rebuild) + stop_typing = asyncio.Event() + asyncio.create_task(keep_typing(message.channel, stop_typing)) ok, result = await call_main(payload) + stop_typing.set() if not ok: await handle_error(result, notify_user=message.author) return try: - async with message.channel.typing(): - await message.reply(result) + await message.reply(result) print(f"[{timestamp()}] DM from {message.author}: {message.content} Bot replied in DM: {result}") log_message(f"[{timestamp()}] DM from {message.author}: {message.content}") log_message(f"[{timestamp()}] Faggot-chan replied in DM: {result}") @@ -369,14 +383,16 @@ async def on_message(message): user_input = f"{message.author} said: {message.content}" payload = build_payload(system_prompt, user_input, rebuild) + stop_typing = asyncio.Event() + asyncio.create_task(keep_typing(message.channel, stop_typing)) ok, result = await call_main(payload) + stop_typing.set() if not ok: await handle_error(result, notify_channel=message.channel) return try: - async with message.channel.typing(): - await message.reply(result) + await message.reply(result) print(f"[{timestamp()}] {message.author} said: {message.content}\n[{timestamp()}] Faggot-chan said: {result}") log_message(f"[{timestamp()}] {message.author} said: {message.content}\n[{timestamp()}] Faggot-chan said: {result}") except Exception as e: diff --git a/main.py b/main.py index 6091a7d..f1e7dfa 100644 --- a/main.py +++ b/main.py @@ -10,11 +10,10 @@ from datetime import datetime embedmodel = 'hf.co/CompendiumLabs/bge-base-en-v1.5-gguf' # these are test models just ignore -chatmodel = "hf.co/tvall43/Qwen3.5-4B-heretic-gguf:Q4_K_M" #chatmodel = 'hf.co/bartowski/Llama-3.2-1B-Instruct-GGUF' #chatmodel = 'hf.co/VibeStudio/Nidum-Llama-3.2-3B-Uncensored-GGUF' #chatmodel = "faggotchan" -#chatmodel = "deepseek-r1:1.5b" +chatmodel = "qwen3.5:4b" NUM_THREADS = 6 # hardcoded since threads.txt is gone, change if needed -- cgit v1.3-2-g0d8e