Functional draft
This commit is contained in:
parent
07c0a63d8f
commit
f9e222d2f1
@ -259,24 +259,29 @@ class Admins(commands.Cog):
|
|||||||
e_string = "\n- ".join(errors)
|
e_string = "\n- ".join(errors)
|
||||||
await ctx.send(f'I encountered the following errors:\n\n{e_string}')
|
await ctx.send(f'I encountered the following errors:\n\n{e_string}')
|
||||||
|
|
||||||
# @app_commands.command(name='tc', description='Mod: Test choice function')
|
@app_commands.command(name='tc', description='Mod: Test command')
|
||||||
# async def test_choices_command(self, interaction: discord.Interaction):
|
async def test_choices_command(self, interaction: discord.Interaction):
|
||||||
# await interaction.response.send_message(f'Let\'s test this function!')
|
# await interaction.response.send_message(f'Let\'s test this function!')
|
||||||
# pl = db_get('players/random', params=[
|
# pl = db_get('players/random', params=[
|
||||||
# ('min_rarity', 5), ('max_rarity', 5), ('limit', 4)
|
# ('min_rarity', 5), ('max_rarity', 5), ('limit', 4)
|
||||||
# ])
|
# ])
|
||||||
# if pl['count']:
|
# if pl['count']:
|
||||||
# players = pl['players']
|
# players = pl['players']
|
||||||
# else:
|
# else:
|
||||||
# raise ConnectionError(f'Could not create MVP pack')
|
# raise ConnectionError(f'Could not create MVP pack')
|
||||||
#
|
#
|
||||||
# def p_callback(player):
|
# def p_callback(player):
|
||||||
# db_get('players', object_id=player['player_id'])
|
# db_get('players', object_id=player['player_id'])
|
||||||
#
|
#
|
||||||
# choice = await get_choice_from_cards(
|
# choice = await get_choice_from_cards(
|
||||||
# interaction, players, callback=p_callback, temp_message='Hello!', conf_message='All done - great choice!'
|
# interaction, players, callback=p_callback, temp_message='Hello!', conf_message='All done - great choice!'
|
||||||
# )
|
# )
|
||||||
# await interaction.edit_original_response(content=f'The choice was: {choice}')
|
# await interaction.edit_original_response(content=f'The choice was: {choice}')
|
||||||
|
|
||||||
|
pass
|
||||||
|
# Delete cards
|
||||||
|
# Delete packs
|
||||||
|
# Delete team
|
||||||
|
|
||||||
# @commands.command(name='refresh')
|
# @commands.command(name='refresh')
|
||||||
# @commands.is_owner()
|
# @commands.is_owner()
|
||||||
|
|||||||
@ -1398,12 +1398,13 @@ class Economy(commands.Cog):
|
|||||||
@commands.has_any_role(PD_PLAYERS)
|
@commands.has_any_role(PD_PLAYERS)
|
||||||
async def share_sheet_command(
|
async def share_sheet_command(
|
||||||
self, ctx, google_sheet_url: str, team_abbrev: Optional[str], copy_rosters: Optional[bool] = True):
|
self, ctx, google_sheet_url: str, team_abbrev: Optional[str], copy_rosters: Optional[bool] = True):
|
||||||
team = get_team_by_owner(ctx.author.id)
|
owner_team = get_team_by_owner(ctx.author.id)
|
||||||
if not team:
|
if not owner_team:
|
||||||
await ctx.send(f'I don\'t see a team for you, yet. You can sign up with the `/newteam` command!')
|
await ctx.send(f'I don\'t see a team for you, yet. You can sign up with the `/newteam` command!')
|
||||||
return
|
return
|
||||||
|
team = owner_team
|
||||||
|
|
||||||
if team_abbrev and team_abbrev != team['abbrev']:
|
if team_abbrev and team_abbrev != owner_team['abbrev']:
|
||||||
if ctx.author.id != 258104532423147520:
|
if ctx.author.id != 258104532423147520:
|
||||||
await ctx.send(f'You can only update the team sheet for your own team, you goober.')
|
await ctx.send(f'You can only update the team sheet for your own team, you goober.')
|
||||||
return
|
return
|
||||||
@ -1415,6 +1416,21 @@ class Economy(commands.Cog):
|
|||||||
await ctx.send(f'Ope, looks like that is the template sheet. Would you please make a copy and then share?')
|
await ctx.send(f'Ope, looks like that is the template sheet. Would you please make a copy and then share?')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
gauntlet_team = get_team_by_abbrev(f'Gauntlet-{owner_team["abbrev"]}')
|
||||||
|
if gauntlet_team:
|
||||||
|
view = ButtonOptions([ctx.author], timeout=30, labels=['Main Team', 'Gauntlet Team', None, None, None])
|
||||||
|
question = await ctx.send(f'Is this sheet for your main PD team or your active Gauntlet team?', view=view)
|
||||||
|
await view.wait()
|
||||||
|
|
||||||
|
if not view.value:
|
||||||
|
await question.edit(
|
||||||
|
content=f'Okay you keep thinking on it and get back to me when you\'re ready.', view=None
|
||||||
|
)
|
||||||
|
return
|
||||||
|
elif view.value == 'Gauntlet Team':
|
||||||
|
await question.delete()
|
||||||
|
team = gauntlet_team
|
||||||
|
|
||||||
sheets = get_sheets(self.bot)
|
sheets = get_sheets(self.bot)
|
||||||
response = await ctx.send(f'I\'ll go grab that sheet...')
|
response = await ctx.send(f'I\'ll go grab that sheet...')
|
||||||
try:
|
try:
|
||||||
@ -1428,10 +1444,11 @@ class Economy(commands.Cog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
team_data = new_sheet.worksheet_by_title('Team Data')
|
team_data = new_sheet.worksheet_by_title('Team Data')
|
||||||
team_data.update_values(
|
if not gauntlet_team or owner_team != gauntlet_team:
|
||||||
crange='B1:B2',
|
team_data.update_values(
|
||||||
values=[[f'{team["id"]}'], [f'\'{team_hash(team)}']]
|
crange='B1:B2',
|
||||||
)
|
values=[[f'{team["id"]}'], [f'\'{team_hash(team)}']]
|
||||||
|
)
|
||||||
|
|
||||||
if copy_rosters and team['gsheet'] != 'None':
|
if copy_rosters and team['gsheet'] != 'None':
|
||||||
old_sheet = sheets.open_by_key(team['gsheet'])
|
old_sheet = sheets.open_by_key(team['gsheet'])
|
||||||
@ -1476,8 +1493,13 @@ class Economy(commands.Cog):
|
|||||||
team = db_patch('teams', object_id=team['id'], params=[('gsheet', new_sheet.id)])
|
team = db_patch('teams', object_id=team['id'], params=[('gsheet', new_sheet.id)])
|
||||||
await refresh_sheet(team, self.bot, sheets)
|
await refresh_sheet(team, self.bot, sheets)
|
||||||
|
|
||||||
await response.edit(content=f'Alright, your sheet is linked to your team - good luck this season!\n\n'
|
conf_message = f'Alright, your sheet is linked to your team - good luck'
|
||||||
f'{HELP_SHEET_SCRIPTS}')
|
if owner_team == team:
|
||||||
|
conf_message += 'this season!'
|
||||||
|
else:
|
||||||
|
conf_message += 'on your run!'
|
||||||
|
conf_message += f'\n\n{HELP_SHEET_SCRIPTS}'
|
||||||
|
await response.edit(content=f'{conf_message}')
|
||||||
|
|
||||||
@commands.hybrid_command(name='refresh', help='Refresh team data in Sheets')
|
@commands.hybrid_command(name='refresh', help='Refresh team data in Sheets')
|
||||||
@commands.has_any_role(PD_PLAYERS)
|
@commands.has_any_role(PD_PLAYERS)
|
||||||
|
|||||||
@ -1370,10 +1370,17 @@ class Gameplay(commands.Cog):
|
|||||||
draft_team = db_get('teams', params=[('abbrev', f'Gauntlet-{main_team["abbrev"]}')])
|
draft_team = db_get('teams', params=[('abbrev', f'Gauntlet-{main_team["abbrev"]}')])
|
||||||
for x in draft_team['teams']:
|
for x in draft_team['teams']:
|
||||||
db_delete('teams', object_id=x['id'])
|
db_delete('teams', object_id=x['id'])
|
||||||
|
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.'
|
||||||
|
)
|
||||||
|
|
||||||
await interaction.channel.send(
|
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'Good luck, champ in the making! To start playing, follow these steps:\n\n'
|
||||||
f'for now. I let {get_cal_user(interaction).mention} know what happened so he better '
|
f'1) Make a copy of the Team Sheet Template found in `/help-pd links`\n'
|
||||||
f'fix it quick.'
|
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"]}`'
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -1388,10 +1395,9 @@ class Gameplay(commands.Cog):
|
|||||||
# Get or create Gauntlet run
|
# Get or create Gauntlet run
|
||||||
r_query = db_get(
|
r_query = db_get(
|
||||||
'gauntletruns',
|
'gauntletruns',
|
||||||
params=[('team_id', team['id']), ('gauntled_id', this_event['id']), ('is_active', True)]
|
params=[('team_id', main_team['id']), ('gauntlet_id', this_event['id']), ('is_active', True)]
|
||||||
)
|
)
|
||||||
|
|
||||||
# If a new run, run draft and return; make sure player has time for a game after draft by running /new-game
|
|
||||||
if r_query['count'] == 0:
|
if r_query['count'] == 0:
|
||||||
raise KeyError(f'I found your Gauntlet team, but no run data')
|
raise KeyError(f'I found your Gauntlet team, but no run data')
|
||||||
else:
|
else:
|
||||||
|
|||||||
99
gauntlets.py
99
gauntlets.py
@ -83,8 +83,8 @@ def get_starting_pitcher(this_team, this_game, this_event):
|
|||||||
|
|
||||||
async def run_draft(interaction: discord.Interaction, main_team, this_event):
|
async def run_draft(interaction: discord.Interaction, main_team, this_event):
|
||||||
if this_event['id'] == 1:
|
if this_event['id'] == 1:
|
||||||
draft_embed = helpers.get_team_embed(f'{this_event["name"]}')
|
embed_title = f'{main_team["lname"]} - {this_event["name"]} Draft'
|
||||||
draft_embed.description = f'{main_team["lname"]} - Team Draft - Round 1'
|
embed_description = f'{this_event["name"]}'
|
||||||
base_params = ai_manager.MAJOR_CARDSET_PARAMS
|
base_params = ai_manager.MAJOR_CARDSET_PARAMS
|
||||||
base_params.append(('limit', 8))
|
base_params.append(('limit', 8))
|
||||||
else:
|
else:
|
||||||
@ -132,13 +132,67 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event):
|
|||||||
round_num = 1
|
round_num = 1
|
||||||
counter = 1
|
counter = 1
|
||||||
|
|
||||||
if this_event['id'] == 1:
|
def get_embeds():
|
||||||
while round_num <= 3 and counter < 50:
|
top_embed = helpers.get_team_embed(f'{embed_title} - Round {round_num}')
|
||||||
counter += 1
|
top_embed.description = f'Rarity Counts'
|
||||||
|
bot_embed = helpers.get_team_embed(f'{embed_title} - Round {round_num}')
|
||||||
|
bot_embed.description = f'Current Roster'
|
||||||
|
all_str = {
|
||||||
|
'MVP': '',
|
||||||
|
'All-Star': '',
|
||||||
|
'Starter': '',
|
||||||
|
'Reserve': '',
|
||||||
|
'Replacement': '',
|
||||||
|
'C': '',
|
||||||
|
'1B': '',
|
||||||
|
'2B': '',
|
||||||
|
'3B': '',
|
||||||
|
'SS': '',
|
||||||
|
'LF': '',
|
||||||
|
'CF': '',
|
||||||
|
'RF': '',
|
||||||
|
'DH': '',
|
||||||
|
'SP': '',
|
||||||
|
'RP': '',
|
||||||
|
'CP': ''
|
||||||
|
}
|
||||||
|
|
||||||
await interaction.edit_original_response(
|
for y in all_players:
|
||||||
content=f'**Round {round_num}**\n\n__Draft Picks__\n{p_names}'
|
all_str[y['rarity']['name']] += f'[{y["description"]}]({y["image"]})\n'
|
||||||
)
|
for z in helpers.get_all_pos(y):
|
||||||
|
all_str[z] += f'[{y["description"]}]({y["image"]})\n'
|
||||||
|
|
||||||
|
top_embed.add_field(name=f'MVPs ({counts["MVP"]}/1)', 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
|
||||||
|
)
|
||||||
|
|
||||||
|
bot_embed.add_field(name=f'Catcher', value=all_str['C'], inline=False)
|
||||||
|
bot_embed.add_field(name=f'First Base', value=all_str['1B'], inline=False)
|
||||||
|
bot_embed.add_field(name=f'Second Base', value=all_str['2B'], inline=False)
|
||||||
|
bot_embed.add_field(name=f'Third Base', value=all_str['3B'], inline=False)
|
||||||
|
bot_embed.add_field(name=f'Shortstop', value=all_str['SS'], inline=False)
|
||||||
|
bot_embed.add_field(name=f'Left Field', value=all_str['LF'], inline=False)
|
||||||
|
bot_embed.add_field(name=f'Center Field', value=all_str['CF'], inline=False)
|
||||||
|
bot_embed.add_field(name=f'Right Field', value=all_str['RF'], inline=False)
|
||||||
|
bot_embed.add_field(name=f'Designated Hitter', value=all_str['DH'], inline=False)
|
||||||
|
bot_embed.add_field(name=f'Starting Pitcher', value=all_str['SP'], inline=False)
|
||||||
|
bot_embed.add_field(name=f'Relief Pitcher', value=all_str['RP'], inline=False)
|
||||||
|
bot_embed.add_field(name=f'Closing Pitcher', value=all_str['CP'], inline=False)
|
||||||
|
|
||||||
|
return [top_embed, bot_embed]
|
||||||
|
|
||||||
|
await interaction.edit_original_response(
|
||||||
|
content=None,
|
||||||
|
embeds=get_embeds()
|
||||||
|
)
|
||||||
|
|
||||||
|
if this_event['id'] == 1:
|
||||||
|
while round_num <= 26 and counter < 50:
|
||||||
|
counter += 1
|
||||||
# Set params based on current round
|
# Set params based on current round
|
||||||
params = copy.deepcopy(base_params)
|
params = copy.deepcopy(base_params)
|
||||||
if round_num == 1:
|
if round_num == 1:
|
||||||
@ -192,12 +246,15 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event):
|
|||||||
|
|
||||||
# Any positional adjustments can be added as params here
|
# Any positional adjustments can be added as params here
|
||||||
for x in ['C', '1B', '2B', '3B', 'SS', 'LF', 'CF', 'RF']:
|
for x in ['C', '1B', '2B', '3B', 'SS', 'LF', 'CF', 'RF']:
|
||||||
if counts[x] > 2:
|
if counts[x] > 2 and 0 in [
|
||||||
logging.info(f'run_draft pos_check - {x} count up to {counts[x]}')
|
counts['C'], counts['1B'], counts['2B'], counts['3B'], counts['SS'], counts['LF'],
|
||||||
if 0 in [counts['C'], counts['1B'], counts['2B'], counts['3B'], counts['SS'], counts['LF'],
|
counts['CF'], counts['RF']]:
|
||||||
counts['CF'], counts['RF']]:
|
logging.info(f'0 exists in other positions; excluding {x}')
|
||||||
logging.info(f'0 exists in other positions; excluding {x}')
|
params.append(('pos_exc', x))
|
||||||
params.append(('pos_exc', x))
|
elif counts[x] > 3:
|
||||||
|
params.append(('pos_exc', x))
|
||||||
|
if round_num > 20 and counts[x] < 2:
|
||||||
|
params.append(('pos_inc', x))
|
||||||
|
|
||||||
if counts['RP'] > 8:
|
if counts['RP'] > 8:
|
||||||
params.append(('pos_exc', 'RP'))
|
params.append(('pos_exc', 'RP'))
|
||||||
@ -219,7 +276,7 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event):
|
|||||||
test_player_list = ''
|
test_player_list = ''
|
||||||
for x in p_query['players']:
|
for x in p_query['players']:
|
||||||
test_player_list += f'{x["rarity"]["name"]} - {x["description"]} - {helpers.get_all_pos(x)}\n'
|
test_player_list += f'{x["rarity"]["name"]} - {x["description"]} - {helpers.get_all_pos(x)}\n'
|
||||||
await interaction.channel.send(f'The Round {round_num} players drawn are:\n\n{test_player_list}')
|
# await interaction.channel.send(f'The Round {round_num} players drawn are:\n\n{test_player_list}')
|
||||||
|
|
||||||
# Collect 4 cards with no repeat player names
|
# Collect 4 cards with no repeat player names
|
||||||
this_batch = []
|
this_batch = []
|
||||||
@ -230,24 +287,26 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event):
|
|||||||
break
|
break
|
||||||
|
|
||||||
# Present choices and capture selection
|
# Present choices and capture selection
|
||||||
p_choice = await helpers.get_choice_from_cards(interaction, this_batch)
|
p_choice = await helpers.get_choice_from_cards(interaction, this_batch, delete_message=True)
|
||||||
|
|
||||||
# Add player to list and update counts
|
# Add player to list and update counts
|
||||||
p_names.append(p_choice['p_name'])
|
p_names.append(p_choice['p_name'])
|
||||||
|
counts[p_choice['rarity']['name']] += 1
|
||||||
all_players.append(p_choice)
|
all_players.append(p_choice)
|
||||||
for x in helpers.get_all_pos(p_choice):
|
for x in helpers.get_all_pos(p_choice):
|
||||||
if x in counts:
|
if x in counts:
|
||||||
counts[x] += 1
|
counts[x] += 1
|
||||||
|
|
||||||
# Update roster embed
|
# Update roster embed
|
||||||
|
await interaction.edit_original_response(
|
||||||
|
content=None,
|
||||||
|
embeds=get_embeds()
|
||||||
|
)
|
||||||
round_num += 1
|
round_num += 1
|
||||||
else:
|
else:
|
||||||
logging.error(f'run_draft - No draft logic for Event ID {this_event["id"]}')
|
logging.error(f'run_draft - No draft logic for Event ID {this_event["id"]}')
|
||||||
raise KeyError(f'Draft data not found for Gauntlet {this_event["id"]}')
|
raise KeyError(f'Draft data not found for Gauntlet {this_event["id"]}')
|
||||||
|
|
||||||
raise EnvironmentError(f'End test run')
|
|
||||||
|
|
||||||
# Create team google sheet
|
|
||||||
this_pack = db_post(
|
this_pack = db_post(
|
||||||
'packs/one',
|
'packs/one',
|
||||||
payload={
|
payload={
|
||||||
@ -265,7 +324,7 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event):
|
|||||||
db_post(
|
db_post(
|
||||||
'gauntletruns',
|
'gauntletruns',
|
||||||
payload={
|
payload={
|
||||||
'team_id': draft_team['id'],
|
'team_id': main_team['id'],
|
||||||
'gauntlet_id': this_event['id']
|
'gauntlet_id': this_event['id']
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@ -2574,7 +2574,7 @@ async def open_st_pr_packs(all_packs: list, team: dict, context):
|
|||||||
async def get_choice_from_cards(
|
async def get_choice_from_cards(
|
||||||
interaction: discord.Interaction, all_players: list = None, cover_title: str = None,
|
interaction: discord.Interaction, all_players: list = None, cover_title: str = None,
|
||||||
cover_desc: str = None, cover_image_url: str = None, callback=None, temp_message: str = None,
|
cover_desc: str = None, cover_image_url: str = None, callback=None, temp_message: str = None,
|
||||||
conf_message: str = None):
|
conf_message: str = None, delete_message: bool = False):
|
||||||
# Display them with pagination, prev/next/select
|
# Display them with pagination, prev/next/select
|
||||||
card_embeds = [
|
card_embeds = [
|
||||||
await get_card_embeds(
|
await get_card_embeds(
|
||||||
@ -2662,6 +2662,8 @@ async def get_choice_from_cards(
|
|||||||
|
|
||||||
await msg.edit(content=None, embeds=card_embeds[page_num - 1], view=view)
|
await msg.edit(content=None, embeds=card_embeds[page_num - 1], view=view)
|
||||||
|
|
||||||
|
if delete_message:
|
||||||
|
await msg.delete()
|
||||||
return all_players[page_num - 1]
|
return all_players[page_num - 1]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user