This commit is contained in:
Slipstream 2025-05-03 16:46:30 -06:00
parent 1500e9d768
commit 9d5f5d3255
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD
3 changed files with 75 additions and 146 deletions

View File

@ -71,174 +71,143 @@ class EconomyCog(
self.bot = bot
# Create the main command group for this cog
self.economy_group = app_commands.Group(
name="economy",
self.econ_group = app_commands.Group(
name="econ",
description="Economy system commands"
)
# Create subgroups
self.earning_group = app_commands.Group(
name="earning",
description="Commands for earning currency",
parent=self.economy_group
)
self.gambling_group = app_commands.Group(
name="gambling",
description="Gambling and games of chance",
parent=self.economy_group
)
self.utility_group = app_commands.Group(
name="utility",
description="Utility commands for the economy system",
parent=self.economy_group
)
self.risky_group = app_commands.Group(
name="risky",
description="High-risk, high-reward commands",
parent=self.economy_group
)
self.jobs_group = app_commands.Group(
name="jobs",
description="Job-related commands",
parent=self.economy_group
)
# Register commands
self.register_commands()
# Add command groups to the bot's tree
self.bot.tree.add_command(self.economy_group)
# Add command group to the bot's tree
self.bot.tree.add_command(self.econ_group)
log.info("EconomyCog initialized with command groups.")
log.info("EconomyCog initialized with econ command group.")
def register_commands(self):
"""Register all commands for this cog"""
# --- Earning Group Commands ---
# --- Earning Commands ---
# Daily command
daily_command = app_commands.Command(
name="daily",
description="Claim your daily reward",
callback=self.economy_daily_callback,
parent=self.earning_group
parent=self.econ_group
)
self.earning_group.add_command(daily_command)
self.econ_group.add_command(daily_command)
# Beg command
beg_command = app_commands.Command(
name="beg",
description="Beg for some spare change",
callback=self.economy_beg_callback,
parent=self.earning_group
parent=self.econ_group
)
self.earning_group.add_command(beg_command)
self.econ_group.add_command(beg_command)
# Work command
work_command = app_commands.Command(
name="work",
description="Do some work for a guaranteed reward",
callback=self.economy_work_callback,
parent=self.earning_group
parent=self.econ_group
)
self.earning_group.add_command(work_command)
self.econ_group.add_command(work_command)
# Scavenge command
scavenge_command = app_commands.Command(
name="scavenge",
description="Scavenge around for some spare change",
callback=self.economy_scavenge_callback,
parent=self.earning_group
parent=self.econ_group
)
self.earning_group.add_command(scavenge_command)
self.econ_group.add_command(scavenge_command)
# --- Gambling Group Commands ---
# --- Gambling Commands ---
# Coinflip command
coinflip_command = app_commands.Command(
name="coinflip",
description="Bet on a coin flip",
callback=self.economy_coinflip_callback,
parent=self.gambling_group
parent=self.econ_group
)
self.gambling_group.add_command(coinflip_command)
self.econ_group.add_command(coinflip_command)
# Slots command
slots_command = app_commands.Command(
name="slots",
description="Play the slot machine",
callback=self.economy_slots_callback,
parent=self.gambling_group
parent=self.econ_group
)
self.gambling_group.add_command(slots_command)
self.econ_group.add_command(slots_command)
# --- Utility Group Commands ---
# --- Utility Commands ---
# Balance command
balance_command = app_commands.Command(
name="balance",
description="Check your balance",
callback=self.economy_balance_callback,
parent=self.utility_group
parent=self.econ_group
)
self.utility_group.add_command(balance_command)
self.econ_group.add_command(balance_command)
# Transfer command
transfer_command = app_commands.Command(
name="transfer",
description="Transfer money to another user",
callback=self.economy_transfer_callback,
parent=self.utility_group
parent=self.econ_group
)
self.utility_group.add_command(transfer_command)
self.econ_group.add_command(transfer_command)
# Leaderboard command
leaderboard_command = app_commands.Command(
name="leaderboard",
description="View the economy leaderboard",
callback=self.economy_leaderboard_callback,
parent=self.utility_group
parent=self.econ_group
)
self.utility_group.add_command(leaderboard_command)
self.econ_group.add_command(leaderboard_command)
# --- Risky Group Commands ---
# --- Risky Commands ---
# Rob command
rob_command = app_commands.Command(
name="rob",
description="Attempt to rob another user",
callback=self.economy_rob_callback,
parent=self.risky_group
parent=self.econ_group
)
self.risky_group.add_command(rob_command)
self.econ_group.add_command(rob_command)
# --- Jobs Group Commands ---
# --- Jobs Commands ---
# Apply command
apply_command = app_commands.Command(
name="apply",
description="Apply for a job",
callback=self.economy_apply_callback,
parent=self.jobs_group
parent=self.econ_group
)
self.jobs_group.add_command(apply_command)
self.econ_group.add_command(apply_command)
# Quit command
quit_command = app_commands.Command(
name="quit",
description="Quit your current job",
callback=self.economy_quit_callback,
parent=self.jobs_group
parent=self.econ_group
)
self.jobs_group.add_command(quit_command)
self.econ_group.add_command(quit_command)
# List command
list_command = app_commands.Command(
name="list",
joblist_command = app_commands.Command(
name="joblist",
description="List available jobs",
callback=self.economy_joblist_callback,
parent=self.jobs_group
parent=self.econ_group
)
self.jobs_group.add_command(list_command)
self.econ_group.add_command(joblist_command)
async def cog_load(self):
"""Called when the cog is loaded, ensures DB is initialized."""
@ -843,6 +812,6 @@ async def setup(bot: commands.Bot):
print("Setting up EconomyCog...")
cog = EconomyCog(bot)
await bot.add_cog(cog)
log.info("Combined EconomyCog added to bot with command groups.")
print(f"EconomyCog setup complete with command groups: {[cmd.name for cmd in bot.tree.get_commands() if cmd.name == 'economy']}")
print(f"Available subgroups: {[group.name for group in cog.economy_group.walk_commands() if isinstance(group, app_commands.Group)]}")
log.info("Combined EconomyCog added to bot with econ command group.")
print(f"EconomyCog setup complete with command group: {[cmd.name for cmd in bot.tree.get_commands() if cmd.name == 'econ']}")
print(f"Available commands: {[cmd.name for cmd in cog.econ_group.walk_commands() if isinstance(cmd, app_commands.Command)]}")

View File

@ -33,33 +33,14 @@ class GamesCog(commands.Cog, name="Games"):
# Create the main command group for this cog
self.games_group = app_commands.Group(
name="games",
name="fun",
description="Play various games with the bot or other users"
)
# Create subgroups
self.chess_group = app_commands.Group(
name="chess",
description="Chess-related commands",
parent=self.games_group
)
self.tictactoe_group = app_commands.Group(
name="tictactoe",
description="Tic-tac-toe game commands",
parent=self.games_group
)
self.dice_group = app_commands.Group(
name="dice",
description="Dice and coin games",
parent=self.games_group
)
# Register commands
self.register_commands()
# Add command groups to the bot's tree
# Add command group to the bot's tree
self.bot.tree.add_command(self.games_group)
def _array_to_fen(self, board_array: List[List[str]], turn: chess.Color) -> str:
@ -91,35 +72,35 @@ class GamesCog(commands.Cog, name="Games"):
def register_commands(self):
"""Register all commands for this cog"""
# --- Dice Group Commands ---
# --- Dice Commands ---
# Coinflip command
coinflip_command = app_commands.Command(
name="coinflip",
description="Flip a coin and get Heads or Tails",
callback=self.games_coinflip_callback,
parent=self.dice_group
parent=self.games_group
)
self.dice_group.add_command(coinflip_command)
self.games_group.add_command(coinflip_command)
# Roll command
roll_command = app_commands.Command(
name="roll",
description="Roll a dice and get a number between 1 and 6",
callback=self.games_roll_callback,
parent=self.dice_group
parent=self.games_group
)
self.dice_group.add_command(roll_command)
self.games_group.add_command(roll_command)
# Magic 8-ball command
magic8ball_command = app_commands.Command(
name="magic8ball",
description="Ask the magic 8 ball a question",
callback=self.games_magic8ball_callback,
parent=self.dice_group
parent=self.games_group
)
self.dice_group.add_command(magic8ball_command)
self.games_group.add_command(magic8ball_command)
# --- Main Games Group Commands ---
# --- RPS Commands ---
# RPS command
rps_command = app_commands.Command(
name="rps",
@ -138,6 +119,7 @@ class GamesCog(commands.Cog, name="Games"):
)
self.games_group.add_command(rpschallenge_command)
# --- Other Game Commands ---
# Guess command
guess_command = app_commands.Command(
name="guess",
@ -156,52 +138,52 @@ class GamesCog(commands.Cog, name="Games"):
)
self.games_group.add_command(hangman_command)
# --- TicTacToe Group Commands ---
# --- TicTacToe Commands ---
# TicTacToe command
tictactoe_command = app_commands.Command(
name="play",
name="tictactoe",
description="Challenge another user to a game of Tic-Tac-Toe",
callback=self.games_tictactoe_callback,
parent=self.tictactoe_group
parent=self.games_group
)
self.tictactoe_group.add_command(tictactoe_command)
self.games_group.add_command(tictactoe_command)
# TicTacToe Bot command
tictactoebot_command = app_commands.Command(
name="bot",
name="tictactoebot",
description="Play a game of Tic-Tac-Toe against the bot",
callback=self.games_tictactoebot_callback,
parent=self.tictactoe_group
parent=self.games_group
)
self.tictactoe_group.add_command(tictactoebot_command)
self.games_group.add_command(tictactoebot_command)
# --- Chess Group Commands ---
# --- Chess Commands ---
# Chess command
chess_command = app_commands.Command(
name="play",
name="chess",
description="Challenge another user to a game of chess",
callback=self.games_chess_callback,
parent=self.chess_group
parent=self.games_group
)
self.chess_group.add_command(chess_command)
self.games_group.add_command(chess_command)
# Chess Bot command
chessbot_command = app_commands.Command(
name="bot",
name="chessbot",
description="Play chess against the bot",
callback=self.games_chessbot_callback,
parent=self.chess_group
parent=self.games_group
)
self.chess_group.add_command(chessbot_command)
self.games_group.add_command(chessbot_command)
# Load Chess command
loadchess_command = app_commands.Command(
name="load",
name="loadchess",
description="Load a chess game from FEN, PGN, or array representation",
callback=self.games_loadchess_callback,
parent=self.chess_group
parent=self.games_group
)
self.chess_group.add_command(loadchess_command)
self.games_group.add_command(loadchess_command)
async def cog_unload(self):
"""Clean up resources when the cog is unloaded."""
@ -1164,5 +1146,5 @@ async def setup(bot: commands.Bot):
print("Setting up GamesCog...")
cog = GamesCog(bot)
await bot.add_cog(cog)
print(f"GamesCog setup complete with command groups: {[cmd.name for cmd in bot.tree.get_commands() if cmd.name == 'games']}")
print(f"Available subgroups: {[group.name for group in cog.games_group.walk_commands() if isinstance(group, app_commands.Group)]}")
print(f"GamesCog setup complete with command group: {[cmd.name for cmd in bot.tree.get_commands() if cmd.name == 'games']}")
print(f"Available commands: {[cmd.name for cmd in cog.games_group.walk_commands() if isinstance(cmd, app_commands.Command)]}")

View File

@ -8,29 +8,6 @@ class PingCog(commands.Cog, name="Ping"):
def __init__(self, bot):
self.bot = bot
# Create the main command group for this cog
self.ping_group = app_commands.Group(
name="ping",
description="Check the bot's response time"
)
# Register commands
self.register_commands()
# Add command group to the bot's tree
self.bot.tree.add_command(self.ping_group)
def register_commands(self):
"""Register all commands for this cog"""
# Check command
check_command = app_commands.Command(
name="check",
description="Check the bot's response time",
callback=self.ping_check_callback,
parent=self.ping_group
)
self.ping_group.add_command(check_command)
async def _ping_logic(self):
"""Core logic for the ping command."""
latency = round(self.bot.latency * 1000)
@ -43,9 +20,10 @@ class PingCog(commands.Cog, name="Ping"):
response = await self._ping_logic()
await ctx.reply(response)
# --- Slash Command Callbacks ---
async def ping_check_callback(self, interaction: discord.Interaction):
"""Callback for /ping check command"""
# --- Slash Command ---
@app_commands.command(name="ping", description="Check the bot's response time")
async def ping_slash(self, interaction: discord.Interaction):
"""Slash command for ping."""
response = await self._ping_logic()
await interaction.response.send_message(response)