ffg
This commit is contained in:
parent
afdb1cb7d2
commit
0a5dc14b04
@ -6,6 +6,9 @@ import random
|
||||
import os
|
||||
import aiohttp
|
||||
|
||||
# In-memory conversation history for owo AI (keyed by channel id)
|
||||
_owo_conversations = {}
|
||||
|
||||
def _owoify_text(text: str) -> str:
|
||||
"""Improved owoification with more rules and randomness."""
|
||||
# Basic substitutions
|
||||
@ -48,6 +51,13 @@ def _owoify_text(text: str) -> str:
|
||||
|
||||
async def _owoify_text_ai(text: str) -> str:
|
||||
"""Owoify text using AI via OpenRouter (google/gemini-2.0-flash-exp:free)."""
|
||||
return await _owoify_text_ai_with_messages([{"role": "user", "content": text}], system_mode="transform")
|
||||
|
||||
async def _owoify_text_ai_with_messages(messages, system_mode="transform"):
|
||||
"""
|
||||
Use OpenRouter AI to generate an owoified response.
|
||||
system_mode: "transform" for just transforming, "reply" for replying as an owo AI.
|
||||
"""
|
||||
api_key = os.getenv("AI_API_KEY")
|
||||
if not api_key:
|
||||
raise RuntimeError("AI_API_KEY environment variable not set.")
|
||||
@ -56,18 +66,23 @@ async def _owoify_text_ai(text: str) -> str:
|
||||
"Authorization": f"Bearer {api_key}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
if system_mode == "transform":
|
||||
system_prompt = (
|
||||
"You are a text transformer. Your ONLY job is to convert the user's input into an uwu/owo style of speech. "
|
||||
"Do NOT reply, greet, or comment. Do NOT add any extra words, context, or explanation. "
|
||||
"Return ONLY the transformed version of the input text, preserving punctuation and structure. "
|
||||
"Make the output playful, creative, and expressive, using a variety of cute interjections, stuttering, and playful punctuation. "
|
||||
"Never act as if you are replying to a message—just output the transformed text."
|
||||
)
|
||||
else:
|
||||
system_prompt = (
|
||||
"You are an uwu/owo style AI chatbot. Reply to the user in a playful, expressive, and cute uwu/owo style. "
|
||||
"Stay in character, use lots of interjections, stuttering, and playful punctuation. "
|
||||
"You are having a conversation, so respond naturally and keep the conversation going in uwu/owo style."
|
||||
)
|
||||
payload = {
|
||||
"model": "google/gemini-2.0-flash-exp:free",
|
||||
"messages": [
|
||||
{"role": "system", "content": (
|
||||
"You are a text transformer. Your ONLY job is to convert the user's input into an uwu/owo style of speech. "
|
||||
"Do NOT reply, greet, or comment. Do NOT add any extra words, context, or explanation. "
|
||||
"Return ONLY the transformed version of the input text, preserving punctuation and structure. "
|
||||
"Make the output playful, creative, and expressive, using a variety of cute interjections, stuttering, and playful punctuation. "
|
||||
"Never act as if you are replying to a message—just output the transformed text."
|
||||
)},
|
||||
{"role": "user", "content": text}
|
||||
]
|
||||
"messages": [{"role": "system", "content": system_prompt}] + messages
|
||||
}
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.post(url, headers=headers, json=payload) as resp:
|
||||
@ -147,10 +162,47 @@ async def owoify_context_menu_ai(interaction: discord.Interaction, message: disc
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"AI owoification failed: {e} >w<", ephemeral=True)
|
||||
|
||||
@app_commands.context_menu(name="Owo AI Reply")
|
||||
async def owoify_context_menu_ai_reply(interaction: discord.Interaction, message: discord.Message):
|
||||
"""Replies to the selected message as an owo AI."""
|
||||
if not message.content:
|
||||
await interaction.response.send_message("The sewected message has no text content to reply to! >.<", ephemeral=True)
|
||||
return
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
convo_key = message.channel.id
|
||||
convo = _owo_conversations.get(convo_key, [])
|
||||
convo.append({"role": "user", "content": message.content})
|
||||
try:
|
||||
ai_reply = await _owoify_text_ai_with_messages(convo, system_mode="reply")
|
||||
await message.reply(ai_reply)
|
||||
await interaction.followup.send("AI replied in owo style! uwu", ephemeral=True)
|
||||
convo.append({"role": "assistant", "content": ai_reply})
|
||||
_owo_conversations[convo_key] = convo[-10:] # Keep last 10 messages
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"AI owo reply failed: {e} >w<", ephemeral=True)
|
||||
|
||||
async def setup(bot: commands.Bot):
|
||||
cog = OwoifyCog(bot)
|
||||
await bot.add_cog(cog)
|
||||
# Add the context menu commands to the tree
|
||||
# Add context menu commands globally (do not use guild=... for global commands)
|
||||
bot.tree.add_command(owoify_context_menu)
|
||||
bot.tree.add_command(owoify_context_menu_ai)
|
||||
bot.tree.add_command(owoify_context_menu_ai_reply)
|
||||
print("OwoifyCog woaded! uwu")
|
||||
|
||||
# Conversation handler: reply to mentions or replies to the bot in owo style
|
||||
@commands.Cog.listener()
|
||||
async def on_message(self, message: discord.Message):
|
||||
if message.author.bot:
|
||||
return
|
||||
if (self.bot.user in message.mentions) or (message.reference and getattr(message.reference.resolved, "author", None) == self.bot.user):
|
||||
convo_key = message.channel.id
|
||||
convo = _owo_conversations.get(convo_key, [])
|
||||
convo.append({"role": "user", "content": message.content})
|
||||
try:
|
||||
ai_reply = await _owoify_text_ai_with_messages(convo, system_mode="reply")
|
||||
await message.reply(ai_reply)
|
||||
convo.append({"role": "assistant", "content": ai_reply})
|
||||
_owo_conversations[convo_key] = convo[-10:]
|
||||
except Exception as e:
|
||||
await message.channel.send(f"AI owo conversation failed: {e} >w<")
|
||||
|
Loading…
x
Reference in New Issue
Block a user