Add rare plays, 2016, and 2008
This commit is contained in:
parent
33e5e97726
commit
d1f82eb58e
173
cogs/admins.py
173
cogs/admins.py
@ -1,20 +1,11 @@
|
||||
import copy
|
||||
import csv
|
||||
import datetime
|
||||
import logging
|
||||
import re
|
||||
|
||||
import discord
|
||||
import pygsheets
|
||||
import requests
|
||||
|
||||
import gauntlets
|
||||
from helpers import *
|
||||
from db_calls import *
|
||||
from discord import Member
|
||||
from discord.ext import commands, tasks
|
||||
from discord import app_commands
|
||||
from difflib import get_close_matches
|
||||
|
||||
# date = f'{datetime.datetime.now().year}-{datetime.datetime.now().month}-{datetime.datetime.now().day}'
|
||||
# logging.basicConfig(
|
||||
@ -207,20 +198,11 @@ class Admins(commands.Cog):
|
||||
|
||||
await response.edit(content=f'All done!')
|
||||
|
||||
@commands.hybrid_command(name='update-rarity', help='Mod: Pull current rarities and update players')
|
||||
@commands.command(name='update-rarity', help='Mod: Pull current rarities and update players')
|
||||
@commands.is_owner()
|
||||
async def update_rarity_command(self, ctx, sheet_url: str):
|
||||
async def update_rarity_command(self, ctx):
|
||||
await ctx.send(f'Oh boy, here I go sheetsing again!')
|
||||
|
||||
# Template:
|
||||
# https://docs.google.com/spreadsheets/d/14FpNo2JOmAKc7rdeiEGNUOud_gbLSrlcoic-OXlhsQc/edit#gid=1845561581
|
||||
sheets = get_sheets(self.bot)
|
||||
this_sheet = sheets.open_by_url(sheet_url)
|
||||
logging.info(f'this_sheet: {this_sheet}')
|
||||
up_sheet = this_sheet.worksheet_by_title('Rarity Updates')
|
||||
logging.info(f'up_sheet: {up_sheet}')
|
||||
all_players = up_sheet.range('A2:E')
|
||||
# logging.info(f'all_players: {all_players}')
|
||||
rarities = {
|
||||
'MVP': 1,
|
||||
'All-Star': 2,
|
||||
@ -245,6 +227,8 @@ class Admins(commands.Cog):
|
||||
return max(old_cost - 780, 15)
|
||||
elif new_rarity == 5:
|
||||
return max(old_cost - 800, 5)
|
||||
elif new_rarity == 99:
|
||||
return old_cost + 1600
|
||||
elif old_rarity == 2:
|
||||
if new_rarity == 1:
|
||||
return old_cost + 540
|
||||
@ -254,6 +238,8 @@ class Admins(commands.Cog):
|
||||
return max(old_cost - 240, 15)
|
||||
elif new_rarity == 5:
|
||||
return max(old_cost - 260, 5)
|
||||
elif new_rarity == 99:
|
||||
return old_cost + 2140
|
||||
elif old_rarity == 3:
|
||||
if new_rarity == 1:
|
||||
return old_cost + 720
|
||||
@ -263,6 +249,8 @@ class Admins(commands.Cog):
|
||||
return max(old_cost - 60, 15)
|
||||
elif new_rarity == 5:
|
||||
return max(old_cost - 80, 5)
|
||||
elif new_rarity == 99:
|
||||
return old_cost + 2320
|
||||
elif old_rarity == 4:
|
||||
if new_rarity == 1:
|
||||
return old_cost + 780
|
||||
@ -272,6 +260,8 @@ class Admins(commands.Cog):
|
||||
return old_cost + 60
|
||||
elif new_rarity == 5:
|
||||
return max(old_cost - 20, 5)
|
||||
elif new_rarity == 99:
|
||||
return old_cost + 2380
|
||||
elif old_rarity == 5:
|
||||
if new_rarity == 1:
|
||||
return old_cost + 800
|
||||
@ -281,49 +271,124 @@ class Admins(commands.Cog):
|
||||
return old_cost + 80
|
||||
elif new_rarity == 4:
|
||||
return old_cost + 20
|
||||
elif new_rarity == 99:
|
||||
return old_cost + 2400
|
||||
elif old_rarity == 99:
|
||||
if new_rarity == 1:
|
||||
return max(old_cost - 1600, 800)
|
||||
elif new_rarity == 2:
|
||||
return max(old_cost - 2140, 100)
|
||||
elif new_rarity == 3:
|
||||
return max(old_cost - 2320, 50)
|
||||
elif new_rarity == 4:
|
||||
return max(old_cost - 2380, 15)
|
||||
elif new_rarity == 5:
|
||||
return max(old_cost - 2400, 5)
|
||||
|
||||
raise KeyError(f'Could not find a cost update for {player["p_name"]} from {player["rarity"]["name"]} to '
|
||||
f'{new_rarity}')
|
||||
|
||||
player_id = 804
|
||||
await ctx.send(f'Running player updates...')
|
||||
errors = []
|
||||
new_players = []
|
||||
done = 0
|
||||
for line in all_players:
|
||||
# logging.info(f'line: {line}')
|
||||
if line[4].value == 'CHANGE':
|
||||
try:
|
||||
logging.info(f'Updating {line[1].value}')
|
||||
this_player = await db_get('players', object_id=line[0].value)
|
||||
counter = 0
|
||||
# Read player-json.csv
|
||||
with open('storage/player_json.csv') as csv_file:
|
||||
csv_reader = csv.reader(csv_file)
|
||||
|
||||
logging.info(f'this_player: {this_player["p_name"]}')
|
||||
new_player = copy.deepcopy(this_player)
|
||||
new_player['player_id'] = player_id + done
|
||||
logging.info(f'new_player: {new_player["player_id"]}')
|
||||
new_player['image'] = new_player['image'].replace("-launch", "-launch/update01")
|
||||
new_player['rarity_id'] = rarities[line[3].value]
|
||||
# new_player['cardset_id'] = 3
|
||||
new_player['cost'] = new_cost(this_player, rarities[line[3].value], rarities[line[2].value])
|
||||
logging.info(f'new_player cost: {new_player["cost"]}')
|
||||
# Per line, search for player by cardset_id and bbref_id
|
||||
for row in csv_reader:
|
||||
if counter > 50:
|
||||
pass
|
||||
p_query = await db_get('players', params=[('cardset_id', 9), ('bbref_id', row[4])])
|
||||
if p_query['count'] > 0:
|
||||
this_player = p_query['players'][0]
|
||||
updates = []
|
||||
|
||||
this_player = await db_patch('players', object_id=this_player['player_id'], params=[
|
||||
('cost', new_player['cost'])
|
||||
])
|
||||
logging.info(f'patched_player: {this_player["p_name"]} / cardset: {this_player["cardset"]["id"]}')
|
||||
# new_players.append(new_player)
|
||||
if '0501' in this_player['image']:
|
||||
updates.append(('image', this_player['image'].replace('2023-0501', '2023-0515')))
|
||||
|
||||
# new_player = db_patch('players', object_id=this_player['player_id'], params=[
|
||||
# ('image', this_player['image'].replace("-launch", "-launch/update01")),
|
||||
# ('rarity_id', rarities[line[3].value]), ('cost', new_cost(this_player, rarities[line[3].value]))
|
||||
# ])
|
||||
done += 1
|
||||
except Exception as e:
|
||||
e_message = f'{line[1].value}: {e}'
|
||||
logging.error(e_message)
|
||||
errors.append(e_message)
|
||||
if this_player['rarity']['name'] != row[9]:
|
||||
new_r = rarities[row[9]]
|
||||
updates.append(
|
||||
('cost', new_cost(this_player, new_r, rarities[this_player['rarity']['name']]))
|
||||
)
|
||||
updates.append(
|
||||
('rarity_id', new_r)
|
||||
)
|
||||
|
||||
if this_player['pos_1'] != row[11]:
|
||||
updates.append(('pos_1', row[11]))
|
||||
|
||||
try:
|
||||
if len(row[12]) > 0:
|
||||
if this_player['pos_2'] != row[12]:
|
||||
updates.append(('pos_2', row[12]))
|
||||
elif this_player['pos_2'] is not None:
|
||||
updates.append(('pos_2', False))
|
||||
except IndexError:
|
||||
pass
|
||||
try:
|
||||
if len(row[13]) > 0:
|
||||
if this_player['pos_3'] != row[13]:
|
||||
updates.append(('pos_3', row[13]))
|
||||
elif this_player['pos_3'] is not None:
|
||||
updates.append(('pos_3', False))
|
||||
except IndexError:
|
||||
pass
|
||||
try:
|
||||
if len(row[14]) > 0:
|
||||
if this_player['pos_4'] != row[14]:
|
||||
updates.append(('pos_4', row[14]))
|
||||
elif this_player['pos_4'] is not None:
|
||||
updates.append(('pos_4', False))
|
||||
except IndexError:
|
||||
pass
|
||||
try:
|
||||
if len(row[15]) > 0:
|
||||
if this_player['pos_5'] != row[15]:
|
||||
updates.append(('pos_5', row[15]))
|
||||
elif this_player['pos_5'] is not None:
|
||||
updates.append(('pos_5', False))
|
||||
except IndexError:
|
||||
pass
|
||||
try:
|
||||
if len(row[16]) > 0:
|
||||
if this_player['pos_6'] != row[16]:
|
||||
updates.append(('pos_6', row[16]))
|
||||
elif this_player['pos_6'] is not None:
|
||||
updates.append(('pos_6', False))
|
||||
except IndexError:
|
||||
pass
|
||||
try:
|
||||
if len(row[17]) > 0:
|
||||
if this_player['pos_7'] != row[17]:
|
||||
updates.append(('pos_7', row[17]))
|
||||
elif this_player['pos_7'] is not None:
|
||||
updates.append(('pos_7', False))
|
||||
except IndexError:
|
||||
pass
|
||||
try:
|
||||
if len(row[18]) > 0:
|
||||
if this_player['pos_8'] != row[18]:
|
||||
updates.append(('pos_5', row[18]))
|
||||
elif this_player['pos_8'] is not None:
|
||||
updates.append(('pos_8', False))
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
# Patch player with new rarity_id, cost, and positions 1 - 6
|
||||
if len(updates) > 0:
|
||||
logging.info(f'Updating {row[1]} - params: {updates}')
|
||||
await db_patch(
|
||||
'players',
|
||||
object_id=this_player['player_id'],
|
||||
params=updates
|
||||
)
|
||||
else:
|
||||
errors.append(f'{row[1]} - {row[4]}')
|
||||
counter += 1
|
||||
await ctx.send(f'All done!')
|
||||
|
||||
await db_post('players', payload={'players': new_players})
|
||||
await ctx.send(f'Updated {done} players!')
|
||||
if len(errors) > 0:
|
||||
e_string = "\n- ".join(errors)
|
||||
await ctx.send(f'I encountered the following errors:\n\n{e_string}')
|
||||
|
||||
@ -367,8 +367,9 @@ class Players(commands.Cog):
|
||||
@app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME)
|
||||
async def player_slash_command(
|
||||
self, interaction: discord.Interaction, player_name: str,
|
||||
cardset: Literal['All', '2012 Season', '2013 Season', '2019 Season', '2021 Season', '2022 Season',
|
||||
'2022 Promos', '2023 Live', 'Mario Super Sluggers', 'Sams Choice'] = 'All'):
|
||||
cardset: Literal['All', '2008 Season', '2012 Season', '2013 Season', '2016 Season', '2019 Season',
|
||||
'2021 Season', '2022 Season', '2022 Promos', '2023 Live', 'Mario Super Sluggers',
|
||||
'Sams Choice'] = 'All'):
|
||||
# min_rarity: Literal['Replacement', 'Reserve', 'Starter', 'All-Star', 'MVP'] = None):
|
||||
ephemeral = False
|
||||
if interaction.channel.name in ['paper-dynasty-chat', 'pd-news-ticker']:
|
||||
|
||||
52
helpers.py
52
helpers.py
@ -103,59 +103,55 @@ IMAGES = {
|
||||
}
|
||||
INFIELD_X_CHART = {
|
||||
'si1': {
|
||||
'rp': 'Runner on first: Line drive hits the runner! Runner on first is out. Batter goes to first with single '
|
||||
'and all other runners hold.\nNo runner on first: batter singles, runners advance 1 base.',
|
||||
'rp': 'No runner on first: Batter is safe at first and no one covers second. Batter to second, runners only '
|
||||
'advance 1 base.\nRunner on first: batter singles, runners advance 1 base.',
|
||||
'e1': 'Single and Error, batter to second, runners advance 2 bases.',
|
||||
'e2': 'Single and Error, batter to third, all runners score.',
|
||||
'no': 'Single, runners advance 1 base.'
|
||||
},
|
||||
'po': {
|
||||
'rp': 'The batters hits a popup. None of the fielders take charge on the play and the ball drops in the '
|
||||
'infield for a single! All runners advance 1 base.',
|
||||
'infield for a SI*! All runners advance 1 base.',
|
||||
'e1': 'The catcher drops a popup for an error. All runners advance 1 base.',
|
||||
'e2': 'The catcher grabs a squib in front of the plate and throws it into right field. The batter goes to '
|
||||
'second and all runners score.',
|
||||
'no': 'The batter pops out to the catcher.'
|
||||
},
|
||||
'wp': {
|
||||
'rp': 'Automatic wild pitch. Catcher has trouble finding it and all base runners advance 2 bases.',
|
||||
'no': 'Automatic wild pitch, all runners advance 1 base and batter rolls AB again.'
|
||||
},
|
||||
'x': {
|
||||
'rp': 'Runner(s) on base: pitcher trips during his delivery and the ball sails for automatic wild pitch, '
|
||||
'runners advance 1 base and batter rolls AB again.',
|
||||
'no': 'Wild pitch check (credited as a PB). If a passed ball occurs, batter rerolls AB. '
|
||||
'If no passed ball occurs, the batter fouls out to the catcher.'
|
||||
},
|
||||
'fo': {
|
||||
'rp': 'Batter swings and misses, but is awarded first base on a catcher interference call! Baserunners advance '
|
||||
'only if forced.',
|
||||
'rp': 'Batter swings and misses, but is awarded first base on a catcher interference call! One base error, '
|
||||
'baserunners advance only if forced.',
|
||||
'e1': 'The catcher drops a foul popup for an error. Batter rolls AB again.',
|
||||
'e2': 'The catcher drops a foul popup for an error. Batter rolls AB again.',
|
||||
'no': 'Runner(s) on base: make a passed ball check. If no passed ball, batter pops out to the catcher. If a '
|
||||
'passed ball occurs, batter roll his AB again.\nNo runners: batter pops out to the catcher'
|
||||
},
|
||||
'g1': {
|
||||
'rp': 'Runner on first: runner on first breaks up the double play, but umpires call runner interference and '
|
||||
'the batter is out on GIDP.\nNo runners: Batter grounds out.',
|
||||
'rp': 'Runner on first, <2 outs: runner on first breaks up the double play, gbB\n'
|
||||
'Else: gbA',
|
||||
'e1': 'Error, batter to first, runners advance 1 base.',
|
||||
'e2': 'Error, batter to second, runners advance 2 bases.',
|
||||
'no': 'Consult Groundball Chart: `!gbA`'
|
||||
},
|
||||
'g2': {
|
||||
'rp': 'Batter lines the ball off the pitcher to the fielder who makes the play to first for the out! Runners '
|
||||
'advance only if forced.',
|
||||
'rp': 'Runner(s) on base: fielder makes bad throw for lead runner but batter is out at first for a gbC\n'
|
||||
'No runners: gbB',
|
||||
'e1': 'Error, batter to first, runners advance 1 base.',
|
||||
'e2': 'Error, batter to second, runners advance 2 bases.',
|
||||
'no': 'Consult Groundball Chart: `!gbB`'
|
||||
},
|
||||
'g3': {
|
||||
'rp': 'Batter lines the ball off the mound and deflects to the fielder who makes the play to first for the '
|
||||
'out! Runners advance 1 base.',
|
||||
'rp': 'Runner(s) on base: fielder checks the runner before throwing to first and allows a SI*\n'
|
||||
'No runners: gbC',
|
||||
'e1': 'Error, batter to first, runners advance 1 base.',
|
||||
'e2': 'Error, batter to second, runners advance 2 bases.',
|
||||
'no': 'Consult Groundball Chart: `!gbC`'
|
||||
},
|
||||
'spd': {
|
||||
'rp': 'Catcher throws to first and hits the batter-runner in the back, SI*',
|
||||
'e1': 'Error, batter to first, runners advance 1 base.',
|
||||
'e2': 'Error, batter to second, runners advance 2 bases.',
|
||||
'no': 'Speed check, Batter\'s safe range = Running; if safe, SI*; if out, gbC'
|
||||
},
|
||||
}
|
||||
OUTFIELD_X_CHART = {
|
||||
'si2': {
|
||||
@ -646,8 +642,10 @@ class SelectPaperdexCardset(discord.ui.Select):
|
||||
discord.SelectOption(label='2022 Promos'),
|
||||
discord.SelectOption(label='2021 Season'),
|
||||
discord.SelectOption(label='2019 Season'),
|
||||
discord.SelectOption(label='2016 Season'),
|
||||
discord.SelectOption(label='2013 Season'),
|
||||
discord.SelectOption(label='2012 Season'),
|
||||
discord.SelectOption(label='2008 Season'),
|
||||
discord.SelectOption(label='Mario Super Sluggers')
|
||||
]
|
||||
super().__init__(placeholder='Select a Cardset', options=options)
|
||||
@ -671,6 +669,10 @@ class SelectPaperdexCardset(discord.ui.Select):
|
||||
cardset_id = 8
|
||||
elif self.values[0] == '2023 Season':
|
||||
cardset_id = 9
|
||||
elif self.values[0] == '2016 Season':
|
||||
cardset_id = 11
|
||||
elif self.values[0] == '2008 Season':
|
||||
cardset_id = 12
|
||||
|
||||
c_query = await db_get('cardsets', object_id=cardset_id, none_okay=False)
|
||||
await interaction.response.edit_message(content=f'Okay, sifting through your cards...', view=None)
|
||||
@ -802,8 +804,10 @@ class SelectBuyPacksCardset(discord.ui.Select):
|
||||
discord.SelectOption(label='2022 Season'),
|
||||
discord.SelectOption(label='2021 Season'),
|
||||
discord.SelectOption(label='2019 Season'),
|
||||
discord.SelectOption(label='2016 Season'),
|
||||
discord.SelectOption(label='2013 Season'),
|
||||
discord.SelectOption(label='2012 Season')
|
||||
discord.SelectOption(label='2012 Season'),
|
||||
discord.SelectOption(label='2008 Season')
|
||||
]
|
||||
self.team = team
|
||||
self.quantity = quantity
|
||||
@ -827,6 +831,10 @@ class SelectBuyPacksCardset(discord.ui.Select):
|
||||
cardset_id = 7
|
||||
elif self.values[0] == '2023 Season':
|
||||
cardset_id = 9
|
||||
elif self.values[0] == '2016 Season':
|
||||
cardset_id = 11
|
||||
elif self.values[0] == '2008 Season':
|
||||
cardset_id = 12
|
||||
|
||||
self.pack_embed.description = f'{self.pack_embed.description} - {self.values[0]}'
|
||||
view = Confirm(responders=[interaction.user], timeout=30)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user