Normalize Player.franchise queries to use Team.sname
- Add FRANCHISE_NORMALIZE dict and helper to constants.py - Update economy.py to normalize team_choice and use sname - Update helpers/main.py franchise queries to use sname - Update selectors.py to normalize franchise on player updates Part of cross-era player matching fix for AI rosters 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
5aa88e4e3d
commit
565afd0183
@ -682,8 +682,10 @@ class Economy(commands.Cog):
|
||||
logger.debug(f'pack: {pack}')
|
||||
logger.debug(f'pack cardset: {pack["pack_cardset"]}')
|
||||
if pack['pack_team'] is None and pack['pack_cardset'] is None:
|
||||
if pack['pack_type']['name'] in p_data:
|
||||
p_group = pack['pack_type']['name']
|
||||
p_group = pack['pack_type']['name']
|
||||
# Add to p_data if this is a new pack type
|
||||
if p_group not in p_data:
|
||||
p_data[p_group] = []
|
||||
|
||||
elif pack['pack_team'] is not None:
|
||||
if pack['pack_type']['name'] == 'Standard':
|
||||
@ -1250,14 +1252,14 @@ class Economy(commands.Cog):
|
||||
anchor_all_stars = await db_get(
|
||||
'players/random',
|
||||
params=[
|
||||
('min_rarity', 3), ('max_rarity', 3), ('franchise', team_choice), ('pos_exclude', 'RP'), ('limit', 1),
|
||||
('min_rarity', 3), ('max_rarity', 3), ('franchise', normalize_franchise(team_choice)), ('pos_exclude', 'RP'), ('limit', 1),
|
||||
('in_packs', True)
|
||||
]
|
||||
)
|
||||
anchor_starters = await db_get(
|
||||
'players/random',
|
||||
params=[
|
||||
('min_rarity', 2), ('max_rarity', 2), ('franchise', team_choice), ('pos_exclude', 'RP'), ('limit', 2),
|
||||
('min_rarity', 2), ('max_rarity', 2), ('franchise', normalize_franchise(team_choice)), ('pos_exclude', 'RP'), ('limit', 2),
|
||||
('in_packs', True)
|
||||
]
|
||||
)
|
||||
@ -1476,7 +1478,7 @@ class Economy(commands.Cog):
|
||||
'is_ai': True
|
||||
})
|
||||
|
||||
p_query = await db_get('players', params=[('franchise', lname)])
|
||||
p_query = await db_get('players', params=[('franchise', sname)])
|
||||
|
||||
this_pack = await db_post(
|
||||
'packs/one',
|
||||
@ -1503,7 +1505,7 @@ class Economy(commands.Cog):
|
||||
total_cards = 0
|
||||
total_teams = 0
|
||||
for team in ai_teams['teams']:
|
||||
all_players = await db_get('players', params=[('franchise', team['lname'])])
|
||||
all_players = await db_get('players', params=[('franchise', team['sname'])])
|
||||
|
||||
new_players = []
|
||||
if all_players:
|
||||
|
||||
@ -6,7 +6,7 @@ Contains all Select classes for various team, cardset, and pack selections.
|
||||
import logging
|
||||
import discord
|
||||
from typing import Literal, Optional
|
||||
from helpers.constants import ALL_MLB_TEAMS, IMAGES
|
||||
from helpers.constants import ALL_MLB_TEAMS, IMAGES, normalize_franchise
|
||||
|
||||
logger = logging.getLogger('discord_app')
|
||||
|
||||
@ -465,7 +465,9 @@ class SelectUpdatePlayerTeam(discord.ui.Select):
|
||||
from discord_ui.confirmations import Confirm
|
||||
from helpers import player_desc, send_to_channel
|
||||
|
||||
if self.values[0] == self.player['franchise'] or self.values[0] == self.player['mlbclub']:
|
||||
# Check if already assigned - compare against both normalized franchise and full mlbclub
|
||||
normalized_selection = normalize_franchise(self.values[0])
|
||||
if normalized_selection == self.player['franchise'] or self.values[0] == self.player['mlbclub']:
|
||||
await interaction.response.send_message(
|
||||
content=f'Thank you for the help, but it looks like somebody beat you to it! '
|
||||
f'**{player_desc(self.player)}** is already assigned to the **{self.player["mlbclub"]}**.'
|
||||
@ -493,7 +495,7 @@ class SelectUpdatePlayerTeam(discord.ui.Select):
|
||||
await question.delete()
|
||||
|
||||
await db_patch('players', object_id=self.player['player_id'], params=[
|
||||
('mlbclub', self.values[0]), ('franchise', self.values[0])
|
||||
('mlbclub', self.values[0]), ('franchise', normalize_franchise(self.values[0]))
|
||||
])
|
||||
await db_post(f'teams/{self.reporting_team["id"]}/money/25')
|
||||
await send_to_channel(
|
||||
|
||||
@ -128,6 +128,48 @@ ALL_MLB_TEAMS = {
|
||||
'Washington Nationals': ['WSN', 'WAS', 'Nationals'],
|
||||
}
|
||||
|
||||
# Franchise normalization: Convert city+team names to city-agnostic team names
|
||||
# This enables cross-era player matching (e.g., 'Oakland Athletics' -> 'Athletics')
|
||||
FRANCHISE_NORMALIZE = {
|
||||
'Arizona Diamondbacks': 'Diamondbacks',
|
||||
'Atlanta Braves': 'Braves',
|
||||
'Baltimore Orioles': 'Orioles',
|
||||
'Boston Red Sox': 'Red Sox',
|
||||
'Chicago Cubs': 'Cubs',
|
||||
'Chicago White Sox': 'White Sox',
|
||||
'Cincinnati Reds': 'Reds',
|
||||
'Cleveland Guardians': 'Guardians',
|
||||
'Colorado Rockies': 'Rockies',
|
||||
'Detroit Tigers': 'Tigers',
|
||||
'Houston Astros': 'Astros',
|
||||
'Kansas City Royals': 'Royals',
|
||||
'Los Angeles Angels': 'Angels',
|
||||
'Los Angeles Dodgers': 'Dodgers',
|
||||
'Miami Marlins': 'Marlins',
|
||||
'Milwaukee Brewers': 'Brewers',
|
||||
'Minnesota Twins': 'Twins',
|
||||
'New York Mets': 'Mets',
|
||||
'New York Yankees': 'Yankees',
|
||||
'Oakland Athletics': 'Athletics',
|
||||
'Philadelphia Phillies': 'Phillies',
|
||||
'Pittsburgh Pirates': 'Pirates',
|
||||
'San Diego Padres': 'Padres',
|
||||
'San Francisco Giants': 'Giants',
|
||||
'Seattle Mariners': 'Mariners',
|
||||
'St Louis Cardinals': 'Cardinals',
|
||||
'St. Louis Cardinals': 'Cardinals',
|
||||
'Tampa Bay Rays': 'Rays',
|
||||
'Texas Rangers': 'Rangers',
|
||||
'Toronto Blue Jays': 'Blue Jays',
|
||||
'Washington Nationals': 'Nationals',
|
||||
}
|
||||
|
||||
|
||||
def normalize_franchise(franchise: str) -> str:
|
||||
"""Convert city+team name to team-only (e.g., 'Oakland Athletics' -> 'Athletics')"""
|
||||
return FRANCHISE_NORMALIZE.get(franchise, franchise)
|
||||
|
||||
|
||||
# Image URLs
|
||||
IMAGES = {
|
||||
'logo': f'{PD_IMAGE_BUCKET}/sba-logo.png',
|
||||
|
||||
@ -723,7 +723,7 @@ async def roll_for_cards(all_packs: list, extra_val=None) -> list:
|
||||
('limit', counts[key]['count'])
|
||||
]
|
||||
if all_packs[0]['pack_team'] is not None:
|
||||
params.extend([('franchise', all_packs[0]['pack_team']['lname']), ('in_packs', True)])
|
||||
params.extend([('franchise', all_packs[0]['pack_team']['sname']), ('in_packs', True)])
|
||||
elif all_packs[0]['pack_cardset'] is not None:
|
||||
params.append(('cardset_id', all_packs[0]['pack_cardset']['id']))
|
||||
else:
|
||||
@ -1458,7 +1458,7 @@ async def paperdex_cardset_embed(team: dict, this_cardset: dict) -> list[discord
|
||||
async def paperdex_team_embed(team: dict, mlb_team: dict) -> list[discord.Embed]:
|
||||
all_dex = await db_get(
|
||||
'paperdex',
|
||||
params=[('team_id', team['id']), ('franchise', mlb_team['lname']), ('flat', True)]
|
||||
params=[('team_id', team['id']), ('franchise', mlb_team['sname']), ('flat', True)]
|
||||
)
|
||||
dex_player_list = [x['player'] for x in all_dex['paperdex']]
|
||||
|
||||
@ -1469,7 +1469,7 @@ async def paperdex_team_embed(team: dict, mlb_team: dict) -> list[discord.Embed]
|
||||
for x in c_query['cardsets']:
|
||||
set_players = await db_get(
|
||||
'players',
|
||||
params=[('cardset_id', x['id']), ('franchise', mlb_team['lname']), ('flat', True), ('inc_dex', False)]
|
||||
params=[('cardset_id', x['id']), ('franchise', mlb_team['sname']), ('flat', True), ('inc_dex', False)]
|
||||
)
|
||||
if set_players is not None:
|
||||
coll_data[x['id']] = {
|
||||
@ -1721,7 +1721,7 @@ async def open_choice_pack(this_pack, team: dict, context, cardset_id: Optional[
|
||||
while len(players) < 4 and rarity_id < 10:
|
||||
params = [
|
||||
('min_rarity', min_rarity), ('max_rarity', rarity_id), ('limit', 4 - len(players)),
|
||||
('franchise', this_pack['pack_team']['lname'])
|
||||
('franchise', this_pack['pack_team']['sname'])
|
||||
]
|
||||
# Only apply in_packs filter if no specific cardset is provided
|
||||
if this_pack['pack_team']['abbrev'] not in ['MSS'] and cardset_id is None:
|
||||
@ -1781,7 +1781,7 @@ async def open_choice_pack(this_pack, team: dict, context, cardset_id: Optional[
|
||||
if cardset_id is None:
|
||||
params.append(('in_packs', True))
|
||||
if this_pack['pack_team'] is not None:
|
||||
params.append(('franchise', this_pack['pack_team']['lname']))
|
||||
params.append(('franchise', this_pack['pack_team']['sname']))
|
||||
if cardset_id is not None:
|
||||
params.append(('cardset_id', cardset_id))
|
||||
pl = await db_get('players/random', params=params)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user