This commit is contained in:
Slipstream 2025-05-13 10:44:56 -06:00
parent d9eca8b9b6
commit 9168da2537
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -3,6 +3,8 @@ from discord.ext import commands
from discord import app_commands
import re
import random
import os
import aiohttp
def _owoify_text(text: str) -> str:
"""Improved owoification with more rules and randomness."""
@ -44,6 +46,33 @@ def _owoify_text(text: str) -> str:
text += random.choice(interjections)
return text
async def _owoify_text_ai(text: str) -> str:
"""Owoify text using AI via OpenRouter (google/gemini-2.0-flash-exp:free)."""
api_key = os.getenv("AI_API_KEY")
if not api_key:
raise RuntimeError("AI_API_KEY environment variable not set.")
url = "https://openrouter.ai/v1/chat/completions"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
payload = {
"model": "google/gemini-2.0-flash-exp:free",
"messages": [
{"role": "system", "content": (
"You are a playful text transformer that turns user input into an uwu/owo style of speech. "
"You must always respond ONLY with the transformed text, never with any explanation or extra commentary. "
"Make the output as playful, creative, and expressive as possible, using a variety of cute interjections, "
"stuttering, and playful punctuation. Preserve the meaning and structure of the input, but maximize the 'owo' style."
)},
{"role": "user", "content": text}
]
}
async with aiohttp.ClientSession() as session:
async with session.post(url, headers=headers, json=payload) as resp:
data = await resp.json()
return data["choices"][0]["message"]["content"]
class OwoifyCog(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
@ -58,6 +87,19 @@ class OwoifyCog(commands.Cog):
owo_text = _owoify_text(message_to_owoify)
await interaction.response.send_message(owo_text)
@app_commands.command(name="owoify_ai", description="Owoify your message with AI!")
@app_commands.describe(message_to_owoify="The message to owoify using AI")
async def owoify_ai_slash_command(self, interaction: discord.Interaction, message_to_owoify: str):
"""Owoifies the provided message via the OpenRouter AI."""
if not message_to_owoify.strip():
await interaction.response.send_message("You nyeed to pwovide some text to owoify! >w<", ephemeral=True)
return
try:
owo_text = await _owoify_text_ai(message_to_owoify)
await interaction.response.send_message(owo_text)
except Exception as e:
await interaction.response.send_message(f"AI owoification failed: {e} >w<", ephemeral=True)
# Context menu command must be defined at module level
@app_commands.context_menu(name="Owoify Message")
async def owoify_context_menu(interaction: discord.Interaction, message: discord.Message):