import discord from .check import Check class RPGMenu(discord.ui.View): def __init__(self, rpg_cog): super().__init__() self.rpg_cog = rpg_cog @discord.ui.button(label="Create Character", style=discord.ButtonStyle.primary, custom_id="create_character_button") async def create_character_button_callback(self, interaction: discord.Interaction, button: discord.ui.Button): await interaction.response.send_modal(CreateCharacterModal(self.rpg_cog)) @discord.ui.button(label="Attack", style=discord.ButtonStyle.red, custom_id="attack_button") async def attack_button_callback(self, interaction: discord.Interaction, button: discord.ui.Button): # You'll need to implement the target selection logic here (e.g., using a dropdown or another interaction) target = None # Placeholder for now if target: await self.rpg_cog.actions.attack(interaction, interaction.user, target) else: await interaction.response.send_message("You need to select a target to attack.", ephemeral=True) @discord.ui.button(label="Heal", style=discord.ButtonStyle.green, custom_id="heal_button") async def heal_button_callback(self, interaction: discord.Interaction, button: discord.ui.Button): await self.rpg_cog.actions.heal(interaction, interaction.user) @discord.ui.button(label="Stats", style=discord.ButtonStyle.blurple, custom_id="stats_button") async def stats_button_callback(self, interaction: discord.Interaction, button: discord.ui.Button): await self.rpg_cog.actions.display_stats(interaction, interaction.user) @discord.ui.button(label="Inventory", style=discord.ButtonStyle.grey, custom_id="inventory_button") async def inventory_button_callback(self, interaction: discord.Interaction, button: discord.ui.Button): await self.rpg_cog.inventory.display_inventory(interaction, interaction.user) class CreateCharacterModal(discord.ui.Modal): def __init__(self, rpg_cog): super().__init__(title="Create Character") self.rpg_cog = rpg_cog self.character_name = discord.ui.TextInput( label="Enter your character's name:", placeholder="e.g., BraveAdventurer", required=True, max_length=30 ) self.add_item(self.character_name) async def on_submit(self, interaction: discord.Interaction): character_name = self.character_name.value #author = interaction.user try: await self.rpg_cog.actions.create_character(interaction, interaction.user, character_name) except Exception as e: await interaction.response.send_message(f"```An error occurred while creating your character: {e}```") self.rpg_cog.log.error(f"Error in create_character: {e}")