# Utility Commands Module # Contains miscellaneous utility and admin commands from the original players.py from discord.ext import commands from discord import app_commands import discord import random # Import specific utilities needed by this module import logging from discord.ext.commands import Greedy from api_calls import db_get, db_post from helpers import ( PD_PLAYERS_ROLE_NAME, IMAGES, get_channel, legal_channel, get_team_embed ) from helpers.search_utils import fuzzy_player_search from helpers.random_content import random_conf_gif, random_conf_word from helpers.utils import get_cal_user logger = logging.getLogger('discord_app') class UtilityCommands(commands.Cog): """Miscellaneous utility and admin commands for Paper Dynasty.""" def __init__(self, bot): self.bot = bot @commands.command(name='in', help='Get Paper Dynasty Players role') async def give_role(self, ctx, *args): """Give the user the Paper Dynasty Players role.""" await ctx.author.add_roles(discord.utils.get(ctx.guild.roles, name='Paper Dynasty Players')) await ctx.send('I got u, boo. ;)\n\nNow that you\'ve got the PD role, you can run all of the Paper Dynasty ' 'bot commands. For help, check out `/help-pd`') @commands.command(name='out', help='Remove Paper Dynasty Players role') @commands.has_any_role('Paper Dynasty Players') async def take_role(self, ctx, *args): """Remove the Paper Dynasty Players role from the user.""" await ctx.author.remove_roles(discord.utils.get(ctx.guild.roles, name='Paper Dynasty Players')) await ctx.send('Oh no! I\'m so sad to see you go! What are we going to do without you?') @commands.command(name='fuck', help='You know') @commands.has_any_role(PD_PLAYERS_ROLE_NAME) @commands.check(legal_channel) async def fuck_command(self, ctx, gm: discord.Member): """Fun command for stress relief.""" t_query = await db_get('teams', params=[('gm_id', gm.id)]) if t_query['count'] == 0: await ctx.send(f'Who?') return await ctx.send(f'{t_query["teams"][0]["sname"]} are a bunch of cuties!') @commands.command(name='c', aliases=['chaos', 'choas'], help='c, chaos, or choas') async def chaos_roll(self, ctx): """ Have the pitcher check for chaos with a runner on base. """ d_twenty = random.randint(1, 20) d_twenty_two = random.randint(1, 20) flag = None if d_twenty == 1: flag = 'wild pitch' elif d_twenty == 2: if random.randint(1, 2) == 1: flag = 'balk' else: flag = 'passed ball' if not flag: roll_message = f'Chaos roll for {ctx.author.name}\n```md\nNo Chaos```' else: roll_message = f'Chaos roll for {ctx.author.name}\n```md\nCheck {flag}```\n'\ f'{flag.title()} roll```md\n# {d_twenty_two}\nDetails: [1d20 ({d_twenty_two})]```' await ctx.send(roll_message) @commands.command(name='sba', hidden=True) async def sba_command(self, ctx, *, player_name): """Hidden search command for player lookup.""" async def get_one_player(id_or_name): """Helper function to get player data.""" try: # Try as ID first player_id = int(id_or_name) p_query = await db_get('players', params=[('player_id', player_id)]) except ValueError: # Search by name p_query = await db_get('players', params=[('name', id_or_name)]) if p_query and p_query.get('count'): return p_query['players'][0] return None player = await get_one_player(player_name) if not player: # Try fuzzy search fuzzy_results = fuzzy_player_search(player_name) if fuzzy_results: player = await get_one_player(fuzzy_results[0]) if not player: await ctx.send(f'Could not find player: {player_name}') return # Simplified to match original - just logs player data logger.debug(f'this_player: {player}') @commands.command(name='build_list', help='Mod: Synchronize fuzzy player list') async def build_player_command(self, ctx): """Manual command to rebuild player search list.""" # Find the PlayerLookup cog and trigger its build_list method player_lookup_cog = self.bot.get_cog('PlayerLookup') if player_lookup_cog and hasattr(player_lookup_cog, 'build_player_list'): player_lookup_cog.build_player_list.stop() player_lookup_cog.build_player_list.start() await ctx.send(f'Just kicked off the build...') import asyncio await asyncio.sleep(10) await ctx.send(f'There are now {len(player_lookup_cog.player_list)} player names in the fuzzy search list.') else: await ctx.send('❌ Could not find PlayerLookup cog or build_player_list method') @commands.hybrid_command(name='random', help='Check out a random card') @commands.has_any_role(PD_PLAYERS_ROLE_NAME) @commands.check(legal_channel) async def random_card_command(self, ctx: commands.Context): """Display a random player card.""" p_query = await db_get('players/random', params=[('limit', 1)]) if not p_query or not p_query.get('count'): await ctx.send('Could not find any random players') return this_player = p_query['players'][0] # Use blank team card structure like original from helpers import get_card_embeds, PD_SEASON this_embed = await get_card_embeds( {'player': this_player, 'team': {'lname': 'Paper Dynasty', 'logo': IMAGES['logo'], 'season': PD_SEASON}} ) await ctx.send(content=None, embeds=this_embed) @commands.hybrid_command(name='ai-teams', help='Get list of AI teams and abbreviations') @commands.has_any_role(PD_PLAYERS_ROLE_NAME) @commands.check(legal_channel) async def ai_teams_command(self, ctx: commands.Context): """Display list of AI teams available for solo play.""" embed = get_team_embed(f'Paper Dynasty AI Teams') embed.description = 'Teams Available for Solo Play' embed.add_field( name='AL East', value=f'BAL - Baltimore Orioles\nBOS - Boston Red Sox\nNYY - New York Yankees\nTBR - Tampa Bay Rays\nTOR - ' f'Toronto Blue Jays' ) embed.add_field( name='AL Central', value=f'CLE - Cleveland Guardians\nCHW - Chicago White Sox\nDET - Detroit Tigers\nKCR - Kansas City ' f'Royals\nMIN - Minnesota Twins' ) embed.add_field( name='AL West', value=f'HOU - Houston Astros\nLAA - Los Angeles Angels\nOAK - Oakland Athletics\nSEA - Seattle Mariners' f'\nTEX - Texas Rangers' ) embed.add_field( name='NL East', value=f'ATL - Atlanta Braves\nMIA - Miami Marlins\nNYM - New York Mets\nPHI - Philadelphia Phillies\n' f'WSN - Washington Nationals' ) embed.add_field( name='NL Central', value=f'CHC - Chicago Cubs\nCIN - Cincinnati Reds\nMIL - Milwaukee Brewers\nPIT - Pittsburgh Pirates\n' f'STL - St Louis Cardinals' ) embed.add_field( name='NL West', value=f'ARI - Arizona Diamondbacks\nCOL - Colorado Rockies\nLAD - Los Angeles Dodgers\nSDP - San Diego ' f'Padres\nSFG - San Francisco Giants' ) await ctx.send(content=None, embed=embed) async def setup(bot): """Setup function for the UtilityCommands cog.""" await bot.add_cog(UtilityCommands(bot))