mirror of
https://git.squeakyrat.moe/faggot-chan/
synced 2026-11-04 18:35:45 +01:00
asked claude to fix a bug i caused
This commit is contained in:
1 parent
a8fdeb52f0
commit
c3b8b4ee86
3 files changed
+28
-11
No files matched your search
@@ -0,0 +1,2 @@
|
||||
files
|
||||
env
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user