Move gauntlet commands to /gauntlets; add support for opening Mario packs
This commit is contained in:
parent
c7d4824ee0
commit
871eaa2c06
@ -562,17 +562,17 @@ class Economy(commands.Cog):
|
||||
'Standard': [],
|
||||
'Premium': [],
|
||||
'Daily': [],
|
||||
'MVP': []
|
||||
'MVP': [],
|
||||
'All Star': [],
|
||||
'Mario': []
|
||||
}
|
||||
for pack in p_query['packs']:
|
||||
p_group = None
|
||||
logging.info(f'this pack type: {pack["pack_type"]["name"]}')
|
||||
if pack['pack_team'] is None and pack['pack_cardset'] is None:
|
||||
if pack['pack_type']['name'] == 'Standard':
|
||||
p_group = 'Standard'
|
||||
elif pack['pack_type']['name'] == 'Premium':
|
||||
p_group = 'Premium'
|
||||
elif pack['pack_type']['name'] == 'MVP':
|
||||
p_group = 'MVP'
|
||||
if pack['pack_type']['name'] in p_data:
|
||||
logging.info(f'adding this pack')
|
||||
p_group = pack['pack_type']['name']
|
||||
|
||||
elif pack['pack_team'] is not None:
|
||||
if pack['pack_type']['name'] == 'Standard':
|
||||
|
||||
@ -18,7 +18,7 @@ from dice import sa_fielding_roll
|
||||
from helpers import SBA_PLAYERS_ROLE_NAME, PD_PLAYERS_ROLE_NAME, random_conf_gif, SBA_SEASON, PD_SEASON, IMAGES, \
|
||||
get_team_embed, Confirm, get_pos_abbrev, SBA_COLOR, get_roster_lineups, Question, give_packs, send_to_channel, \
|
||||
get_channel, get_or_create_role, team_role, get_cal_user, get_card_embeds, ButtonOptions, get_ratings_guide, \
|
||||
get_team_by_owner
|
||||
get_team_by_owner, get_roster_sheet
|
||||
from gameplay_helpers import *
|
||||
from db_calls import db_get, db_patch, db_post, db_delete, get_team_by_abbrev
|
||||
from db_calls_gameplay import StratGame, StratPlay, StratLineup, StratManagerAi, get_sba_team, get_sba_player, \
|
||||
@ -1364,24 +1364,8 @@ class Gameplay(commands.Cog):
|
||||
)
|
||||
return
|
||||
if not team:
|
||||
try:
|
||||
await gauntlets.run_draft(interaction, main_team, this_event)
|
||||
except Exception as e:
|
||||
logging.error(f'Failed to run {event_name} draft for the {main_team["sname"]}: {e}')
|
||||
draft_team = db_get('teams', params=[('abbrev', f'Gauntlet-{main_team["abbrev"]}')])
|
||||
await gauntlets.wipe_team(draft_team, interaction, delete_runs=True)
|
||||
await interaction.channel.send(
|
||||
content=f'Shoot - it looks like we ran into an issue running the draft. I had to clear it all out '
|
||||
f'for now. I let {get_cal_user(interaction).mention} know what happened so he better '
|
||||
f'fix it quick.'
|
||||
)
|
||||
return
|
||||
|
||||
await interaction.channel.send(
|
||||
f'Good luck, champ in the making! To start playing, follow these steps:\n\n'
|
||||
f'1) Make a copy of the Team Sheet Template found in `/help-pd links`\n'
|
||||
f'2) Run `/newsheet` to link it to your Gauntlet team\n'
|
||||
f'3) Go play your first game with `/new-game gauntlet {this_event["name"]}`'
|
||||
await interaction.edit_original_response(
|
||||
content=f'I don\'t see an active run for you. You can get started with the `/gauntlets start` command!'
|
||||
)
|
||||
return
|
||||
|
||||
@ -1393,7 +1377,7 @@ class Gameplay(commands.Cog):
|
||||
)
|
||||
return
|
||||
|
||||
# Get or create Gauntlet run
|
||||
# Get Gauntlet run
|
||||
r_query = db_get(
|
||||
'gauntletruns',
|
||||
params=[('team_id', team['id']), ('gauntlet_id', this_event['id']), ('is_active', True)]
|
||||
@ -1414,7 +1398,7 @@ class Gameplay(commands.Cog):
|
||||
|
||||
await interaction.channel.send(
|
||||
f'Good luck, champ in the making! To start playing, follow these steps:\n\n'
|
||||
f'1) Update your Gauntlet lineups here: {team["gsheet"]}`\n'
|
||||
f'1) Update your Gauntlet lineups here: {get_roster_sheet(team)}`\n'
|
||||
f'2) Go play your first game with `/new-game gauntlet {this_event["name"]}`'
|
||||
)
|
||||
return
|
||||
|
||||
@ -16,7 +16,7 @@ from difflib import get_close_matches
|
||||
from discord.ext.commands import Greedy
|
||||
|
||||
import gauntlets
|
||||
from db_calls import db_get, db_post, db_patch
|
||||
from db_calls import db_get, db_post, db_patch, get_team_by_abbrev
|
||||
from helpers import PD_PLAYERS_ROLE_NAME, IMAGES, PD_SEASON, random_conf_gif, fuzzy_player_search, ALL_MLB_TEAMS, \
|
||||
fuzzy_search, get_channel, display_cards, get_card_embeds, get_team_embed, cardset_search, get_blank_team_card, \
|
||||
get_team_by_owner, get_rosters, get_roster_sheet, legal_channel, random_conf_word, embed_pagination, get_cal_user, \
|
||||
@ -729,37 +729,93 @@ class Players(commands.Cog):
|
||||
|
||||
await ctx.send(random_conf_gif())
|
||||
|
||||
@app_commands.command(name='gauntlet-run', description='View status of current Gauntlet run')
|
||||
group_gauntlet = app_commands.Group(name='gauntlets', description='Check your progress or start a new Gauntlet')
|
||||
|
||||
@group_gauntlet.command(name='status', description='View status of current Gauntlet run')
|
||||
@app_commands.describe(
|
||||
team_abbrev='To check the status of a team\'s active run, enter their abbreviation'
|
||||
)
|
||||
@app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME)
|
||||
async def gauntlet_run_command(self, interaction: discord.Interaction, team_abbrev: str = None):
|
||||
async def gauntlet_run_command(
|
||||
self, interaction: discord.Interaction, event_name: Literal['Paper Sluggers'], team_abbrev: str = None):
|
||||
await interaction.response.defer()
|
||||
|
||||
e_query = db_get('events', params=[("name", event_name), ("active", True)])
|
||||
if e_query['count'] == 0:
|
||||
await interaction.response.send_message(f'Hmm...looks like that event has ended already.')
|
||||
return
|
||||
else:
|
||||
this_event = e_query['events'][0]
|
||||
|
||||
this_run = None
|
||||
if team_abbrev:
|
||||
if 'Gauntlet-' not in team_abbrev:
|
||||
team_abbrev = f'Gauntlet-{team_abbrev}'
|
||||
t_query = db_get('teams', params=[('abbrev', team_abbrev)])
|
||||
else:
|
||||
ot_query = db_get('teams', params=[('gm_id', interaction.user.id)])
|
||||
team_abbrev = ot_query['teams'][0]['abbrev']
|
||||
t_query = db_get('teams', params=[('abbrev', f'Gauntlet-{team_abbrev}')])
|
||||
if t_query['count'] != 0:
|
||||
this_team = t_query['teams'][0]
|
||||
r_query = db_get('gauntletruns', params=[('team_id', this_team['id']), ('is_active', True)])
|
||||
|
||||
if t_query['count'] == 0:
|
||||
await interaction.response.send_message(
|
||||
f'Hmm...I see any gauntlet teams for {team_abbrev}.',
|
||||
ephemeral=True
|
||||
this_run = r_query['runs'][0]
|
||||
|
||||
await interaction.edit_original_response(
|
||||
content=None,
|
||||
embed=gauntlets.get_embed(this_run, this_event)
|
||||
)
|
||||
|
||||
@group_gauntlet.command(name='start', description='Start a new Gauntlet run')
|
||||
@app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME)
|
||||
async def gauntlet_start_command(self, interaction: discord.Interaction, event_name: Literal['Paper Sluggers']):
|
||||
await interaction.response.defer()
|
||||
main_team = get_team_by_owner(interaction.user.id)
|
||||
draft_team = get_team_by_abbrev(f'Gauntlet-{main_team["abbrev"]}')
|
||||
|
||||
e_query = db_get('events', params=[("name", event_name), ("active", True)])
|
||||
if e_query['count'] == 0:
|
||||
await interaction.response.send_message(f'Hmm...looks like that event has ended already.')
|
||||
return
|
||||
else:
|
||||
this_event = e_query['events'][0]
|
||||
|
||||
first_flag = draft_team is None
|
||||
if draft_team is not None:
|
||||
r_query = db_get(
|
||||
'gauntletruns',
|
||||
params=[('team_id', draft_team['id']), ('gauntlet_id', this_event['id']), ('is_active', True)]
|
||||
)
|
||||
|
||||
if r_query['count'] != 0:
|
||||
await interaction.edit_original_response(
|
||||
content=f'Looks like you already have a {event_name} run active! You can check it out with the '
|
||||
f'`/gauntlets status` command.'
|
||||
)
|
||||
return
|
||||
|
||||
try:
|
||||
await gauntlets.run_draft(interaction, main_team, this_event, draft_team)
|
||||
except Exception as e:
|
||||
logging.error(f'Failed to run {event_name} draft for the {main_team["sname"]}: {e}')
|
||||
draft_team = db_get('teams', params=[('abbrev', f'Gauntlet-{main_team["abbrev"]}')])
|
||||
await gauntlets.wipe_team(draft_team, interaction)
|
||||
await interaction.channel.send(
|
||||
content=f'Shoot - it looks like we ran into an issue running the draft. I had to clear it all out '
|
||||
f'for now. I let {get_cal_user(interaction).mention} know what happened so he better '
|
||||
f'fix it quick.'
|
||||
)
|
||||
return
|
||||
|
||||
team = t_query['teams'][0]
|
||||
|
||||
await interaction.response.defer()
|
||||
r_query = db_get('gauntletruns', params=[('team_id', team['id']), ('is_active', True)])
|
||||
if r_query['count'] > 0:
|
||||
this_run = r_query['runs'][0]
|
||||
await interaction.edit_original_response(
|
||||
content=None,
|
||||
embed=gauntlets.get_embed(this_run)
|
||||
if first_flag:
|
||||
await interaction.channel.send(
|
||||
f'Good luck, champ in the making! To start playing, follow these steps:\n\n'
|
||||
f'1) Make a copy of the Team Sheet Template found in `/help-pd links`\n'
|
||||
f'2) Run `/newsheet` to link it to your Gauntlet team\n'
|
||||
f'3) Go play your first game with `/new-game gauntlet {this_event["name"]}`'
|
||||
)
|
||||
else:
|
||||
await interaction.edit_original_response(content=f'I do not see any Gauntlet runs for the {team["lname"]}.')
|
||||
await interaction.channel.send(
|
||||
f'Good luck, champ in the making! Go ahead and set your lineup here and you\'ll be ready to go!\n\n'
|
||||
f'{get_roster_sheet(draft_team)}'
|
||||
)
|
||||
|
||||
# @commands.command(name='standings', aliases=['leaders', 'points', 'weekly'], help='Weekly standings')
|
||||
# async def standings_command(self, ctx, *week_or_season):
|
||||
|
||||
67
gauntlets.py
67
gauntlets.py
@ -181,7 +181,7 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event, dra
|
||||
'Replacement': 0,
|
||||
}
|
||||
round_num = 1
|
||||
counter = 1
|
||||
counter = 0
|
||||
|
||||
def get_embeds(include_links=True):
|
||||
top_embed = helpers.get_team_embed(f'{embed_title} - Round {round_num}')
|
||||
@ -217,12 +217,12 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event, dra
|
||||
for z in helpers.get_all_pos(y):
|
||||
all_str[z] += f'{name_string}\n'
|
||||
|
||||
top_embed.add_field(name=f'MVPs ({counts["MVP"]}/1)', value=all_str['MVP'], inline=False)
|
||||
top_embed.add_field(name=f'MVPs ({counts["MVP"]}/2)', value=all_str['MVP'], inline=False)
|
||||
top_embed.add_field(name=f'All-Stars ({counts["All-Star"]}/3)', value=all_str['All-Star'], inline=False)
|
||||
top_embed.add_field(name=f'Starters ({counts["Starter"]}/9)', value=all_str['Starter'], inline=False)
|
||||
top_embed.add_field(name=f'Reserves ({counts["Reserve"]}/8)', value=all_str['Reserve'], inline=False)
|
||||
top_embed.add_field(
|
||||
name=f'Replacements ({counts["Replacement"]}/5)', value=all_str['Replacement'], inline=False
|
||||
name=f'Replacements ({counts["Replacement"]}/4)', value=all_str['Replacement'], inline=False
|
||||
)
|
||||
|
||||
bot_embed.add_field(name=f'Catcher', value=all_str['C'], inline=False)
|
||||
@ -262,10 +262,14 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event, dra
|
||||
params.extend([
|
||||
('min_rarity', RARITY['Starter']), ('max_rarity', RARITY['Starter'])
|
||||
])
|
||||
elif round_num <= 10:
|
||||
elif round_num <= 9:
|
||||
params.extend([
|
||||
('min_rarity', RARITY['Reserve']), ('max_rarity', RARITY['Reserve'])
|
||||
])
|
||||
elif round_num == 10:
|
||||
params.extend([
|
||||
('min_rarity', RARITY['MVP']), ('max_rarity', RARITY['MVP']), ('pos_exc', 'RP')
|
||||
])
|
||||
elif round_num == 11:
|
||||
params.extend([
|
||||
('min_rarity', RARITY['All-Star']), ('max_rarity', RARITY['All-Star'])
|
||||
@ -390,26 +394,37 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event, dra
|
||||
)
|
||||
|
||||
|
||||
def get_embed(this_run):
|
||||
def get_embed(this_run=None, this_event=None):
|
||||
if this_run is None and this_event is None:
|
||||
raise KeyError('Must provide either a run or an event to get_embed')
|
||||
|
||||
if this_run is not None:
|
||||
this_event = this_run['gauntlet']
|
||||
|
||||
embed = helpers.image_embed(
|
||||
image_url=this_run['gauntlet']['url'],
|
||||
title=f'{this_run["gauntlet"]["name"]}',
|
||||
desc=f'{this_run["team"]["lname"]}'
|
||||
image_url=this_event['url'],
|
||||
title=f'{this_event["name"]}',
|
||||
)
|
||||
if this_run['team']['logo']:
|
||||
if this_run is not None and this_run['team']['logo']:
|
||||
embed.set_thumbnail(url=this_run['team']['logo'])
|
||||
else:
|
||||
embed.set_thumbnail(url=helpers.IMAGES['logo'])
|
||||
embed.description = this_run['team']['lname']
|
||||
|
||||
embed.add_field(name='Event Info', value=this_run['gauntlet']['short_desc'], inline=False)
|
||||
embed.add_field(name='Record', value=f'{this_run["wins"]}-{this_run["losses"]}', inline=False)
|
||||
embed.add_field(name='Event Info', value=this_event['short_desc'], inline=False)
|
||||
if this_run is not None:
|
||||
embed.add_field(name='Record', value=f'{this_run["wins"]}-{this_run["losses"]}', inline=False)
|
||||
|
||||
# TODO: make sure 10-0 is last (maybe sort by strings?); add an x for 10-0 reward if there is a loss
|
||||
r_query = db_get('gauntletrewards', params=[('gauntlet_id', this_run['gauntlet']['id'])])
|
||||
r_query = db_get('gauntletrewards', params=[('gauntlet_id', this_event['id'])])
|
||||
reward_string = ''
|
||||
for x in r_query['rewards']:
|
||||
if this_run is not None:
|
||||
if this_run['wins'] >= x['win_num'] and this_run['losses'] <= x['loss_max']:
|
||||
reward_string += '✅️ '
|
||||
elif this_run['losses'] > x['loss_max']:
|
||||
reward_string += '❌ '
|
||||
else:
|
||||
reward_string += '⬜ '
|
||||
reward_string += f'{x["win_num"]}{"-0" if x["loss_max"] == 0 else " Wins"}: '
|
||||
reward_string += '☑ ' if this_run['wins'] >= x['win_num'] else '⬜ '
|
||||
|
||||
if x['reward']['money']:
|
||||
reward_string += f' {x["reward"]["money"]}₼\n'
|
||||
elif x['reward']['player']:
|
||||
@ -419,12 +434,16 @@ def get_embed(this_run):
|
||||
if len(reward_string) > 0:
|
||||
embed.add_field(name='Rewards', value=reward_string, inline=False)
|
||||
|
||||
if this_run is not None:
|
||||
embed.add_field(name='Team Sheet', value=helpers.get_roster_sheet(this_run['team']))
|
||||
|
||||
return embed
|
||||
|
||||
|
||||
async def post_result(run_id: int, is_win: bool, this_team, bot, ctx):
|
||||
this_run = db_get('gauntletruns', object_id=run_id)
|
||||
this_event = db_get('events', object_id=this_run['gauntlet']['id'])
|
||||
main_team = db_get('teams', params=[('abbrev', f'{this_team["abbrev"].replace("Gauntlet-","")}')])['teams'][0]
|
||||
|
||||
if is_win:
|
||||
this_run = db_patch(
|
||||
@ -434,18 +453,18 @@ async def post_result(run_id: int, is_win: bool, this_team, bot, ctx):
|
||||
)
|
||||
r_query = db_get(
|
||||
'gauntletrewards',
|
||||
params=[('gauntlet_id', this_event['id']), ('wins', this_run['wins']), ('loss_max', this_run['losses'])]
|
||||
params=[('gauntlet_id', this_event['id']), ('win_num', this_run['wins']), ('loss_max', this_run['losses'])]
|
||||
)
|
||||
reward_string = ''
|
||||
for x in r_query['rewards']:
|
||||
if x['reward']['money']:
|
||||
db_post(f'teams/{this_team["id"]}/money/{x["reward"]["money"]}')
|
||||
db_post(f'teams/{main_team["id"]}/money/{x["reward"]["money"]}')
|
||||
reward_string += f'- {x["reward"]["money"]}₼\n'
|
||||
elif x['reward']['player']:
|
||||
# TODO: add give player code
|
||||
pass
|
||||
elif x['reward']['pack_type']:
|
||||
helpers.give_packs(this_team, 1, x['reward']['pack_type'])
|
||||
helpers.give_packs(main_team, 1, x['reward']['pack_type'])
|
||||
reward_string += f'- 1x {x["reward"]["pack_type"]["name"]} Pack'
|
||||
|
||||
if this_run['wins'] == 10:
|
||||
@ -458,10 +477,14 @@ async def post_result(run_id: int, is_win: bool, this_team, bot, ctx):
|
||||
f'{this_run["losses"]}!'
|
||||
)
|
||||
else:
|
||||
final_message = f'Big win there! Your {this_event["name"]} record is now **{this_run["wins"]}-' \
|
||||
f'{this_run["losses"]}**. '
|
||||
if len(reward_string) > 0:
|
||||
final_message += f"You earned the following rewards:\n{reward_string}"
|
||||
final_message += f'\n\nGo share the highlights in {get_channel(ctx, "pd-news-ticker").mention}!'
|
||||
|
||||
await ctx.send(
|
||||
content=f'Big win there! Your {this_event["name"]} record is now **{this_run["wins"]}-'
|
||||
f'{this_run["losses"]}**. Go share the highlights in '
|
||||
f'{get_channel(ctx, "pd-news-ticker").mention}!',
|
||||
content=final_message,
|
||||
embed=get_embed(this_run)
|
||||
)
|
||||
else:
|
||||
|
||||
47
helpers.py
47
helpers.py
@ -470,6 +470,12 @@ class SelectOpenPack(discord.ui.Select):
|
||||
elif 'MVP' in pack_vals:
|
||||
open_type = 'choice'
|
||||
params.append(('pack_type_id', 5))
|
||||
elif 'All Star' in pack_vals:
|
||||
open_type = 'choice'
|
||||
params.append(('pack_type_id', 6))
|
||||
elif 'Mario' in pack_vals:
|
||||
open_type = 'choice'
|
||||
params.append(('pack_type_id', 7))
|
||||
else:
|
||||
raise KeyError(f'Cannot identify pack details: {pack_vals}')
|
||||
|
||||
@ -2672,20 +2678,36 @@ async def open_choice_pack(this_pack, team: dict, context):
|
||||
pack_cover = get_pack_cover(this_pack)
|
||||
pack_type = this_pack['pack_type']['name']
|
||||
|
||||
# Get 4 MVP cards
|
||||
rarity_id = 5
|
||||
if pack_type == 'HoF':
|
||||
rarity_id = 8
|
||||
elif pack_type == 'All-Star':
|
||||
rarity_id = 3
|
||||
if pack_type == 'Mario':
|
||||
d1000 = random.randint(1, 1000)
|
||||
if d1000 > 800:
|
||||
rarity_id = 5
|
||||
elif d1000 > 550:
|
||||
rarity_id = 3
|
||||
else:
|
||||
rarity_id = 2
|
||||
pl = db_get(
|
||||
'players/random',
|
||||
params=[
|
||||
('cardset_id', 8), ('min_rarity', rarity_id), ('max_rarity', rarity_id), ('limit', 4)
|
||||
]
|
||||
)
|
||||
else:
|
||||
# Get 4 MVP cards
|
||||
rarity_id = 5
|
||||
if pack_type == 'HoF':
|
||||
rarity_id = 8
|
||||
elif pack_type == 'All Star':
|
||||
rarity_id = 3
|
||||
|
||||
pl = db_get('players/random', params=[
|
||||
('min_rarity', rarity_id), ('max_rarity', rarity_id), ('limit', 4)
|
||||
])
|
||||
|
||||
pl = db_get('players/random', params=[
|
||||
('min_rarity', rarity_id), ('max_rarity', rarity_id), ('limit', 4)
|
||||
])
|
||||
if pl['count']:
|
||||
players = pl['players']
|
||||
else:
|
||||
raise ConnectionError(f'Could not create MVP pack')
|
||||
raise ConnectionError(f'Could not create choice pack')
|
||||
|
||||
if type(context) == commands.Context:
|
||||
author = context.author
|
||||
@ -2716,7 +2738,10 @@ async def open_choice_pack(this_pack, team: dict, context):
|
||||
embed=image_embed(pack_cover, title=f'{team["lname"]}', desc=f'{pack_type} Pack - Choose 1 of 4 {pack_type}s!'),
|
||||
view=view
|
||||
)
|
||||
tmp_msg = await pack_channel.send(content=f'@here we\'ve got an MVP!')
|
||||
if rarity_id >= 5:
|
||||
tmp_msg = await pack_channel.send(content=f'@here we\'ve got an MVP!')
|
||||
else:
|
||||
tmp_msg = await pack_channel.send(content=f'We\'ve got a choice pack here!')
|
||||
|
||||
while True:
|
||||
await view.wait()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user