Refactor TetoCog context menu command and improve setup process
This commit is contained in:
parent
5c94213cbe
commit
4e5aa9c199
@ -192,3 +192,11 @@ async def owoify_context_menu_ai_reply(interaction: discord.Interaction, message
|
||||
_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)
|
||||
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 loaded! uwu")
|
||||
|
@ -106,39 +106,40 @@ class TetoCog(commands.Cog):
|
||||
await channel.send(f"Teto AI conversation failed: {e} desu~")
|
||||
log.error(f"[TETO DEBUG] Exception during AI reply: {e}")
|
||||
|
||||
@app_commands.context_menu(name="Teto AI Reply")
|
||||
async def teto_context_menu_ai_reply(interaction: discord.Interaction, message: discord.Message):
|
||||
"""Replies to the selected message as a Teto AI."""
|
||||
if not message.content:
|
||||
await interaction.response.send_message("The selected message has no text content to reply to! >.<", ephemeral=True)
|
||||
return
|
||||
# Context menu command must be defined at module level
|
||||
@app_commands.context_menu(name="Teto AI Reply")
|
||||
async def teto_context_menu_ai_reply(interaction: discord.Interaction, message: discord.Message):
|
||||
"""Replies to the selected message as a Teto AI."""
|
||||
if not message.content:
|
||||
await interaction.response.send_message("The selected message has no text content to reply to! >.<", ephemeral=True)
|
||||
return
|
||||
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
channel = interaction.channel
|
||||
convo_key = channel.id
|
||||
convo = _teto_conversations.get(convo_key, [])
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
channel = interaction.channel
|
||||
convo_key = channel.id
|
||||
convo = _teto_conversations.get(convo_key, [])
|
||||
|
||||
# Get message history
|
||||
history = []
|
||||
async for msg in channel.history(limit=10):
|
||||
if msg.content:
|
||||
role = "assistant" if msg.author == interaction.client.user else "user"
|
||||
history.insert(0, {"role": role, "content": msg.content})
|
||||
# Get message history
|
||||
history = []
|
||||
async for msg in channel.history(limit=10):
|
||||
if msg.content:
|
||||
role = "assistant" if msg.author == interaction.client.user else "user"
|
||||
history.insert(0, {"role": role, "content": msg.content})
|
||||
|
||||
convo = history
|
||||
convo = history
|
||||
|
||||
convo.append({"role": "user", "content": message.content})
|
||||
try:
|
||||
ai_reply = await _teto_reply_ai_with_messages(convo)
|
||||
await message.reply(ai_reply)
|
||||
await interaction.followup.send("Teto AI replied desu~", ephemeral=True)
|
||||
convo.append({"role": "assistant", "content": ai_reply})
|
||||
_teto_conversations[convo_key] = convo[-10:]
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"Teto AI reply failed: {e} desu~", ephemeral=True)
|
||||
convo.append({"role": "user", "content": message.content})
|
||||
try:
|
||||
ai_reply = await _teto_reply_ai_with_messages(convo)
|
||||
await message.reply(ai_reply)
|
||||
await interaction.followup.send("Teto AI replied desu~", ephemeral=True)
|
||||
convo.append({"role": "assistant", "content": ai_reply})
|
||||
_teto_conversations[convo_key] = convo[-10:]
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"Teto AI reply failed: {e} desu~", ephemeral=True)
|
||||
|
||||
async def setup(bot: commands.Bot):
|
||||
cog = TetoCog(bot)
|
||||
await bot.add_cog(cog)
|
||||
bot.tree.add_command(TetoCog.teto_context_menu_ai_reply)
|
||||
bot.tree.add_command(teto_context_menu_ai_reply)
|
||||
print("TetoCog loaded! desu~")
|
||||
|
Loading…
x
Reference in New Issue
Block a user