Added /update-player command

This commit is contained in:
Cal Corum 2023-10-22 14:00:06 -05:00
parent b39fb13a6a
commit 5668b7f04e
2 changed files with 161 additions and 38 deletions

View File

@ -413,6 +413,52 @@ class Players(commands.Cog):
else:
await interaction.edit_original_response(content=None, embed=all_embeds[0])
@app_commands.command(name='update-player', description='Update a player\'s card to a specific MLB team')
@app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME)
async def update_player_team(self, interaction: discord.Interaction, player_id: int):
owner_team = await get_team_by_owner(interaction.user.id)
if not owner_team:
await interaction.response.send_message(
'Thank you for offering to help - if you sign up for a team with /newteam I can let you post updates.',
ephemeral=True
)
return
if interaction.channel.name in ['paper-dynasty-chat', 'pd-news-ticker']:
await interaction.response.send_message(
f'Slide on down to #pd-bot-hole to run updates - thanks!',
ephemeral=True
)
await interaction.response.defer()
this_player = await db_get('players', object_id=player_id)
if not this_player:
await interaction.response.send_message(f'No clue who that is.')
return
embed = await get_card_embeds(get_blank_team_card(this_player))
await interaction.edit_original_response(content=None, embed=embed[0])
view = helpers.Confirm(responders=[interaction.user])
question = await interaction.channel.send(
content='Is this the player you want to update?',
view=view
)
await view.wait()
if not view.value:
await question.edit(content='Okay, we\'ll leave it be.', view=None)
return
else:
await question.delete()
view = SelectView([
helpers.SelectUpdatePlayerTeam('AL', this_player, owner_team, self.bot),
helpers.SelectUpdatePlayerTeam('NL', this_player, owner_team, self.bot)
])
await interaction.channel.send(content=None, view=view)
@app_commands.command(name='record', description='Display team record against AI teams')
@app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME)
async def record_slash_command(

View File

@ -1022,6 +1022,83 @@ class SelectBuyPacksTeam(discord.ui.Select):
)
class SelectUpdatePlayerTeam(discord.ui.Select):
def __init__(self, which: Literal['AL', 'NL'], player: dict, reporting_team: dict, bot):
self.bot = bot
self.which = which
self.player = player
self.reporting_team = reporting_team
if which == 'AL':
options = [
discord.SelectOption(label='Baltimore Orioles'),
discord.SelectOption(label='Boston Red Sox'),
discord.SelectOption(label='Chicago White Sox'),
discord.SelectOption(label='Cleveland Guardians'),
discord.SelectOption(label='Detroit Tigers'),
discord.SelectOption(label='Houston Astros'),
discord.SelectOption(label='Kansas City Royals'),
discord.SelectOption(label='Los Angeles Angels'),
discord.SelectOption(label='Minnesota Twins'),
discord.SelectOption(label='New York Yankees'),
discord.SelectOption(label='Oakland Athletics'),
discord.SelectOption(label='Seattle Mariners'),
discord.SelectOption(label='Tampa Bay Rays'),
discord.SelectOption(label='Texas Rangers'),
discord.SelectOption(label='Toronto Blue Jays')
]
else:
options = [
discord.SelectOption(label='Arizona Diamondbacks'),
discord.SelectOption(label='Atlanta Braves'),
discord.SelectOption(label='Chicago Cubs'),
discord.SelectOption(label='Cincinnati Reds'),
discord.SelectOption(label='Colorado Rockies'),
discord.SelectOption(label='Los Angeles Dodgers'),
discord.SelectOption(label='Miami Marlins'),
discord.SelectOption(label='Milwaukee Brewers'),
discord.SelectOption(label='New York Mets'),
discord.SelectOption(label='Philadelphia Phillies'),
discord.SelectOption(label='Pittsburgh Pirates'),
discord.SelectOption(label='San Diego Padres'),
discord.SelectOption(label='San Francisco Giants'),
discord.SelectOption(label='St. Louis Cardinals'),
discord.SelectOption(label='Washington Nationals')
]
super().__init__(placeholder=f'Select an {which} team', options=options)
async def callback(self, interaction: discord.Interaction):
view = Confirm(responders=[interaction.user], timeout=15)
await interaction.response.edit_message(
content=f'Should I update **{player_desc(self.player)}**\'s team to the **{self.values[0]}**?',
view=None
)
question = await interaction.channel.send(
content=None,
view=view
)
await view.wait()
if not view.value:
await question.edit(
content='That didnt\'t sound right to me, either. Let\'s not touch that.',
view=None
)
return
else:
await question.delete()
await db_patch('players', object_id=self.player['player_id'], params=[
('mlbclub', self.values[0]), ('franchise', self.values[0])
])
await db_post(f'teams/{self.reporting_team["id"]}/money/25')
await send_to_channel(
self.bot, 'pd-news-ticker',
content=f'{interaction.user.name} just updated **{player_desc(self.player)}**\'s team to the '
f'**{self.values[0]}**'
)
await interaction.channel.send(f'All done!')
class SelectView(discord.ui.View):
def __init__(self, select_objects: [discord.ui.Select], timeout: float = 300.0):
super().__init__(timeout=timeout)
@ -1527,9 +1604,9 @@ async def get_card_embeds(card, include_stats=False) -> list:
embed.set_author(name=card['team']['lname'], url=IMAGES['logo'], icon_url=card['team']['logo'])
embed.set_footer(text=f'Paper Dynasty Season {card["team"]["season"]}', icon_url=IMAGES['logo'])
if include_stats:
b_query = await db_get('plays/batting', params=[('player_id', card['player']['player_id'])])
p_query = await db_get('plays/pitching', params=[('player_id', card['player']['player_id'])])
# if include_stats:
# b_query = await db_get('plays/batting', params=[('player_id', card['player']['player_id'])])
# p_query = await db_get('plays/pitching', params=[('player_id', card['player']['player_id'])])
# embed.add_field(
# name='Cardset',
@ -1578,35 +1655,35 @@ async def get_card_embeds(card, include_stats=False) -> list:
else:
embed.set_thumbnail(url=IMAGES['logo'])
if include_stats:
if b_query['count'] > 0:
b = b_query['stats'][0]
batting_string = f'```\n' \
f' AVG OBP SLG\n' \
f' {b["avg"]:.3f} {b["obp"]:.3f} {b["slg"]:.3f}\n``````\n' \
f' OPS wOBA\n' \
f' {b["ops"]:.3f} {b["woba"]:.3f}\n``````\n' \
f' PA H RBI 2B 3B HR SB\n' \
f'{b["pa"]: >3} {b["hit"]: ^3} {b["rbi"]: ^3} {b["double"]: >2} {b["triple"]: >2} ' \
f'{b["hr"]: >2} {b["sb"]: >2}```\n'
embed.add_field(name='Batting Stats', value=batting_string, inline=False)
if p_query['count'] > 0:
p = p_query['stats'][0]
ip_whole = math.floor(p['outs'] / 3)
ip_denom = p['outs'] % 3
ips = ip_whole + (ip_denom * 0.1)
kpbb = f'{p["k/bb"]:.1f}'
era = f'{p["era"]:.2f}'
whip = f'{p["whip"]:.2f}'
pitching_string = f'```\n' \
f' W-L SV ERA WHIP\n' \
f'{p["win"]: >2}-{p["loss"]: <2} {p["save"]: >2} {era: >5} {whip: >4}\n``````\n' \
f' IP SO K/BB\n' \
f'{ips: >5} {p["so"]: ^3} {kpbb: ^4}\n```'
embed.add_field(name='Pitching Stats', value=pitching_string, inline=False)
# if include_stats:
# if b_query['count'] > 0:
# b = b_query['stats'][0]
# batting_string = f'```\n' \
# f' AVG OBP SLG\n' \
# f' {b["avg"]:.3f} {b["obp"]:.3f} {b["slg"]:.3f}\n``````\n' \
# f' OPS wOBA\n' \
# f' {b["ops"]:.3f} {b["woba"]:.3f}\n``````\n' \
# f' PA H RBI 2B 3B HR SB\n' \
# f'{b["pa"]: >3} {b["hit"]: ^3} {b["rbi"]: ^3} {b["double"]: >2} {b["triple"]: >2} ' \
# f'{b["hr"]: >2} {b["sb"]: >2}```\n'
# embed.add_field(name='Batting Stats', value=batting_string, inline=False)
# if p_query['count'] > 0:
# p = p_query['stats'][0]
#
# ip_whole = math.floor(p['outs'] / 3)
# ip_denom = p['outs'] % 3
# ips = ip_whole + (ip_denom * 0.1)
#
# kpbb = f'{p["k/bb"]:.1f}'
# era = f'{p["era"]:.2f}'
# whip = f'{p["whip"]:.2f}'
#
# pitching_string = f'```\n' \
# f' W-L SV ERA WHIP\n' \
# f'{p["win"]: >2}-{p["loss"]: <2} {p["save"]: >2} {era: >5} {whip: >4}\n``````\n' \
# f' IP SO K/BB\n' \
# f'{ips: >5} {p["so"]: ^3} {kpbb: ^4}\n```'
# embed.add_field(name='Pitching Stats', value=pitching_string, inline=False)
if not card['player']['image2']:
return [embed]
@ -3017,18 +3094,18 @@ def player_desc(this_player) -> str:
def player_pcard(this_player):
if 'pitching' in this_player['image']:
if this_player['image'] is not None and 'pitching' in this_player['image']:
return this_player['image']
elif 'pitching' in this_player['image2']:
elif this_player['image2'] is not None and 'pitching' in this_player['image2']:
return this_player['image2']
else:
return None
return this_player['image']
def player_bcard(this_player):
if 'batting' in this_player['image']:
if this_player['image'] is not None and 'batting' in this_player['image']:
return this_player['image']
elif 'batting' in this_player['image2']:
elif this_player['image2'] is not None and 'batting' in this_player['image2']:
return this_player['image2']
else:
return None
return this_player['image']