From 5f4939367a19a3e4d98577613cb059cc587545e5 Mon Sep 17 00:00:00 2001 From: SimolZimol <70102430+SimolZimol@users.noreply.github.com> Date: Thu, 30 Oct 2025 21:42:09 +0100 Subject: [PATCH] modified: app.py --- app.py | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/app.py b/app.py index f16b19b..18e3abd 100644 --- a/app.py +++ b/app.py @@ -665,6 +665,98 @@ async def hoi4create(ctx, game_type: str, game_name: str): except Exception as e: await ctx.send(f"❌ Error creating game: {str(e)}") +@bot.hybrid_command(name='hoi4delete', description='Delete a game lobby') +async def hoi4delete(ctx, game_name: str): + """Delete a game lobby that is in setup phase""" + try: + async with db_pool.acquire() as conn: + async with conn.cursor(aiomysql.DictCursor) as cursor: + # Get the game + await cursor.execute( + "SELECT * FROM games WHERE game_name = %s AND status = 'setup'", + (game_name,) + ) + game = await cursor.fetchone() + + if not game: + await ctx.send(f"❌ No active game found with name '{game_name}' in setup phase!") + return + + # Delete the game + await cursor.execute( + "DELETE FROM games WHERE id = %s", + (game['id'],) + ) + + embed = discord.Embed( + title="🗑️ Game Deleted", + description=f"Game '{game_name}' has been deleted!", + color=discord.Color.red() + ) + embed.add_field(name="Game Name", value=game_name, inline=True) + embed.add_field(name="Type", value=game['game_type'].title(), inline=True) + embed.set_footer(text=f"Deleted by {ctx.author}") + + await ctx.send(embed=embed) + + except Exception as e: + await ctx.send(f"❌ Error deleting game: {str(e)}") + +@bot.hybrid_command(name='hoi4remove', description='Remove a player from an existing game') +async def hoi4remove(ctx, game_name: str, user: discord.Member): + """Remove a player from an existing game""" + try: + async with db_pool.acquire() as conn: + async with conn.cursor(aiomysql.DictCursor) as cursor: + # Get the game + await cursor.execute( + "SELECT * FROM games WHERE game_name = %s AND status = 'setup'", + (game_name,) + ) + game = await cursor.fetchone() + + if not game: + await ctx.send(f"❌ No game found with name '{game_name}' in setup phase!") + return + + # Parse existing players + players = json.loads(game['players']) if game['players'] else [] + + # Find and remove the player + player_found = False + new_players = [] + for p in players: + if p['discord_id'] == user.id: + player_found = True + # Skip this player (don't add to new_players) + else: + new_players.append(p) + + if not player_found: + await ctx.send(f"❌ {user.display_name} is not in this game!") + return + + # Update game with new player list + await cursor.execute( + "UPDATE games SET players = %s WHERE id = %s", + (json.dumps(new_players), game['id']) + ) + + embed = discord.Embed( + title="✅ Player Removed", + description=f"{user.display_name} has been removed from '{game_name}'!", + color=discord.Color.orange() + ) + embed.add_field(name="Player", value=user.display_name, inline=True) + embed.add_field(name="Game", value=game_name, inline=True) + embed.add_field(name="Players Left", value=len(new_players), inline=True) + embed.set_footer(text=f"Removed by {ctx.author}") + + await ctx.send(embed=embed) + + except Exception as e: + await ctx.send(f"❌ Error removing player: {str(e)}") + @bot.hybrid_command(name='hoi4setup', description='Add a player to an existing game') async def hoi4setup(ctx, game_name: str, user: discord.Member, team_name: str, t_level: int, country: Optional[str] = None): """Add a player to an existing game"""