diff options
| author | david <[email protected]> | 2026-03-11 20:48:50 -0300 |
|---|---|---|
| committer | david <[email protected]> | 2026-03-11 20:48:50 -0300 |
| commit | c3b8b4ee862263f41269abdc1b0312f3394a512b (patch) | |
| tree | c0aed9c14682d2bbb7c17128f6414c2561b3d816 /bot.py | |
| parent | a8fdeb52f075d3267a938f5298dd1549feeeafbc (diff) | |
| download | faggot-chan-c3b8b4ee862263f41269abdc1b0312f3394a512b.tar.gz faggot-chan-c3b8b4ee862263f41269abdc1b0312f3394a512b.zip | |
asked claude to fix a bug i caused
Diffstat (limited to 'bot.py')
| -rw-r--r-- | bot.py | 34 |
1 files changed, 25 insertions, 9 deletions
@@ -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: |
