Merge pull request #1 from calcorum/paperdex-to-selectview
Paperdex to selectview
This commit is contained in:
commit
25b9669c17
@ -34,7 +34,7 @@ class Gameplay(commands.Cog):
|
||||
self.pitcher_ratings = None
|
||||
self.live_scoreboard.start()
|
||||
|
||||
@tasks.loop(minutes=1)
|
||||
@tasks.loop(minutes=5)
|
||||
async def live_scoreboard(self):
|
||||
guild = self.bot.get_guild(int(os.environ.get('GUILD_ID')))
|
||||
if not guild:
|
||||
|
||||
184
cogs/players.py
184
cogs/players.py
@ -18,7 +18,7 @@ from db_calls import db_get, db_post, db_patch
|
||||
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, \
|
||||
team_summary_embed
|
||||
team_summary_embed, SelectView, SelectPaperdexCardset, SelectPaperdexTeam
|
||||
from typing import Optional, Literal
|
||||
|
||||
# date = f'{datetime.datetime.now().year}-{datetime.datetime.now().month}-{datetime.datetime.now().day}'
|
||||
@ -540,164 +540,45 @@ class Players(commands.Cog):
|
||||
)
|
||||
await ctx.send(content=None, embeds=this_embed)
|
||||
|
||||
@commands.hybrid_group(name='paperdex', help='Check your collection counts')
|
||||
group_paperdex = app_commands.Group(name='paperdex', description='Check your collection counts')
|
||||
|
||||
@group_paperdex.command(name='cardset', description='Check your collection of a specific cardset')
|
||||
@commands.has_any_role(PD_PLAYERS_ROLE_NAME)
|
||||
@commands.check(legal_channel)
|
||||
async def paperdex_command(self, ctx: commands.Context):
|
||||
if ctx.invoked_subcommand is None:
|
||||
await ctx.send(f'The available dex commands are: `cardset`')
|
||||
|
||||
@paperdex_command.command(name='cardset', help='Check your collection of a specific cardset')
|
||||
@commands.has_any_role(PD_PLAYERS_ROLE_NAME)
|
||||
@commands.check(legal_channel)
|
||||
async def paperdex_cardset(
|
||||
self, ctx: commands.Context,
|
||||
cardset_name: Literal['2013 Season', '2019 Season', '2021 Season', '2022 Season', '2022 Promos',
|
||||
'Sams Choice']):
|
||||
team = get_team_by_owner(ctx.author.id)
|
||||
|
||||
c_query = db_get('cardsets', params=[('name', cardset_name)])
|
||||
if c_query['count'] == 0:
|
||||
await ctx.send(f'Ope, I couldn\'t find that cardset. {get_cal_user(ctx).mention} halp.')
|
||||
return
|
||||
this_cardset = c_query['cardsets'][0]
|
||||
|
||||
all_dex = db_get(
|
||||
'paperdex',
|
||||
params=[('team_id', team['id']), ('cardset_id', this_cardset['id']), ('flat', True)]
|
||||
)
|
||||
dex_player_list = [x['player'] for x in all_dex['paperdex']]
|
||||
|
||||
hof_embed = get_team_embed(f'{team["lname"]} Collection', team=team)
|
||||
mvp_embed = get_team_embed(f'{team["lname"]} Collection', team=team)
|
||||
as_embed = get_team_embed(f'{team["lname"]} Collection', team=team)
|
||||
sta_embed = get_team_embed(f'{team["lname"]} Collection', team=team)
|
||||
res_embed = get_team_embed(f'{team["lname"]} Collection', team=team)
|
||||
rep_embed = get_team_embed(f'{team["lname"]} Collection', team=team)
|
||||
|
||||
coll_data = {
|
||||
99: {
|
||||
'name': 'Hall of Fame',
|
||||
'owned': 0,
|
||||
'players': [],
|
||||
'embeds': [hof_embed]
|
||||
},
|
||||
1: {
|
||||
'name': 'MVP',
|
||||
'owned': 0,
|
||||
'players': [],
|
||||
'embeds': [mvp_embed]
|
||||
},
|
||||
2: {
|
||||
'name': 'All-Star',
|
||||
'owned': 0,
|
||||
'players': [],
|
||||
'embeds': [as_embed]
|
||||
},
|
||||
3: {
|
||||
'name': 'Starter',
|
||||
'owned': 0,
|
||||
'players': [],
|
||||
'embeds': [sta_embed]
|
||||
},
|
||||
4: {
|
||||
'name': 'Reserve',
|
||||
'owned': 0,
|
||||
'players': [],
|
||||
'embeds': [res_embed]
|
||||
},
|
||||
5: {
|
||||
'name': 'Replacement',
|
||||
'owned': 0,
|
||||
'players': [],
|
||||
'embeds': [rep_embed]
|
||||
},
|
||||
'total_owned': 0
|
||||
}
|
||||
|
||||
response = await ctx.send(f'Okay, sifting through your cards...')
|
||||
|
||||
set_players = db_get(
|
||||
'players',
|
||||
params=[('cardset_id', this_cardset['id']), ('flat', True), ('inc_dex', False)],
|
||||
timeout=5
|
||||
)
|
||||
if not set_players:
|
||||
await ctx.send('Yikes, I don\'t see any players for that set.')
|
||||
async def paperdex_cardset_slash(self, interaction: discord.Interaction):
|
||||
team = get_team_by_owner(interaction.user.id)
|
||||
if not team:
|
||||
await interaction.response.send_message(f'Do you even have a team? I don\'t know you.', ephemeral=True)
|
||||
return
|
||||
|
||||
for player in set_players['players']:
|
||||
if player['player_id'] in dex_player_list:
|
||||
coll_data[player['rarity']]['owned'] += 1
|
||||
coll_data['total_owned'] += 1
|
||||
player['owned'] = True
|
||||
else:
|
||||
player['owned'] = False
|
||||
view = SelectView([SelectPaperdexCardset()], timeout=15)
|
||||
await interaction.response.send_message(
|
||||
content='You have 15 seconds to select a cardset.',
|
||||
view=view,
|
||||
ephemeral=True
|
||||
)
|
||||
|
||||
logging.debug(f'player: {player} / type: {type(player)}')
|
||||
coll_data[player['rarity']]['players'].append(player)
|
||||
await response.delete()
|
||||
await view.wait()
|
||||
await interaction.delete_original_response()
|
||||
|
||||
cover_embed = get_team_embed(f'{team["lname"]} Collection', team=team)
|
||||
cover_embed.description = this_cardset['name']
|
||||
cover_embed.add_field(name='# Total Cards', value=f'{set_players["count"]}')
|
||||
cover_embed.add_field(name='# Collected', value=f'{coll_data["total_owned"]}')
|
||||
display_embeds = [cover_embed]
|
||||
|
||||
for rarity_id in coll_data:
|
||||
if rarity_id != 'total_owned':
|
||||
if coll_data[rarity_id]['players']:
|
||||
coll_data[rarity_id]['embeds'][0].description = f'Rarity: {coll_data[rarity_id]["name"]}'
|
||||
coll_data[rarity_id]['embeds'][0].add_field(
|
||||
name='# Collected / # Total Cards',
|
||||
value=f'{coll_data[rarity_id]["owned"]} / {len(coll_data[rarity_id]["players"])}',
|
||||
inline=False
|
||||
)
|
||||
|
||||
chunk_string = ''
|
||||
for index, this_player in enumerate(coll_data[rarity_id]['players']):
|
||||
logging.debug(f'this_player: {this_player}')
|
||||
chunk_string += '☑ ' if this_player['owned'] else '⬜ '
|
||||
chunk_string += f'{this_player["p_name"]}\n'
|
||||
|
||||
if (index + 1) == len(coll_data[rarity_id]["players"]):
|
||||
coll_data[rarity_id]['embeds'][0].add_field(
|
||||
name=f'Group {math.ceil((index + 1) / 20)} / '
|
||||
f'{math.ceil(len(coll_data[rarity_id]["players"]) / 20)}',
|
||||
value=chunk_string
|
||||
)
|
||||
|
||||
elif (index + 1) % 20 == 0:
|
||||
coll_data[rarity_id]['embeds'][0].add_field(
|
||||
name=f'Group {math.floor((index + 1) / 20)} / '
|
||||
f'{math.ceil(len(coll_data[rarity_id]["players"]) / 20)}',
|
||||
value=chunk_string
|
||||
)
|
||||
chunk_string = ''
|
||||
|
||||
display_embeds.append(coll_data[rarity_id]['embeds'][0])
|
||||
|
||||
await embed_pagination(display_embeds, ctx.channel, ctx.author, timeout=30)
|
||||
|
||||
@paperdex_command.command(name='team', help='Check your collection of a specific MLB team')
|
||||
@group_paperdex.command(name='team', description='Check your collection of a specific MLB franchise')
|
||||
@commands.has_any_role(PD_PLAYERS_ROLE_NAME)
|
||||
@commands.check(legal_channel)
|
||||
async def paperdex_team(self, ctx: commands.Context, team_name: str):
|
||||
team = get_team_by_owner(ctx.author.id)
|
||||
async def paperdex_cardset_slash(self, interaction: discord.Interaction):
|
||||
team = get_team_by_owner(interaction.user.id)
|
||||
if not team:
|
||||
await interaction.response.send_message(f'Do you even have a team? I don\'t know you.', ephemeral=True)
|
||||
return
|
||||
|
||||
team_choice = None
|
||||
if team_name.title() in ALL_MLB_TEAMS.keys():
|
||||
team_choice = team_name.title()
|
||||
else:
|
||||
for x in ALL_MLB_TEAMS:
|
||||
if team_name.upper() in ALL_MLB_TEAMS[x] or team_name.title() in ALL_MLB_TEAMS[x]:
|
||||
team_choice = x
|
||||
break
|
||||
view = SelectView([SelectPaperdexTeam('AL'), SelectPaperdexTeam('NL')], timeout=30)
|
||||
await interaction.response.send_message(
|
||||
content='You have 30 seconds to select a team.',
|
||||
view=view,
|
||||
ephemeral=True
|
||||
)
|
||||
|
||||
p_query = db_get('players', params=[('franchise', team_choice)])
|
||||
if p_query['count'] == 0:
|
||||
await ctx.send(f'Hmm...I don\'t see any players from the {team_choice}. What\'s up with that '
|
||||
f'{get_cal_user(ctx).mention}?')
|
||||
await view.wait()
|
||||
await interaction.delete_original_response()
|
||||
|
||||
@commands.hybrid_command(name='ai-teams', help='Get list of AI teams and abbreviations')
|
||||
@commands.has_any_role(PD_PLAYERS_ROLE_NAME)
|
||||
@ -814,11 +695,6 @@ class Players(commands.Cog):
|
||||
|
||||
await ctx.send(content=None, embed=embed)
|
||||
|
||||
# @paperdex_command.command(name='teams', help='Check your collection based on team')
|
||||
# @commands.has_any_role(PD_PLAYERS_ROLE_NAME)
|
||||
# @commands.check(legal_channel)
|
||||
# async def paperdex_team(self, ctx: commands.Context, team_abbrev: Optional[str]):
|
||||
|
||||
@commands.hybrid_command(name='pullroster', help='Pull saved rosters from your team Sheet',
|
||||
aliases=['roster', 'rosters', 'pullrosters'])
|
||||
@app_commands.describe(
|
||||
|
||||
350
helpers.py
350
helpers.py
@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
import datetime
|
||||
import logging
|
||||
import math
|
||||
import os
|
||||
import random
|
||||
import traceback
|
||||
@ -435,6 +436,158 @@ class Pagination(discord.ui.View):
|
||||
self.stop()
|
||||
|
||||
|
||||
class SelectPaperdexCardset(discord.ui.Select):
|
||||
def __init__(self):
|
||||
options = [
|
||||
discord.SelectOption(label='2022 Season'),
|
||||
discord.SelectOption(label='2022 Promos'),
|
||||
discord.SelectOption(label='2021 Season'),
|
||||
discord.SelectOption(label='2019 Season'),
|
||||
discord.SelectOption(label='2013 Season')
|
||||
]
|
||||
super().__init__(placeholder='Select a Cardset', options=options)
|
||||
|
||||
async def callback(self, interaction: discord.Interaction):
|
||||
logging.info(f'SelectPaperdexCardset - selection: {self.values[0]}')
|
||||
cardset_id = None
|
||||
if self.values[0] == '2022 Season':
|
||||
cardset_id = 3
|
||||
elif self.values[0] == '2022 Promos':
|
||||
cardset_id = 4
|
||||
elif self.values[0] == '2021 Season':
|
||||
cardset_id = 1
|
||||
elif self.values[0] == '2019 Season':
|
||||
cardset_id = 5
|
||||
elif self.values[0] == '2013 Season':
|
||||
cardset_id = 6
|
||||
|
||||
c_query = db_get('cardsets', object_id=cardset_id, none_okay=False)
|
||||
await interaction.response.edit_message(content=f'Okay, sifting through your cards...', view=None)
|
||||
|
||||
cardset_embeds = paperdex_cardset_embed(team=get_team_by_owner(interaction.user.id), this_cardset=c_query)
|
||||
await embed_pagination(cardset_embeds, interaction.channel, interaction.user)
|
||||
|
||||
|
||||
class SelectPaperdexTeam(discord.ui.Select):
|
||||
def __init__(self, which: Literal['AL', 'NL']):
|
||||
self.which = which
|
||||
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):
|
||||
team_id = None
|
||||
if self.which == 'AL':
|
||||
if self.values[0] == 'Baltimore Orioles':
|
||||
team_id = 3
|
||||
elif self.values[0] == 'Boston Red Sox':
|
||||
team_id = 4
|
||||
elif self.values[0] == 'Chicago White Sox':
|
||||
team_id = 6
|
||||
elif self.values[0] == 'Cleveland Guardians':
|
||||
team_id = 8
|
||||
elif self.values[0] == 'Detroit Tigers':
|
||||
team_id = 10
|
||||
elif self.values[0] == 'Houston Astros':
|
||||
team_id = 11
|
||||
elif self.values[0] == 'Kansas City Royals':
|
||||
team_id = 12
|
||||
elif self.values[0] == 'Los Angeles Angels':
|
||||
team_id = 13
|
||||
elif self.values[0] == 'Minnesota Twins':
|
||||
team_id = 17
|
||||
elif self.values[0] == 'New York Yankees':
|
||||
team_id = 19
|
||||
elif self.values[0] == 'Oakland Athletics':
|
||||
team_id = 20
|
||||
elif self.values[0] == 'Seattle Mariners':
|
||||
team_id = 24
|
||||
elif self.values[0] == 'Tampa Bay Rays':
|
||||
team_id = 27
|
||||
elif self.values[0] == 'Texas Rangers':
|
||||
team_id = 28
|
||||
elif self.values[0] == 'Toronto Blue Jays':
|
||||
team_id = 29
|
||||
else:
|
||||
if self.values[0] == 'Arizona Diamondbacks':
|
||||
team_id = 1
|
||||
elif self.values[0] == 'Atlanta Braves':
|
||||
team_id = 2
|
||||
elif self.values[0] == 'Chicago Cubs':
|
||||
team_id = 5
|
||||
elif self.values[0] == 'Cincinnati Reds':
|
||||
team_id = 7
|
||||
elif self.values[0] == 'Colorado Rockies':
|
||||
team_id = 9
|
||||
elif self.values[0] == 'Los Angeles Dodgers':
|
||||
team_id = 14
|
||||
elif self.values[0] == 'Miami Marlins':
|
||||
team_id = 15
|
||||
elif self.values[0] == 'Milwaukee Brewers':
|
||||
team_id = 16
|
||||
elif self.values[0] == 'New York Mets':
|
||||
team_id = 18
|
||||
elif self.values[0] == 'Philadelphia Phillies':
|
||||
team_id = 21
|
||||
elif self.values[0] == 'Pittsburgh Pirates':
|
||||
team_id = 22
|
||||
elif self.values[0] == 'San Diego Padres':
|
||||
team_id = 23
|
||||
elif self.values[0] == 'San Francisco Giants':
|
||||
team_id = 25
|
||||
elif self.values[0] == 'St. Louis Cardinals':
|
||||
team_id = 26
|
||||
elif self.values[0] == 'Washington Nationals':
|
||||
team_id = 30
|
||||
|
||||
t_query = db_get('teams', object_id=team_id, none_okay=False)
|
||||
await interaction.response.edit_message(content=f'Okay, sifting through your cards...', view=None)
|
||||
|
||||
team_embeds = paperdex_team_embed(team=get_team_by_owner(interaction.user.id), mlb_team=t_query)
|
||||
await embed_pagination(team_embeds, interaction.channel, interaction.user)
|
||||
|
||||
|
||||
class SelectView(discord.ui.View):
|
||||
def __init__(self, select_objects: [discord.ui.Select], timeout: float = 300.0):
|
||||
super().__init__(timeout=timeout)
|
||||
|
||||
for x in select_objects:
|
||||
self.add_item(x)
|
||||
|
||||
# class Email(discord.ui.Modal, title='Team Sheet Share'):
|
||||
# def __init__(self, title: str, timeout: float = 300.0, custom_id: int = None):
|
||||
# super().__init__(timeout=timeout)
|
||||
@ -1138,7 +1291,7 @@ async def display_cards(
|
||||
|
||||
|
||||
async def embed_pagination(
|
||||
all_embeds: list, channel: commands.Context.channel, user: discord.Member, custom_message: str = None,
|
||||
all_embeds: list, channel, user: discord.Member, custom_message: str = None,
|
||||
timeout: int = 10, start_page: int = 0):
|
||||
if start_page > len(all_embeds) - 1 or start_page < 0:
|
||||
page_num = 0
|
||||
@ -1146,8 +1299,8 @@ async def embed_pagination(
|
||||
page_num = start_page
|
||||
|
||||
view = Pagination([user], timeout=timeout)
|
||||
l_emoji = await get_emoji(channel.guild, 'arrow_left')
|
||||
r_emoji = await get_emoji(channel.guild, 'arrow_right')
|
||||
l_emoji = ''
|
||||
r_emoji = ''
|
||||
view.right_button.label = f'Next: {page_num + 2}/{len(all_embeds)}{r_emoji}'
|
||||
view.cancel_button.label = f'Cancel'
|
||||
view.left_button.label = f'{l_emoji}Prev: {page_num}/{len(all_embeds)}'
|
||||
@ -1896,3 +2049,194 @@ def get_ratings_guide(sheets):
|
||||
'pitcher_ratings': pitchers
|
||||
}
|
||||
|
||||
|
||||
def paperdex_cardset_embed(team: dict, this_cardset: dict) -> [discord.Embed]:
|
||||
all_dex = db_get(
|
||||
'paperdex',
|
||||
params=[('team_id', team['id']), ('cardset_id', this_cardset['id']), ('flat', True)]
|
||||
)
|
||||
dex_player_list = [x['player'] for x in all_dex['paperdex']]
|
||||
|
||||
hof_embed = get_team_embed(f'{team["lname"]} Collection', team=team)
|
||||
mvp_embed = get_team_embed(f'{team["lname"]} Collection', team=team)
|
||||
as_embed = get_team_embed(f'{team["lname"]} Collection', team=team)
|
||||
sta_embed = get_team_embed(f'{team["lname"]} Collection', team=team)
|
||||
res_embed = get_team_embed(f'{team["lname"]} Collection', team=team)
|
||||
rep_embed = get_team_embed(f'{team["lname"]} Collection', team=team)
|
||||
|
||||
coll_data = {
|
||||
99: {
|
||||
'name': 'Hall of Fame',
|
||||
'owned': 0,
|
||||
'players': [],
|
||||
'embeds': [hof_embed]
|
||||
},
|
||||
1: {
|
||||
'name': 'MVP',
|
||||
'owned': 0,
|
||||
'players': [],
|
||||
'embeds': [mvp_embed]
|
||||
},
|
||||
2: {
|
||||
'name': 'All-Star',
|
||||
'owned': 0,
|
||||
'players': [],
|
||||
'embeds': [as_embed]
|
||||
},
|
||||
3: {
|
||||
'name': 'Starter',
|
||||
'owned': 0,
|
||||
'players': [],
|
||||
'embeds': [sta_embed]
|
||||
},
|
||||
4: {
|
||||
'name': 'Reserve',
|
||||
'owned': 0,
|
||||
'players': [],
|
||||
'embeds': [res_embed]
|
||||
},
|
||||
5: {
|
||||
'name': 'Replacement',
|
||||
'owned': 0,
|
||||
'players': [],
|
||||
'embeds': [rep_embed]
|
||||
},
|
||||
'total_owned': 0
|
||||
}
|
||||
|
||||
set_players = db_get(
|
||||
'players',
|
||||
params=[('cardset_id', this_cardset['id']), ('flat', True), ('inc_dex', False)],
|
||||
timeout=5
|
||||
)
|
||||
|
||||
for player in set_players['players']:
|
||||
if player['player_id'] in dex_player_list:
|
||||
coll_data[player['rarity']]['owned'] += 1
|
||||
coll_data['total_owned'] += 1
|
||||
player['owned'] = True
|
||||
else:
|
||||
player['owned'] = False
|
||||
|
||||
logging.debug(f'player: {player} / type: {type(player)}')
|
||||
coll_data[player['rarity']]['players'].append(player)
|
||||
|
||||
cover_embed = get_team_embed(f'{team["lname"]} Collection', team=team)
|
||||
cover_embed.description = this_cardset['name']
|
||||
cover_embed.add_field(name='# Total Cards', value=f'{set_players["count"]}')
|
||||
cover_embed.add_field(name='# Collected', value=f'{coll_data["total_owned"]}')
|
||||
display_embeds = [cover_embed]
|
||||
|
||||
for rarity_id in coll_data:
|
||||
if rarity_id != 'total_owned':
|
||||
if coll_data[rarity_id]['players']:
|
||||
coll_data[rarity_id]['embeds'][0].description = f'Rarity: {coll_data[rarity_id]["name"]}'
|
||||
coll_data[rarity_id]['embeds'][0].add_field(
|
||||
name='# Collected / # Total Cards',
|
||||
value=f'{coll_data[rarity_id]["owned"]} / {len(coll_data[rarity_id]["players"])}',
|
||||
inline=False
|
||||
)
|
||||
|
||||
chunk_string = ''
|
||||
for index, this_player in enumerate(coll_data[rarity_id]['players']):
|
||||
logging.debug(f'this_player: {this_player}')
|
||||
chunk_string += '☑ ' if this_player['owned'] else '⬜ '
|
||||
chunk_string += f'{this_player["p_name"]}\n'
|
||||
|
||||
if (index + 1) == len(coll_data[rarity_id]["players"]):
|
||||
coll_data[rarity_id]['embeds'][0].add_field(
|
||||
name=f'Group {math.ceil((index + 1) / 20)} / '
|
||||
f'{math.ceil(len(coll_data[rarity_id]["players"]) / 20)}',
|
||||
value=chunk_string
|
||||
)
|
||||
|
||||
elif (index + 1) % 20 == 0:
|
||||
coll_data[rarity_id]['embeds'][0].add_field(
|
||||
name=f'Group {math.floor((index + 1) / 20)} / '
|
||||
f'{math.ceil(len(coll_data[rarity_id]["players"]) / 20)}',
|
||||
value=chunk_string
|
||||
)
|
||||
chunk_string = ''
|
||||
|
||||
display_embeds.append(coll_data[rarity_id]['embeds'][0])
|
||||
|
||||
return display_embeds
|
||||
|
||||
|
||||
def paperdex_team_embed(team: dict, mlb_team: dict) -> [discord.Embed]:
|
||||
all_dex = db_get(
|
||||
'paperdex',
|
||||
params=[('team_id', team['id']), ('franchise', mlb_team['lname']), ('flat', True)]
|
||||
)
|
||||
dex_player_list = [x['player'] for x in all_dex['paperdex']]
|
||||
|
||||
c_query = db_get('cardsets')
|
||||
coll_data = {'total_owned': 0}
|
||||
|
||||
total_players = 0
|
||||
for x in c_query['cardsets']:
|
||||
set_players = db_get(
|
||||
'players',
|
||||
params=[('cardset_id', x['id']), ('franchise', mlb_team['lname']), ('flat', True), ('inc_dex', False)]
|
||||
)
|
||||
if set_players is not None:
|
||||
coll_data[x['id']] = {
|
||||
'name': x['name'],
|
||||
'owned': 0,
|
||||
'players': [],
|
||||
'embeds': [get_team_embed(f'{team["lname"]} Collection', team=team)]
|
||||
}
|
||||
total_players += set_players['count']
|
||||
|
||||
for player in set_players['players']:
|
||||
if player['player_id'] in dex_player_list:
|
||||
coll_data[x['id']]['owned'] += 1
|
||||
coll_data['total_owned'] += 1
|
||||
player['owned'] = True
|
||||
else:
|
||||
player['owned'] = False
|
||||
|
||||
logging.debug(f'player: {player} / type: {type(player)}')
|
||||
coll_data[x['id']]['players'].append(player)
|
||||
|
||||
cover_embed = get_team_embed(f'{team["lname"]} Collection', team=team)
|
||||
cover_embed.description = mlb_team['lname']
|
||||
cover_embed.add_field(name='# Total Cards', value=f'{total_players}')
|
||||
cover_embed.add_field(name='# Collected', value=f'{coll_data["total_owned"]}')
|
||||
display_embeds = [cover_embed]
|
||||
|
||||
for cardset_id in coll_data:
|
||||
if cardset_id != 'total_owned':
|
||||
if coll_data[cardset_id]['players']:
|
||||
coll_data[cardset_id]['embeds'][0].description = f'{mlb_team["lname"]} / ' \
|
||||
f'{coll_data[cardset_id]["name"]}'
|
||||
coll_data[cardset_id]['embeds'][0].add_field(
|
||||
name='# Collected / # Total Cards',
|
||||
value=f'{coll_data[cardset_id]["owned"]} / {len(coll_data[cardset_id]["players"])}',
|
||||
inline=False
|
||||
)
|
||||
|
||||
chunk_string = ''
|
||||
for index, this_player in enumerate(coll_data[cardset_id]['players']):
|
||||
logging.debug(f'this_player: {this_player}')
|
||||
chunk_string += '☑ ' if this_player['owned'] else '⬜ '
|
||||
chunk_string += f'{this_player["p_name"]}\n'
|
||||
|
||||
if (index + 1) == len(coll_data[cardset_id]["players"]):
|
||||
coll_data[cardset_id]['embeds'][0].add_field(
|
||||
name=f'Group {math.ceil((index + 1) / 20)} / '
|
||||
f'{math.ceil(len(coll_data[cardset_id]["players"]) / 20)}',
|
||||
value=chunk_string
|
||||
)
|
||||
|
||||
elif (index + 1) % 20 == 0:
|
||||
coll_data[cardset_id]['embeds'][0].add_field(
|
||||
name=f'Group {math.floor((index + 1) / 20)} / '
|
||||
f'{math.ceil(len(coll_data[cardset_id]["players"]) / 20)}',
|
||||
value=chunk_string
|
||||
)
|
||||
chunk_string = ''
|
||||
|
||||
display_embeds.append(coll_data[cardset_id]['embeds'][0])
|
||||
|
||||
return display_embeds
|
||||
|
||||
Loading…
Reference in New Issue
Block a user