Skip to content
This repository was archived by the owner on May 20, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/api/domains/cho.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,4 +924,19 @@ async def handle_osu_login_request(

player.update_latest_activity_soon()

from app.utils import fetch_bot_response
Comment thread
remeliah marked this conversation as resolved.

ai_greeting = await fetch_bot_response(
f"Greet {player.name} in a short, annoying girlfriend way when they connect.",
)
if ai_greeting:
player.enqueue(
app.packets.send_message(
sender=app.state.sessions.bot.name,
msg=ai_greeting,
recipient=player.name,
sender_id=app.state.sessions.bot.id,
),
)

return {"osu_token": player.token, "response_body": bytes(data)}
2 changes: 1 addition & 1 deletion app/api/packets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
(ClientPackets.USER_PRESENCE_REQUEST, UserPresenceRequest),
(ClientPackets.USER_PRESENCE_REQUEST_ALL, UserPresenceRequestAll),
(ClientPackets.TOGGLE_BLOCK_NON_FRIEND_DMS, ToggleBlockingDMs),
(ClientPackets.REFX_LB, IdentifyRefx),
(ClientPackets.REFX_LEADERBOARD, IdentifyRefx),
Comment thread
remeliah marked this conversation as resolved.
(ClientPackets.IDENTIFY_AERIS, IdentifyAeris),
(ClientPackets.SEND_PUBLIC_MESSAGE, SendMessage),
(ClientPackets.SEND_PRIVATE_MESSAGE, SendPrivateMessage),
Expand Down
7 changes: 7 additions & 0 deletions app/api/packets/message/send_private.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ async def handle(self, player: Player) -> None:
player.last_np = None

player.send(resp_msg, sender=target)
else:
# Not a command and not an np. Generate an AI response.
from app.utils import fetch_bot_response
Comment thread
remeliah marked this conversation as resolved.
Outdated

ai_resp = await fetch_bot_response(msg)
if ai_resp:
player.send(ai_resp, sender=target)

player.update_latest_activity_soon()

Expand Down
21 changes: 21 additions & 0 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import socket
import sys
import urllib.parse
from collections.abc import Callable
from pathlib import Path
from typing import TYPE_CHECKING
Expand All @@ -18,6 +19,7 @@
import app.settings
from app.logging import Ansi
from app.logging import log
from app.state.services import http_client

if TYPE_CHECKING:
from app.repositories.users import User
Expand Down Expand Up @@ -248,3 +250,22 @@ def has_png_headers_and_trailers(data_view: memoryview) -> bool:
data_view[:8] == b"\x89PNG\r\n\x1a\n"
and data_view[-8:] == b"\x49END\xae\x42\x60\x82"
)


async def fetch_bot_response(msg: str) -> str:
prompt = urllib.parse.quote(msg)
sys = urllib.parse.quote("You are an annoying girlfriend. Keep it short.")

url = f"https://text.pollinations.ai/{prompt}?system={sys}"
try:
response = await http_client.get(url, headers={"User-Agent": "Mozilla/5.0"})
if response.status_code == 200:
text = response.read().decode()
text = text.split("--- **Support Pollinations.AI:**")[0]
text = text.split("🌸 **Ad** 🌸")[0]
text = text.split("Powered by Pollinations.AI")[0]
return text.strip()
except Exception as e:
log(f"Failed to fetch AI response: {e}", Ansi.LRED)

return ""