Migrate get_current() to db_get

This commit is contained in:
Cal Corum 2023-06-27 10:18:58 -05:00
parent 2c8e20e614
commit ac34c5dd10
8 changed files with 86 additions and 88 deletions

View File

@ -20,7 +20,7 @@ class Admins(commands.Cog):
@commands.command(name='current', help='Current db info')
@commands.is_owner()
async def current_command(self, ctx):
current = await get_current()
current = await db_get('current')
current_string = ''
for x in current:
@ -40,7 +40,7 @@ class Admins(commands.Cog):
async def blast_slash(
self, interaction: discord.Interaction, channel: discord.TextChannel, msg_content: str = None,
embed_title: str = None, embed_field_name: str = None, image_url: str = None, color_hex: str = None):
current = await get_current()
current = await db_get('current')
try:
embed = None
@ -83,13 +83,13 @@ class Admins(commands.Cog):
#
# await send_to_channel(self.bot, 'general', freeze_message)
current = await patch_current(freeze=False)
current = await db_get('current')
await ctx.send(f'Current: {current}')
@commands.command(name='sendmoves', help='Send moves to sheets')
@commands.is_owner()
async def send_moves_command(self, ctx):
current = await get_current()
current = await db_get('current')
await ctx.send('Authenticating with sheets...')
sheets = pygsheets.authorize(service_file='storage/major-domo-service-creds.json')
trans_tab = sheets.open_by_key(SBA_ROSTER_KEY).worksheet_by_title('Transactions')
@ -131,7 +131,7 @@ class Admins(commands.Cog):
@commands.command(name='xpick', help='Expansion pick')
@commands.is_owner()
async def expansion_pick_command(self, ctx, team_abbrev, *, name):
current = await get_current()
current = await db_get('current')
player_cog = self.bot.get_cog('Players')
player_name = await fuzzy_player_search(ctx, ctx.channel, self.bot, name, player_cog.player_list.keys())
player = await get_one_player(player_name)

View File

@ -47,7 +47,7 @@ class Dice(commands.Cog):
@tasks.loop(minutes=5)
async def updates(self):
self.current = await get_current()
self.current = await db_get('current')
if len(self.rolls) > 0:
all_rolls = self.rolls
self.rolls = []

View File

@ -41,7 +41,7 @@ class Draft(commands.Cog):
# Timer is active and pick is due
if draft_data['timer'] and deadline:
current = await get_current()
current = await db_get('current')
draft_pick = await get_one_draftpick_byoverall(current['season'], draft_data['currentpick'])
team_role = get_team_role(None, draft_pick['owner'], self.bot)
@ -59,7 +59,7 @@ class Draft(commands.Cog):
else:
# # Slow Draft
# if (deadline - datetime.timedelta(hours=10) <= now) and self.warnings == 0:
# current = await get_current()
# current = await db_get('current')
# draft_pick = await get_one_draftpick_byoverall(current['season'], draft_data['currentpick'])
# team_role = get_team_role(None, draft_pick['owner'], self.bot)
# await send_to_channel(
@ -70,7 +70,7 @@ class Draft(commands.Cog):
# )
# self.warnings = 1
# elif (deadline - datetime.timedelta(hours=6) <= now) and self.warnings == 1:
# current = await get_current()
# current = await db_get('current')
# draft_pick = await get_one_draftpick_byoverall(current['season'], draft_data['currentpick'])
# team_role = get_team_role(None, draft_pick['owner'], self.bot)
# await send_to_channel(
@ -81,7 +81,7 @@ class Draft(commands.Cog):
# )
# self.warnings = 2
# elif (deadline - datetime.timedelta(hours=2) <= now) and self.warnings == 2:
# current = await get_current()
# current = await db_get('current')
# draft_pick = await get_one_draftpick_byoverall(current['season'], draft_data['currentpick'])
# team_role = get_team_role(None, draft_pick['owner'], self.bot)
# await send_to_channel(
@ -92,7 +92,7 @@ class Draft(commands.Cog):
# )
# self.warnings = 3
# elif (deadline - datetime.timedelta(hours=1) <= now) and self.warnings == 3:
# current = await get_current()
# current = await db_get('current')
# draft_pick = await get_one_draftpick_byoverall(current['season'], draft_data['currentpick'])
# team_role = get_team_role(None, draft_pick['owner'], self.bot)
# await send_to_channel(
@ -103,7 +103,7 @@ class Draft(commands.Cog):
# )
# self.warnings = 4
# elif (deadline - datetime.timedelta(minutes=5) <= now) and self.warnings == 4:
# current = await get_current()
# current = await db_get('current')
# draft_pick = await get_one_draftpick_byoverall(current['season'], draft_data['currentpick'])
# team_role = get_team_role(None, draft_pick['owner'], self.bot)
# await send_to_channel(
@ -137,7 +137,7 @@ class Draft(commands.Cog):
await patch_draftdata(pick_deadline=deadline)
async def send_draft_ping(self, ping=True):
current = await get_current()
current = await db_get('current')
draft_data = await get_draftdata()
logging.info(f'current: {current}\nd_data: {draft_data}')
this_pick = await get_one_draftpick_byoverall(current['season'], draft_data['currentpick'])
@ -233,7 +233,7 @@ class Draft(commands.Cog):
await send_to_channel(self.bot, draft_data['ping_channel'], content=team_ping, embed=embed)
async def advance_pick(self):
current = await get_current()
current = await db_get('current')
draft_data = await get_draftdata()
draft_pick = await get_one_draftpick_byoverall(current['season'], draft_data['currentpick'])
@ -401,7 +401,7 @@ class Draft(commands.Cog):
# @commands.command(name='start', help='Start pick timer')
# @commands.is_owner()
# async def advance_draft_command(self, ctx):
# current = await get_current()
# current = await db_get('current')
# draft_data = await get_draftdata()
# draft_pick = await get_one_draftpick_byoverall(current['season'], draft_data['currentpick'])
#
@ -421,7 +421,7 @@ class Draft(commands.Cog):
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
async def draft_command(self, ctx, *, name):
cal_can_pick_for_all = True
current = await get_current()
current = await db_get('current')
team = await get_team_by_owner(current['season'], ctx.author.id)
if not team:
await ctx.message.add_reaction('')
@ -476,7 +476,7 @@ class Draft(commands.Cog):
@commands.command(name='list', aliases=['draftlist', 'mylist'], help='Set your draft list')
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
async def draft_list_command(self, ctx, *player_list):
current = await get_current()
current = await db_get('current')
team = await get_team_by_owner(current['season'], ctx.author.id)
if not team:
await react_and_reply(ctx, '', 'I don\'t know youuuuuuuuu')
@ -538,7 +538,7 @@ class Draft(commands.Cog):
@commands.command(name='whomst', aliases=['draftstatus'], help='Get draft status')
async def draft_status_command(self, ctx):
current = await get_current()
current = await db_get('current')
draft_data = await get_draftdata()
await ctx.send(await self.draftdata_to_string(current, draft_data))
@ -564,7 +564,7 @@ class Draft(commands.Cog):
ping_channel: TextChannel = None, current_overall: int = None, timer_master: int = None,
timer_this_pick: int = None, timer_active: bool = None, wipe_pick: int = None):
await interaction.response.defer()
current = await get_current()
current = await db_get('current')
draft_data = await get_draftdata()
pick_deadline = None
@ -737,7 +737,7 @@ class Draft(commands.Cog):
# @commands.command(name='keeper', help='Set keeper slots')
# @commands.is_owner()
# async def keeper_command(self, ctx, team_abbrev, draft_round, *, name):
# current = await get_current()
# current = await db_get('current')
# this_team = await get_one_team(team_abbrev)
# if not this_team:
# await ctx.send(f'Are you familiar with this league? Who the fuck is **{team_abbrev}**?')
@ -765,7 +765,7 @@ class Draft(commands.Cog):
# @commands.command(name='cutem', help='Release non-keepers')
# @commands.is_owner()
# async def cutem_command(self, ctx, team_abbrev):
# current = await get_current()
# current = await db_get('current')
# if current['week'] == -2:
# await ctx.send('Advance the week and run transactions before running this.')
# return
@ -986,7 +986,7 @@ class Draft(commands.Cog):
# @commands.command(name='dropmildem', help='Remove MiL demotion week', hidden=True)
# @commands.is_owner()
# async def drop_mil_demotion_command(self, ctx):
# current = await get_current()
# current = await db_get('current')
# await ctx.send('I\'m fuckin on it')
# return_string = ''
# for x in range(99, 154):
@ -1006,7 +1006,7 @@ class Draft(commands.Cog):
# @commands.command(name='keepers', help='Set keepers', hidden=True)
# @commands.is_owner()
# async def keepers_command(self, ctx, team_abbrev, *, player_names):
# current = await get_current()
# current = await db_get('current')
# player_list = []
#
# this_team = await get_one_team(team_abbrev)

View File

@ -80,6 +80,9 @@ class Fun(commands.Cog):
logging.error(f'Could not run daily_check: {e}')
return
if guild.id != 613880856032968834:
logging.info(f'Not checking CCs outside of SBa server')
return
# <discordid> = {'member': <discord member>, 'commands': [(<command.name>, <command.message>)]}
del_notifs = {}
del_counter = 0
@ -433,7 +436,7 @@ class Fun(commands.Cog):
day_or_night: Literal['day', 'night'] = 'night',
result: Literal['no-doubt', 'bp-homerun', 'bp-flyout'] = 'bp-homerun', d20: int = None):
await interaction.response.defer()
current = await get_current()
current = await db_get('current')
team = await get_team_by_owner(current['season'], interaction.user.id)
result_text = 'Home Run'

View File

@ -798,7 +798,7 @@ class Gameday(commands.Cog):
@commands.command(name='newgame', aliases=['ng'], help='Start a new game')
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME, PD_PLAYERS_ROLE_NAME)
async def new_game_command(self, ctx):
current = await get_current()
current = await db_get('current')
this_team = await get_team_by_owner(current['season'], ctx.author.id)
await ctx.send('**Note:** Make sure this is the channel where you will be playing commands. Once this is set, '
@ -908,7 +908,7 @@ class Gameday(commands.Cog):
'Examples:\n1-Ronald Acuna Jr-RF,2-Trea Turner-SS,3-Robinson Cano-2B\n' \
'7-Travis Jankowski-LF,10-Anthony Bass-P,5-Erik Gonzalez-3B'
# current = await get_current()
# current = await db_get('current')
this_team = await get_one_team(team_abbrev)
this_game = get_game(channel_id=ctx.channel.id, active=1)
logging.info(f'this_game: {this_game}')
@ -1024,7 +1024,7 @@ class Gameday(commands.Cog):
@commands.command(name='gamestate', aliases=['gs'], help='Show game state')
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME, PD_PLAYERS_ROLE_NAME)
async def game_state_command(self, ctx):
# current = await get_current()
# current = await db_get('current')
this_game = get_game(channel_id=ctx.channel.id, active=1)
await ctx.send(content=None, embed=await self.game_state_embed(this_game))
@ -1971,7 +1971,7 @@ class Gameday(commands.Cog):
)
this_player = await get_one_player(this_member['player_id'])
await ctx.send(content=None, embed=await get_player_embed(this_player, await get_current()))
await ctx.send(content=None, embed=await get_player_embed(this_player, await db_get('current')))
@show_data.command(name='batter', help='Show batter card')
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME, PD_PLAYERS_ROLE_NAME)
@ -1996,7 +1996,7 @@ class Gameday(commands.Cog):
)
this_player = await get_one_player(this_member['player_id'])
await ctx.send(content=None, embed=await get_player_embed(this_player, await get_current()))
await ctx.send(content=None, embed=await get_player_embed(this_player, await db_get('current')))
@show_data.command(
name='position',
@ -2012,7 +2012,7 @@ class Gameday(commands.Cog):
logging.info(f'pos: {pos}')
this_player = await get_one_player(self.get_defender(this_game, pos)['player_id'])
await ctx.send(content=None, embed=await get_player_embed(this_player, await get_current()))
await ctx.send(content=None, embed=await get_player_embed(this_player, await db_get('current')))
@show_data.command(name='runner', help='!show runner <base_num>')
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME, PD_PLAYERS_ROLE_NAME)
@ -2031,7 +2031,7 @@ class Gameday(commands.Cog):
return
this_player = await get_one_player(runner_id)
await ctx.send(content=None, embed=await get_player_embed(this_player, await get_current()))
await ctx.send(content=None, embed=await get_player_embed(this_player, await db_get('current')))
@commands.command(name='stats', aliases=['tocsv'], help='Get current stats')
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME, PD_PLAYERS_ROLE_NAME)

View File

@ -315,7 +315,7 @@ class Transactions(commands.Cog):
logging.error(f'Could not run weekly_loop: {e}')
return
current = await get_current()
current = await db_get('current')
now = datetime.datetime.now()
logging.info(f'Datetime: {now} / weekday: {now.weekday()}')
@ -479,7 +479,7 @@ class Transactions(commands.Cog):
async def send_move_to_sheets(self, move_id):
return
current = await get_current()
current = await db_get('current')
sheets = pygsheets.authorize(service_file='storage/major-domo-service-creds.json')
trans_tab = sheets.open_by_key(SBA_ROSTER_KEY).worksheet_by_title('Transactions')
all_vals = []
@ -509,7 +509,7 @@ class Transactions(commands.Cog):
await send_to_channel(self.bot, 'commissioners-office', f'Failed sending move {move_id} to sheets')
async def post_move_to_transaction_log(self, move_id):
current = await get_current()
current = await db_get('current')
all_moves = await get_transactions(
season=current['season'],
move_id=move_id
@ -537,7 +537,7 @@ class Transactions(commands.Cog):
await send_to_channel(self.bot, 'transaction-log', embed=embed)
async def send_stats_to_sheets(self, channel='commissioners-office', which='all'):
current = await get_current()
current = await db_get('current')
b_stats = None
p_stats = None
@ -594,11 +594,11 @@ class Transactions(commands.Cog):
async def update_roster_sheet(self, season):
logging.info(f'calling the db')
# csv_data = db_get('players', api_ver=2, params=[('season', 6), ('csv', True)], as_csv=True)
# csv_data = db_get('players', api_ver=3, params=[('season', 6), ('csv', True)], as_csv=True)
# csv = DataFrame(csv_data).to_csv(header=False, index=False)
# csv = pandas.read_csv(csv_data)
ap = await db_get('players', api_ver=2, timeout=8, params=[('season', season)])
ap = await db_get('players', api_ver=3, timeout=8, params=[('season', season)])
player_data = [
['name', 'sWAR', 'image', 'vanity_card', 'team_abbrev', 'inj_rat', 'pos_1', 'pos_2', 'pos_3', 'pos_4',
'pos_5', 'pos_6', 'pos_7', 'pos_8', 'last_game', 'last_game2', 'il_return', 'dem_week', 'strat_code',
@ -642,7 +642,7 @@ class Transactions(commands.Cog):
@commands.command(name='run_transactions')
@commands.is_owner()
async def run_transactions_helper_command(self, ctx):
current = await get_current()
current = await db_get('current')
await self.run_transactions(current)
await self.update_roster_sheet(current['season'])
await ctx.send(new_rand_conf_gif())
@ -650,7 +650,7 @@ class Transactions(commands.Cog):
@commands.command(name='process_freeze')
@commands.is_owner()
async def process_freeze_helper_command(self, ctx):
current = await get_current()
current = await db_get('current')
await self.process_freeze_moves(current)
await self.update_roster_sheet(current['season'])
await ctx.send(random_conf_gif())
@ -658,7 +658,7 @@ class Transactions(commands.Cog):
@commands.command(name='trade', help='Trade players')
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
async def trade_command(self, ctx):
current = await get_current()
current = await db_get('current')
if current['week'] > current['trade_deadline']:
await ctx.send(await get_emoji(ctx, 'oof', False))
@ -1003,7 +1003,7 @@ class Transactions(commands.Cog):
@commands.command(name='picktrade', help='Trade draft picks', hidden=True)
@commands.is_owner()
async def pick_trade_command(self, ctx):
current = await get_current()
current = await db_get('current')
if current['week'] < -2:
await ctx.send(await get_emoji(ctx, 'oof', False))
@ -1218,7 +1218,7 @@ class Transactions(commands.Cog):
@commands.command(name='dropadd', aliases=['drop', 'add', 'adddrop', 'longil'], help='FA/MiL moves')
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
async def drop_add_command(self, ctx):
current = await get_current()
current = await db_get('current')
team = await get_team_by_owner(current['season'], ctx.author.id)
team_schedule = await get_schedule(
current['season'],
@ -1484,7 +1484,7 @@ class Transactions(commands.Cog):
@commands.command(name='ilmove', help='IL move')
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
async def il_move_command(self, ctx):
current = await get_current()
current = await db_get('current')
if OFFSEASON_FLAG:
await ctx.send(await get_emoji(ctx, 'oof', False))
@ -1770,7 +1770,7 @@ class Transactions(commands.Cog):
@commands.command(name='mymoves', help='Show upcoming moves')
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
async def my_moves_command(self, ctx):
current = await get_current()
current = await db_get('current')
team = await get_team_by_owner(current['season'], ctx.author.id)
set_moves = await get_transactions(
current['season'],
@ -1826,7 +1826,7 @@ class Transactions(commands.Cog):
@commands.command(name='legal', help='Check roster legality')
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
async def legal_command(self, ctx, *team_abbrev):
current = await get_current()
current = await db_get('current')
if team_abbrev:
this_team = await get_one_team(team_abbrev[0])
else:
@ -1945,7 +1945,7 @@ class Transactions(commands.Cog):
@commands.command(name='tomil', help='Post-draft demotions')
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
async def to_mil_command(self, ctx, *player_list):
current = await get_current()
current = await db_get('current')
team = await get_team_by_owner(current['season'], owner_id=ctx.author.id)
il_team = await get_one_team(f'{team["abbrev"]}MiL')
@ -2014,7 +2014,7 @@ class Transactions(commands.Cog):
@commands.command(name='calisamazing', help='Make up for your idiocy')
async def cal_is_amazing_command(self, ctx):
current = await get_current()
current = await db_get('current')
team = await get_team_by_owner(current['season'], owner_id=ctx.author.id)
if not team:
@ -2032,7 +2032,7 @@ class Transactions(commands.Cog):
@commands.command(name='force_roster', help='Mod: Force update roster sheet')
async def force_roster_command(self, ctx):
current = await get_current()
current = await db_get('current')
message = await ctx.send('On it...')
fake_move = SBaTransaction(ctx.channel, current, 'dropadd')
await self.update_roster_sheet(season=current['season'])

View File

@ -7,8 +7,8 @@ import csv
AUTH_TOKEN = {'Authorization': f'Bearer {os.environ.get("API_TOKEN")}'}
DB_URL = 'http://database/api'
# DB_URL = 'https://sombaseball.ddns.net/api'
# DB_URL = 'http://database/api'
DB_URL = 'https://sba.manticorum.com/api'
master_debug = True
@ -19,7 +19,7 @@ def param_char(other_params):
return '?'
def get_req_url(endpoint: str, api_ver: int = 1, object_id: int = None, params: list = None):
def get_req_url(endpoint: str, api_ver: int = 3, object_id: int = None, params: list = None):
# Checking for hard-coded url
if '/api/' in endpoint:
return endpoint
@ -34,7 +34,7 @@ def get_req_url(endpoint: str, api_ver: int = 1, object_id: int = None, params:
return req_url
async def db_get(endpoint: str, api_ver: int = 1, object_id: int = None, params: list = None, none_okay: bool = True,
async def db_get(endpoint: str, api_ver: int = 3, object_id: int = None, params: list = None, none_okay: bool = True,
timeout: int = 3):
req_url = get_req_url(endpoint, api_ver=api_ver, object_id=object_id, params=params)
log_string = f'get:\n{endpoint} id: {object_id} params: {params}'
@ -74,7 +74,7 @@ async def db_get(endpoint: str, api_ver: int = 1, object_id: int = None, params:
raise ValueError(f'DB: {resp.text}')
async def db_patch(endpoint: str, object_id: int, params: list, api_ver: int = 1, timeout: int = 3):
async def db_patch(endpoint: str, object_id: int, params: list, api_ver: int = 3, timeout: int = 3):
req_url = get_req_url(endpoint, api_ver=api_ver, object_id=object_id, params=params)
log_string = f'patch:\n{endpoint} {params}'
logging.info(log_string) if master_debug else logging.debug(log_string)
@ -105,7 +105,7 @@ async def db_patch(endpoint: str, object_id: int, params: list, api_ver: int = 1
raise ValueError(f'DB: {resp.text}')
async def db_post(endpoint: str, api_ver: int = 1, payload: dict = None, timeout: int = 3):
async def db_post(endpoint: str, api_ver: int = 3, payload: dict = None, timeout: int = 3):
req_url = get_req_url(endpoint, api_ver=api_ver)
log_string = f'post:\n{endpoint} payload: {payload}\ntype: {type(payload)}'
logging.info(log_string) if master_debug else logging.debug(log_string)
@ -136,7 +136,7 @@ async def db_post(endpoint: str, api_ver: int = 1, payload: dict = None, timeout
raise ValueError(f'DB: {resp.text}')
async def db_delete(endpoint: str, object_id: int, api_ver: int = 1, timeout=3):
async def db_delete(endpoint: str, object_id: int, api_ver: int = 3, timeout=3):
req_url = get_req_url(endpoint, api_ver=api_ver, object_id=object_id)
log_string = f'delete:\n{endpoint} {object_id}'
logging.info(log_string) if master_debug else logging.debug(log_string)

View File

@ -792,7 +792,9 @@ async def send_to_channel(bot, channel_name, content=None, embed=None):
await this_channel.send(content=content, embed=embed)
async def get_player_embed(player, current, ctx=None):
async def get_player_embed(player, current, ctx=None, season=None):
if season is None:
season = current['season']
player_name = player['name']
if player['il_return']:
if player['team']['abbrev'][-2:].lower() == 'il':
@ -812,18 +814,15 @@ async def get_player_embed(player, current, ctx=None):
if player_photo:
embed.set_thumbnail(url=player_photo)
player_trans = await get_transactions(
current['season'],
week_start=current['week'],
week_end=current['week'] + 1,
player_id=player['id']
)
for x in player_trans:
if player_trans[x]['week'] == current['week']:
embed.add_field(name='Last Week', value=f'{player_trans[x]["oldteam"]["sname"]}')
if player_trans[x]['week'] == current['week'] + 1:
embed.add_field(name='Next Week', value=f'To {player_trans[x]["newteam"]["sname"]}')
t_query = await db_get('transactions', params=[
('season', current['season']), ('week_start', current['week']), ('week_end', current['week'] + 1),
('player_id', player['id'])
])
for x in t_query['transactions']:
if x['week'] == current['week']:
embed.add_field(name='Last Week', value=f'{x["oldteam"]["sname"]}')
if x['week'] == current['week'] + 1:
embed.add_field(name='Next Week', value=f'To {x["newteam"]["sname"]}')
embed.add_field(name='sWAR', value=player['wara'])
embed.set_image(url=player['image'])
@ -858,24 +857,15 @@ async def get_player_embed(player, current, ctx=None):
if player['demotion_week'] > current['week']:
embed.add_field(name='Dem Week', value=player["demotion_week"])
player_awards = await get_awards(season=current['season'], player_name=player['name'])
awards = []
if len(player_awards) > 0:
for x in player_awards:
awards.append(player_awards[x]['name'])
award_string = ', '.join(awards[-3:])
if len(awards) > 3:
award_string += f', plus {len(awards) - 3} more'
embed.add_field(name='Awards', value=award_string, inline=False)
b = await get_one_battingseason(player['id'])
p = await get_one_pitchingseason(player['id'])
b, p = None, None
batting_string = None
pitching_string = None
batter_priority = True
b_query = await db_get('battingstats/totals', params=[('season', season), ('player_id', player['id'])])
if b_query['count'] > 0:
b = b_query['stats'][0]
if len(b) > 0:
if b['ab'] > 0:
singles = b['hit'] - b['hr'] - b['triple'] - b['double']
avg = b['hit'] / b['ab']
@ -902,14 +892,19 @@ async def get_player_embed(player, current, ctx=None):
f'{ab: >3} {run: >2} {hit: ^3} {double: >2} {triple: >2} {hr: >2} {rbi: >3} ' \
f'{sb: >2} {so: ^3}\n```'
if len(p) > 0:
p_query = await db_get('pitchingstats/totals', params=[('season', season), ('player_id', player['id'])])
if p_query['count'] > 0:
p = p_query['stats'][0]
if p['ip'] > 0:
if b is not None and p['ip'] > b['pa']:
batter_priority = False
win = f'{p["win"]:.0f}'
loss = f'{p["loss"]:.0f}'
save = f'{p["sv"]:.0f}'
era = f'{(p["erun"] * 9) / p["ip"]:.2f}'
game = f'{p["game"]:.0f}'
gs = f'{p["gs"]:.0f}'
# game = f'{p["game"]:.0f}'
# gs = f'{p["gs"]:.0f}'
ip = f'{p["ip"]:.0f}'
if p["ip"] % 1 == 0:
ip += '.0'
@ -924,11 +919,11 @@ async def get_player_embed(player, current, ctx=None):
f'{win: >2} {loss: >2} {save: >2} {era: >5} {ip: >5} ' \
f'{so: >3} {whip: >4}\n```'
if batting_string and len(b) > len(p):
if batting_string and batter_priority:
embed.add_field(name='Batting Stats', value=batting_string, inline=False)
if pitching_string:
embed.add_field(name='Pitching Stats', value=pitching_string, inline=False)
if batting_string and len(p) >= len(b):
if batting_string and not batter_priority:
embed.add_field(name='Batting Stats', value=batting_string, inline=False)
return embed