"""Dev-only tools for testing Paper Dynasty systems. This cog is only loaded when DATABASE != prod. It provides commands for integration testing that create and clean up synthetic test data. """ import logging import discord from discord import app_commands from discord.ext import commands from api_calls import db_delete logger = logging.getLogger(__name__) class CleanupView(discord.ui.View): """Post-test buttons to clean up or keep synthetic game data.""" def __init__( self, owner_id: int, game_id: int, embed: discord.Embed, timeout: float = 300.0 ): super().__init__(timeout=timeout) self.owner_id = owner_id self.game_id = game_id self.embed = embed @discord.ui.button( label="Clean Up Test Data", style=discord.ButtonStyle.danger, emoji="๐Ÿงน" ) async def cleanup_btn( self, interaction: discord.Interaction, button: discord.ui.Button ): if interaction.user.id != self.owner_id: return try: await db_delete("decisions/game", self.game_id) await db_delete("plays/game", self.game_id) await db_delete("games", self.game_id) self.embed.add_field( name="", value=f"๐Ÿงน Test data cleaned up (game #{self.game_id} removed)", inline=False, ) except Exception as e: self.embed.add_field( name="", value=f"โŒ Cleanup failed: {e}", inline=False, ) self.clear_items() await interaction.response.edit_message(embed=self.embed, view=self) self.stop() @discord.ui.button( label="Keep Test Data", style=discord.ButtonStyle.secondary, emoji="๐Ÿ“Œ" ) async def keep_btn( self, interaction: discord.Interaction, button: discord.ui.Button ): if interaction.user.id != self.owner_id: return self.embed.add_field( name="", value=f"๐Ÿ“Œ Test data kept (game #{self.game_id})", inline=False, ) self.clear_items() await interaction.response.edit_message(embed=self.embed, view=self) self.stop() async def on_timeout(self): self.clear_items()