Update calls for /current to new Current class
This commit is contained in:
parent
50d0f89c1d
commit
afba7ce456
278
cogs/admins.py
278
cogs/admins.py
@ -1,5 +1,7 @@
|
||||
import copy
|
||||
|
||||
from api_calls.current import get_current
|
||||
from exceptions import ApiException, log_exception
|
||||
from helpers import *
|
||||
from db_calls import db_get, db_patch, db_post, put_player, get_player_by_name, patch_draftpick
|
||||
|
||||
@ -20,13 +22,9 @@ class Admins(commands.Cog):
|
||||
@commands.command(name='current', help='Current db info')
|
||||
@commands.is_owner()
|
||||
async def current_command(self, ctx):
|
||||
current = await db_get('current')
|
||||
current_string = ''
|
||||
current = await get_current()
|
||||
|
||||
for x in current:
|
||||
current_string += f'{x}: {current[x]}\n'
|
||||
|
||||
await ctx.send(current_string)
|
||||
await ctx.send(f'{current}')
|
||||
|
||||
@commands.command(name='blast', help='Megaphone')
|
||||
@commands.is_owner()
|
||||
@ -35,12 +33,11 @@ class Admins(commands.Cog):
|
||||
await ctx.send(random_conf_gif())
|
||||
|
||||
@app_commands.command(name='blast', description='Send a message')
|
||||
@app_commands.guilds(discord.Object(id=os.environ.get('GUILD_ID')))
|
||||
@app_commands.guilds(discord.Object(id=os.environ.get('GUILD_ID', 0)))
|
||||
@app_commands.checks.has_any_role('Da Commish')
|
||||
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 db_get('current')
|
||||
self, interaction: discord.Interaction, channel: discord.TextChannel, msg_content: Optional[str] = None, embed_title: Optional[str] = None, embed_field_name: Optional[str] = None, image_url: Optional[str] = None, color_hex: Optional[str] = None):
|
||||
current = await get_current()
|
||||
|
||||
try:
|
||||
embed = None
|
||||
@ -49,7 +46,7 @@ class Admins(commands.Cog):
|
||||
title=embed_title,
|
||||
color=int(color_hex, 16) if color_hex is not None else int('0xa5fffc', 16)
|
||||
)
|
||||
embed.set_footer(text=f'SBa Season {current["season"]}', icon_url=LOGO)
|
||||
embed.set_footer(text=f'SBa Season {current.season}', icon_url=LOGO)
|
||||
embed.set_image(url=image_url)
|
||||
if embed_field_name:
|
||||
embed.add_field(
|
||||
@ -95,7 +92,7 @@ class Admins(commands.Cog):
|
||||
|
||||
# Try to get card
|
||||
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
try:
|
||||
sheets = pygsheets.authorize(service_file='storage/major-domo-service-creds.json')
|
||||
scorecard = sheets.open_by_url(sheet_url)
|
||||
@ -109,26 +106,31 @@ class Admins(commands.Cog):
|
||||
g_data = setup_tab.get_values('M2', 'R3')
|
||||
at_abbrev = g_data[0][0]
|
||||
ht_abbrev = g_data[1][0]
|
||||
away_team = await get_team_by_abbrev(at_abbrev, current['season'])
|
||||
home_team = await get_team_by_abbrev(ht_abbrev, current['season'])
|
||||
away_team = await get_team_by_abbrev(at_abbrev, current.season)
|
||||
home_team = await get_team_by_abbrev(ht_abbrev, current.season)
|
||||
week_num = g_data[0][5]
|
||||
game_num = g_data[1][5]
|
||||
|
||||
if not away_team:
|
||||
log_exception(ApiException(f'Season {current.season} {at_abbrev} was not found'))
|
||||
if not home_team:
|
||||
log_exception(ApiException(f'Season {current.season} {ht_abbrev} was not found'))
|
||||
|
||||
logger.info(f'gdata: {g_data}\nweek/game: {week_num}/{game_num}')
|
||||
|
||||
dupe_g_query = await db_get('games', params=[
|
||||
('season', current['season']), ('week_start', week_num), ('week_end', week_num),
|
||||
('season', current.season), ('week_start', week_num), ('week_end', week_num),
|
||||
('away_team_id', away_team['id']), ('home_team_id', home_team['id']), ('game_num', game_num)
|
||||
])
|
||||
if dupe_g_query['count'] != 0:
|
||||
if dupe_g_query and dupe_g_query.get('count'):
|
||||
await ctx.send(f'This game has already been played! Maybe one day I can automatically wipe it for you.')
|
||||
return
|
||||
|
||||
g_query = await db_get('games', params=[
|
||||
('season', current['season']), ('week_start', week_num), ('week_end', week_num),
|
||||
('season', current.season), ('week_start', week_num), ('week_end', week_num),
|
||||
('away_team_id', away_team['id']), ('home_team_id', home_team['id'])
|
||||
])
|
||||
if g_query['count'] == 0:
|
||||
if not g_query or not g_query.get('count'):
|
||||
await ctx.send(
|
||||
f'I don\'t see any games between {away_team["abbrev"]} and {home_team["abbrev"]} in week {week_num}.'
|
||||
)
|
||||
@ -175,7 +177,7 @@ class Admins(commands.Cog):
|
||||
# await ctx.send('Collecting transactions...')
|
||||
# all_vals = []
|
||||
# all_moves = await get_transactions(
|
||||
# season=current['season'],
|
||||
# season=current.season,
|
||||
# timeout=30
|
||||
# )
|
||||
# await ctx.send(f'Processing transactions ({len(all_moves)} found)...')
|
||||
@ -248,153 +250,153 @@ class Admins(commands.Cog):
|
||||
@commands.command(name='setdemweek', help='Set player\'s demotion week')
|
||||
@commands.is_owner()
|
||||
async def set_dem_week_command(self, ctx, week_num, *, player_name):
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
player_cog = self.bot.get_cog('Players')
|
||||
player_name = await fuzzy_player_search(ctx, ctx.channel, self.bot, player_name, player_cog.player_list.keys())
|
||||
# player = await get_one_player(player_name)
|
||||
p_query = await db_get('players', params=[('season', current['season']), ('name', player_name)])
|
||||
p_query = await db_get('players', params=[('season', current.season), ('name', player_name)])
|
||||
player = p_query['players'][0]
|
||||
player['demotion_week'] = week_num
|
||||
|
||||
await put_player(player)
|
||||
await ctx.send(random_conf_gif())
|
||||
|
||||
@app_commands.command(name='set-keepers', description='Post final keepers')
|
||||
@app_commands.guilds(discord.Object(id=os.environ.get('GUILD_ID')))
|
||||
# @app_commands.checks.has_any_role('Da Commish')
|
||||
async def keeper_slash(
|
||||
self, interaction: discord.Interaction, keeper_1_name: str,
|
||||
keeper_2_name: Optional[str] = None, keeper_3_name: Optional[str] = None,
|
||||
keeper_4_name: Optional[str] = None, keeper_5_name: Optional[str] = None,
|
||||
keeper_6_name: Optional[str] = None, keeper_7_name: Optional[str] = None,
|
||||
team_abbrev: Optional[str] = None):
|
||||
if interaction.channel.name == 'season-9-chat':
|
||||
await interaction.response.send_message(f'everybody laugh at {interaction.user.display_name} for trying '
|
||||
f'to run keepers here')
|
||||
return
|
||||
# @app_commands.command(name='set-keepers', description='Post final keepers')
|
||||
# @app_commands.guilds(discord.Object(id=os.environ.get('GUILD_ID')))
|
||||
# # @app_commands.checks.has_any_role('Da Commish')
|
||||
# async def keeper_slash(
|
||||
# self, interaction: discord.Interaction, keeper_1_name: str,
|
||||
# keeper_2_name: Optional[str] = None, keeper_3_name: Optional[str] = None,
|
||||
# keeper_4_name: Optional[str] = None, keeper_5_name: Optional[str] = None,
|
||||
# keeper_6_name: Optional[str] = None, keeper_7_name: Optional[str] = None,
|
||||
# team_abbrev: Optional[str] = None):
|
||||
# if interaction.channel.name == 'season-9-chat':
|
||||
# await interaction.response.send_message(f'everybody laugh at {interaction.user.display_name} for trying '
|
||||
# f'to run keepers here')
|
||||
# return
|
||||
|
||||
await interaction.response.defer()
|
||||
current = await db_get('current')
|
||||
# await interaction.response.defer()
|
||||
# current = await get_current()
|
||||
|
||||
if current['week'] != -1:
|
||||
logger.info('entering the thot check')
|
||||
await interaction.edit_original_response(content='https://c.tenor.com/FCAj8xDvEHwAAAAC/be-gone-thot.gif')
|
||||
player_role = get_role(interaction, SBA_PLAYERS_ROLE_NAME)
|
||||
logger.info('beginning sleep')
|
||||
await asyncio.sleep(random.randint(3, 7))
|
||||
# if current.week != -1:
|
||||
# logger.info('entering the thot check')
|
||||
# await interaction.edit_original_response(content='https://c.tenor.com/FCAj8xDvEHwAAAAC/be-gone-thot.gif')
|
||||
# player_role = get_role(interaction, SBA_PLAYERS_ROLE_NAME)
|
||||
# logger.info('beginning sleep')
|
||||
# await asyncio.sleep(random.randint(3, 7))
|
||||
|
||||
try:
|
||||
await interaction.user.remove_roles(player_role)
|
||||
except Exception as e:
|
||||
logger.error(f'unable to remove {player_role} role from {interaction.user}: {e}')
|
||||
# try:
|
||||
# await interaction.user.remove_roles(player_role)
|
||||
# except Exception as e:
|
||||
# logger.error(f'unable to remove {player_role} role from {interaction.user}: {e}')
|
||||
|
||||
return
|
||||
# return
|
||||
|
||||
owner_team = await get_team_by_owner(current['season'], interaction.user.id)
|
||||
# owner_team = await get_team_by_owner(current.season, interaction.user.id)
|
||||
|
||||
if team_abbrev is not None and interaction.user.id != 258104532423147520 and \
|
||||
team_abbrev != owner_team['abbrev']:
|
||||
await interaction.edit_original_response(
|
||||
content='Omg you are so quirky and random trying to set another team\'s keepers.')
|
||||
return
|
||||
else:
|
||||
team_abbrev = owner_team['abbrev']
|
||||
this_team = await get_team_by_abbrev(team_abbrev, current['season'])
|
||||
# if team_abbrev is not None and interaction.user.id != 258104532423147520 and \
|
||||
# team_abbrev != owner_team['abbrev']:
|
||||
# await interaction.edit_original_response(
|
||||
# content='Omg you are so quirky and random trying to set another team\'s keepers.')
|
||||
# return
|
||||
# else:
|
||||
# team_abbrev = owner_team['abbrev']
|
||||
# this_team = await get_team_by_abbrev(team_abbrev, current.season)
|
||||
|
||||
if this_team is None:
|
||||
await interaction.edit_original_response(content=f'Team {team_abbrev} not found')
|
||||
return
|
||||
# if this_team is None:
|
||||
# await interaction.edit_original_response(content=f'Team {team_abbrev} not found')
|
||||
# return
|
||||
|
||||
def get_pos_nickname(position):
|
||||
if 'B' in position:
|
||||
return 'IF'
|
||||
elif position == 'SS':
|
||||
return 'IF'
|
||||
elif 'F' in position:
|
||||
return 'OF'
|
||||
elif 'P' in position:
|
||||
return 'P'
|
||||
elif position == 'C':
|
||||
return 'C'
|
||||
else:
|
||||
return 'DH'
|
||||
# def get_pos_nickname(position):
|
||||
# if 'B' in position:
|
||||
# return 'IF'
|
||||
# elif position == 'SS':
|
||||
# return 'IF'
|
||||
# elif 'F' in position:
|
||||
# return 'OF'
|
||||
# elif 'P' in position:
|
||||
# return 'P'
|
||||
# elif position == 'C':
|
||||
# return 'C'
|
||||
# else:
|
||||
# return 'DH'
|
||||
|
||||
k_query = await db_get('keepers', params=[('team_id', this_team['id'])])
|
||||
if k_query['count'] > 0:
|
||||
await interaction.edit_original_response(content=random_gif('please go away'))
|
||||
await interaction.channel.send('You\'ve already posted your keepers. I can\'t help you.')
|
||||
return
|
||||
# k_query = await db_get('keepers', params=[('team_id', this_team['id'])])
|
||||
# if k_query['count'] > 0:
|
||||
# await interaction.edit_original_response(content=random_gif('please go away'))
|
||||
# await interaction.channel.send('You\'ve already posted your keepers. I can\'t help you.')
|
||||
# return
|
||||
|
||||
k_list = []
|
||||
k_ids = []
|
||||
keeper_string = ''
|
||||
keeper_swar = 0.0
|
||||
p_query = await db_get('draftpicks', params=[
|
||||
('season', current['season']), ('owner_team_id', this_team['id']), ('pick_round_start', 1),
|
||||
('pick_round_end', 8), ('sort', 'order-asc'), ('short_output', False)
|
||||
])
|
||||
picks = p_query['picks']
|
||||
count = 0
|
||||
# k_list = []
|
||||
# k_ids = []
|
||||
# keeper_string = ''
|
||||
# keeper_swar = 0.0
|
||||
# p_query = await db_get('draftpicks', params=[
|
||||
# ('season', current.season), ('owner_team_id', this_team['id']), ('pick_round_start', 1),
|
||||
# ('pick_round_end', 8), ('sort', 'order-asc'), ('short_output', False)
|
||||
# ])
|
||||
# picks = p_query['picks']
|
||||
# count = 0
|
||||
|
||||
for x in [keeper_1_name, keeper_2_name, keeper_3_name, keeper_4_name, keeper_5_name, keeper_6_name,
|
||||
keeper_7_name]:
|
||||
if x is not None:
|
||||
this_player = await get_player_by_name(current['season'], x)
|
||||
if this_player is None:
|
||||
await interaction.edit_original_response(
|
||||
content='No fuzzy search here can help you. Ya gotta get it right.')
|
||||
return
|
||||
# logger.info(f'keeper_slash - this_player: {this_player}')
|
||||
if this_player['team']['id'] != this_team['id']:
|
||||
await interaction.edit_original_response(
|
||||
content=f'Lol {this_player["name"]}. Oh my god be more I hate you.')
|
||||
return
|
||||
# for x in [keeper_1_name, keeper_2_name, keeper_3_name, keeper_4_name, keeper_5_name, keeper_6_name,
|
||||
# keeper_7_name]:
|
||||
# if x is not None:
|
||||
# this_player = await get_player_by_name(current.season, x)
|
||||
# if this_player is None:
|
||||
# await interaction.edit_original_response(
|
||||
# content='No fuzzy search here can help you. Ya gotta get it right.')
|
||||
# return
|
||||
# # logger.info(f'keeper_slash - this_player: {this_player}')
|
||||
# if this_player['team']['id'] != this_team['id']:
|
||||
# await interaction.edit_original_response(
|
||||
# content=f'Lol {this_player["name"]}. Oh my god be more I hate you.')
|
||||
# return
|
||||
|
||||
k_ids.append(this_player['id'])
|
||||
k_list.append({
|
||||
'season': current['season'],
|
||||
'team_id': this_team['id'],
|
||||
'player_id': this_player['id']
|
||||
})
|
||||
# logger.info(f'keeper_slash - updated k_list')
|
||||
# k_ids.append(this_player['id'])
|
||||
# k_list.append({
|
||||
# 'season': current.season,
|
||||
# 'team_id': this_team['id'],
|
||||
# 'player_id': this_player['id']
|
||||
# })
|
||||
# # logger.info(f'keeper_slash - updated k_list')
|
||||
|
||||
keeper_string += f'{get_pos_nickname(this_player["pos_1"])} - ' \
|
||||
f'{this_player["name"]} ({this_player["wara"]:.2f})\n'
|
||||
keeper_swar += this_player['wara']
|
||||
# logger.info(f'keeper_slash - updated keeper_swar')
|
||||
# keeper_string += f'{get_pos_nickname(this_player["pos_1"])} - ' \
|
||||
# f'{this_player["name"]} ({this_player["wara"]:.2f})\n'
|
||||
# keeper_swar += this_player['wara']
|
||||
# # logger.info(f'keeper_slash - updated keeper_swar')
|
||||
|
||||
this_pick = picks[count]
|
||||
this_pick['player'] = this_player
|
||||
# logger.info(f'keeper_slash - patching draftpick')
|
||||
await patch_draftpick(this_pick)
|
||||
count += 1
|
||||
# this_pick = picks[count]
|
||||
# this_pick['player'] = this_player
|
||||
# # logger.info(f'keeper_slash - patching draftpick')
|
||||
# await patch_draftpick(this_pick)
|
||||
# count += 1
|
||||
|
||||
resp = await db_post('keepers', payload={
|
||||
'count': len(k_list),
|
||||
'keepers': k_list
|
||||
})
|
||||
output_string = f'{resp}\nMoving remaining players to FA...'
|
||||
await interaction.edit_original_response(content=output_string)
|
||||
# resp = await db_post('keepers', payload={
|
||||
# 'count': len(k_list),
|
||||
# 'keepers': k_list
|
||||
# })
|
||||
# output_string = f'{resp}\nMoving remaining players to FA...'
|
||||
# await interaction.edit_original_response(content=output_string)
|
||||
|
||||
fa_team = await get_team_by_abbrev('FA', current['season'])
|
||||
p_query = await db_get('players', params=[
|
||||
('season', current['season']), ('team_id', this_team['id'])
|
||||
])
|
||||
for x in p_query['players']:
|
||||
if x['id'] not in k_ids:
|
||||
x['team'] = fa_team
|
||||
await put_player(x)
|
||||
# fa_team = await get_team_by_abbrev('FA', current.season)
|
||||
# p_query = await db_get('players', params=[
|
||||
# ('season', current.season), ('team_id', this_team['id'])
|
||||
# ])
|
||||
# for x in p_query['players']:
|
||||
# if x['id'] not in k_ids:
|
||||
# x['team'] = fa_team
|
||||
# await put_player(x)
|
||||
|
||||
output_string += f'\nNon-kept players have been booted\nBuilding embeds...'
|
||||
await interaction.edit_original_response(content=output_string)
|
||||
# output_string += f'\nNon-kept players have been booted\nBuilding embeds...'
|
||||
# await interaction.edit_original_response(content=output_string)
|
||||
|
||||
embed = get_team_embed(title=f'{this_team["lname"]} Keepers', team=this_team)
|
||||
embed.add_field(name=f'Keepers', value=keeper_string)
|
||||
embed.add_field(name='Total sWAR', value=f'{keeper_swar:.2f}')
|
||||
await send_to_channel(self.bot, 'sba-network-news', content=None, embed=embed)
|
||||
# embed = get_team_embed(title=f'{this_team["lname"]} Keepers', team=this_team)
|
||||
# embed.add_field(name=f'Keepers', value=keeper_string)
|
||||
# embed.add_field(name='Total sWAR', value=f'{keeper_swar:.2f}')
|
||||
# await send_to_channel(self.bot, 'sba-network-news', content=None, embed=embed)
|
||||
|
||||
output_string += f'\nJust sent keeper message to sba-network-news'
|
||||
await interaction.edit_original_response(content=output_string)
|
||||
# output_string += f'\nJust sent keeper message to sba-network-news'
|
||||
# await interaction.edit_original_response(content=output_string)
|
||||
|
||||
@commands.command(name='migrate-players', help='Migrate players between "same-set" seasons')
|
||||
@commands.has_any_role('Da Commish')
|
||||
|
||||
@ -2,6 +2,7 @@ import copy
|
||||
import math
|
||||
|
||||
from helpers import *
|
||||
from api_calls.current import get_current
|
||||
from peewee import *
|
||||
import discord
|
||||
from discord import app_commands
|
||||
@ -442,17 +443,17 @@ 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 db_get('current')
|
||||
team = await get_team_by_owner(current['season'], interaction.user.id)
|
||||
current = await get_current()
|
||||
team = await get_team_by_owner(current.season, interaction.user.id)
|
||||
|
||||
result_text = 'Home Run'
|
||||
if result == 'bp-flyout':
|
||||
result_text = 'Fly Out'
|
||||
|
||||
season = 'fall'
|
||||
if current['week'] < 6:
|
||||
if current.week < 6:
|
||||
season = 'spring'
|
||||
elif current['week'] < 17:
|
||||
elif current.week < 17:
|
||||
season = 'summer'
|
||||
|
||||
hr_count = 16
|
||||
|
||||
198
cogs/players.py
198
cogs/players.py
@ -9,9 +9,10 @@ from discord import app_commands
|
||||
from discord.ext import tasks
|
||||
from discord.app_commands import Choice
|
||||
|
||||
from api_calls.current import get_current
|
||||
from helpers import *
|
||||
from db_calls import db_get, db_patch, get_team_by_abbrev, get_team_by_owner, put_player, get_player_by_name, db_post, \
|
||||
db_delete
|
||||
from db_calls import db_get, db_patch, get_team_by_abbrev, get_team_by_owner, put_player, get_player_by_name, db_post, db_delete
|
||||
import api_calls as api
|
||||
from typing import Literal, Optional
|
||||
|
||||
logger = logging.getLogger('discord_app')
|
||||
@ -117,10 +118,10 @@ class Players(commands.Cog):
|
||||
async def get_dice_embed(self, channel, title, message):
|
||||
team = None
|
||||
try:
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
team_abbrev = re.split('-', channel.name)
|
||||
if len(team_abbrev[0]) <= 4 and team_abbrev not in ['the', 'city']:
|
||||
tquery = await db_get('teams', params=[('season', current['season']), ('team_abbrev', team_abbrev[0])])
|
||||
tquery = await db_get('teams', params=[('season', current.season), ('team_abbrev', team_abbrev[0])])
|
||||
if tquery['count'] > 0:
|
||||
team = tquery['teams'][0]
|
||||
except (ValueError, AttributeError, requests.ReadTimeout) as e:
|
||||
@ -271,9 +272,9 @@ class Players(commands.Cog):
|
||||
@tasks.loop(count=1)
|
||||
async def build_master_player_list(self):
|
||||
# logger.info(f'build_master_player_list - getting current')
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
# logger.info(f'build_master_player_list - getting all_players')
|
||||
p_query = await db_get('players', timeout=8, params=[('season', current['season'])])
|
||||
p_query = await db_get('players', timeout=8, params=[('season', current.season)])
|
||||
# logger.info(f'build_master_player_list - building player_list')
|
||||
self.player_list = {x['name'].lower(): x['id'] for x in p_query['players']}
|
||||
logger.info(f'player list count: {len(self.player_list)}')
|
||||
@ -344,7 +345,7 @@ class Players(commands.Cog):
|
||||
|
||||
@staticmethod
|
||||
async def update_injuries(ctx):
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
injury_log = discord.utils.get(ctx.guild.text_channels, name='injury-log')
|
||||
|
||||
# Build new messages
|
||||
@ -353,7 +354,7 @@ class Players(commands.Cog):
|
||||
inj_team = {}
|
||||
inj_week = {}
|
||||
i_query = await db_get('injuries', params=[
|
||||
('season', current['season']), ('is_active', True), ('sort', 'return-asc')
|
||||
('season', current.season), ('is_active', True), ('sort', 'return-asc')
|
||||
])
|
||||
|
||||
for x in i_query['injuries']:
|
||||
@ -439,16 +440,16 @@ class Players(commands.Cog):
|
||||
@staticmethod
|
||||
async def game_progress(current):
|
||||
# s_query = await db_get('schedules', params=[
|
||||
# ('season', current['season']), ('week_start', current['week']), ('week_end', current['week'])
|
||||
# ('season', current.season), ('week_start', current.week), ('week_end', current.week)
|
||||
# ])
|
||||
# r_query = await db_get('results', params=[
|
||||
# ('season', current['season']), ('week_start', current['week']), ('week_end', current['week'])
|
||||
# ('season', current.season), ('week_start', current.week), ('week_end', current.week)
|
||||
# ])
|
||||
gp_query = await db_get('games', params=[
|
||||
('season', current['season']), ('week', current['week']), ('played', True), ('short_output', True)
|
||||
('season', current.season), ('week', current.week), ('played', True), ('short_output', True)
|
||||
])
|
||||
all_query = await db_get('games', params=[
|
||||
('season', current['season']), ('week', current['week']), ('short_output', True)
|
||||
('season', current.season), ('week', current.week), ('short_output', True)
|
||||
])
|
||||
|
||||
return {'games_played': gp_query['count'], 'game_count': all_query['count']}
|
||||
@ -554,7 +555,7 @@ class Players(commands.Cog):
|
||||
|
||||
# @staticmethod
|
||||
# def get_standings_embed(current, progress, al_standings, nl_standings):
|
||||
# embed = discord.Embed(title=f'Season {current["season"]} | Week {current["week"]} | '
|
||||
# embed = discord.Embed(title=f'Season {current.season} | Week {current.week} | '
|
||||
# f'{progress["games_played"]}/{progress["game_count"]} games played',
|
||||
# color=0xB70000)
|
||||
# embed.add_field(name=f'**Full Standings**', value=SBA_STANDINGS_URL, inline=False)
|
||||
@ -565,13 +566,13 @@ class Players(commands.Cog):
|
||||
|
||||
@commands.command(name='team', aliases=['roster', 'myboys', 'mybois'], help='Get team overview')
|
||||
async def team_command(self, ctx, team_abbrev: str = None):
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
|
||||
# Get Team
|
||||
if team_abbrev is not None:
|
||||
team = await get_team_by_abbrev(team_abbrev, current['season'])
|
||||
team = await get_team_by_abbrev(team_abbrev, current.season)
|
||||
else:
|
||||
team = await get_team_by_owner(season=current['season'], owner_id=ctx.author.id)
|
||||
team = await get_team_by_owner(season=current.season, owner_id=ctx.author.id)
|
||||
|
||||
# Create team embed
|
||||
embed = get_team_embed(f'{team["lname"]} Overview', team)
|
||||
@ -607,14 +608,14 @@ class Players(commands.Cog):
|
||||
# Get player info
|
||||
il_players = None
|
||||
if team['abbrev'][-2:].lower() != 'il':
|
||||
il_team = await get_team_by_abbrev(team['abbrev'], current['season'])
|
||||
il_team = await get_team_by_abbrev(team['abbrev'], current.season)
|
||||
p_query = await db_get('players', params=[
|
||||
('season', current['season']), ('team_id', il_team['id']), ('sort', 'cost-desc')
|
||||
('season', current.season), ('team_id', il_team['id']), ('sort', 'cost-desc')
|
||||
])
|
||||
il_players = p_query['players']
|
||||
|
||||
p_query = await db_get('players', params=[
|
||||
('season', current['season']), ('team_id', team['id']), ('sort', 'cost-desc')
|
||||
('season', current.season), ('team_id', team['id']), ('sort', 'cost-desc')
|
||||
])
|
||||
players = p_query['players']
|
||||
il_wara = 0
|
||||
@ -640,8 +641,8 @@ class Players(commands.Cog):
|
||||
embed.add_field(name='Injured sWAR', value=f'{il_wara:.2f}')
|
||||
|
||||
s_query = await db_get('schedules', params=[
|
||||
('season', current['season']), ('team_abbrev', team['abbrev']), ('week_start', current['week']),
|
||||
('week_end', current['week']+2 if current['week']+2 > 0 else 2), ('short_output', False)
|
||||
('season', current.season), ('team_abbrev', team['abbrev']), ('week_start', current.week),
|
||||
('week_end', current.week+2 if current.week+2 > 0 else 2), ('short_output', False)
|
||||
])
|
||||
if s_query['count'] > 0:
|
||||
team_schedule = s_query['schedules']
|
||||
@ -656,16 +657,16 @@ class Players(commands.Cog):
|
||||
if matchup['hometeam'] == team:
|
||||
st_abbrev = matchup['awayteam']['abbrev']
|
||||
|
||||
r_query = await db_get('standings', params=[('season', current['season']), ('team_abbrev', st_abbrev)])
|
||||
r_query = await db_get('standings', params=[('season', current.season), ('team_abbrev', st_abbrev)])
|
||||
opp_record = None if r_query['count'] == 0 else r_query['standings'][0]
|
||||
|
||||
if matchup['week'] == current['week']:
|
||||
if matchup['week'] == current.week:
|
||||
if matchup['hometeam'] == team:
|
||||
this_week_string += f'Week {current["week"]}: vs ' \
|
||||
this_week_string += f'Week {current.week}: vs ' \
|
||||
f'{matchup["awayteam"]["lname"]} ' \
|
||||
f'({opp_record["wins"]}-{opp_record["losses"]})\n'
|
||||
else:
|
||||
this_week_string += f'Week {current["week"]}: @ {matchup["hometeam"]["lname"]} ' \
|
||||
this_week_string += f'Week {current.week}: @ {matchup["hometeam"]["lname"]} ' \
|
||||
f'({opp_record["wins"]}-{opp_record["losses"]})\n'
|
||||
else:
|
||||
if matchup['hometeam'] == team:
|
||||
@ -685,7 +686,7 @@ class Players(commands.Cog):
|
||||
# Add roster link
|
||||
embed.add_field(
|
||||
name=f'{team["abbrev"]} Roster Page',
|
||||
value=f'https://sba.manticorum.com/teams/{current["season"]}/{team["abbrev"]}',
|
||||
value=f'https://sba.manticorum.com/teams/{current.season}/{team["abbrev"]}',
|
||||
inline=False
|
||||
)
|
||||
|
||||
@ -693,8 +694,9 @@ class Players(commands.Cog):
|
||||
|
||||
@commands.command(name='player', aliases=['card'], help='Get player overview')
|
||||
async def player_command(self, ctx, *, name):
|
||||
current = await db_get('current')
|
||||
season = current['season']
|
||||
current = await get_current()
|
||||
season = current.season
|
||||
logger.info(f'current: {current}')
|
||||
|
||||
# if 'strider' in name.lower():
|
||||
# await ctx.send(f'Ope. Strider has been reserved for Cal.')
|
||||
@ -845,20 +847,20 @@ class Players(commands.Cog):
|
||||
await ctx.send(f'This command has been deprecated, please use `/schedule`')
|
||||
return
|
||||
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
|
||||
if week is not None:
|
||||
schedule_week = week
|
||||
elif current['week'] < 1:
|
||||
elif current.week < 1:
|
||||
schedule_week = 1
|
||||
else:
|
||||
schedule_week = current['week']
|
||||
schedule_week = current.week
|
||||
|
||||
g1_query = await db_get('games', params=[
|
||||
('season', current['season']), ('week_start', schedule_week), ('week_end', schedule_week)
|
||||
('season', current.season), ('week_start', schedule_week), ('week_end', schedule_week)
|
||||
])
|
||||
g2_query = await db_get('games', params=[
|
||||
('season', current['season']), ('week_start', schedule_week + 1), ('week_end', schedule_week + 1)
|
||||
('season', current.season), ('week_start', schedule_week + 1), ('week_end', schedule_week + 1)
|
||||
])
|
||||
|
||||
games_played = 0
|
||||
@ -887,7 +889,7 @@ class Players(commands.Cog):
|
||||
'away_wins': 0, 'home_wins': 0, 'away_team': x["away_team"], 'home_team': x["home_team"]
|
||||
}
|
||||
|
||||
embed = get_team_embed(f'Season {current["season"]} | Week {schedule_week} | '
|
||||
embed = get_team_embed(f'Season {current.season} | Week {schedule_week} | '
|
||||
f'{games_played}/{g1_query["count"]} games played')
|
||||
|
||||
embed.add_field(name='Full Schedule',
|
||||
@ -952,7 +954,7 @@ class Players(commands.Cog):
|
||||
value=string_next_week_0,
|
||||
inline=False
|
||||
)
|
||||
embed.title = f'Season {current["season"]} | Week {schedule_week + 1}'
|
||||
embed.title = f'Season {current.season} | Week {schedule_week + 1}'
|
||||
await ctx.send(content=None, embed=embed)
|
||||
if len(string_next_week_1) > 0:
|
||||
if len(embed.fields) > 1:
|
||||
@ -974,7 +976,7 @@ class Players(commands.Cog):
|
||||
@app_commands.checks.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||
async def schedule_slash(self, interaction: discord.Interaction, team_abbrev: str = None, week_num: int = None, season: int = SBA_SEASON):
|
||||
await interaction.response.defer()
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
|
||||
this_team = None
|
||||
param_list = [('season', season)]
|
||||
@ -993,7 +995,7 @@ class Players(commands.Cog):
|
||||
param_list.append(('week', week_num))
|
||||
|
||||
if len(param_list) == 1:
|
||||
param_list.append(('week', current['week']))
|
||||
param_list.append(('week', current.week))
|
||||
|
||||
g_query = await db_get('games', params=param_list)
|
||||
if g_query['count'] == 0:
|
||||
@ -1044,7 +1046,7 @@ class Players(commands.Cog):
|
||||
away_record = await db_get(f'standings/team/{x["away_team"]["id"]}')
|
||||
home_record = await db_get(f'standings/team/{x["home_team"]["id"]}')
|
||||
|
||||
this_line = f'({x["away_wins"]}) [{x["away_team"]["lname"]: >4}]({SBA_BASE_URL}/teams/{current["season"]}/{x["away_team"]["abbrev"]}) ({away_record["wins"]}-{away_record["losses"]})\n@\n({x["home_wins"]}) [{x["home_team"]["lname"]: <4}]({SBA_BASE_URL}/teams/{current["season"]}/{x["home_team"]["abbrev"]}) ({home_record["wins"]}-{home_record["losses"]})\n\n'
|
||||
this_line = f'({x["away_wins"]}) [{x["away_team"]["lname"]: >4}]({SBA_BASE_URL}/teams/{current.season}/{x["away_team"]["abbrev"]}) ({away_record["wins"]}-{away_record["losses"]})\n@\n({x["home_wins"]}) [{x["home_team"]["lname"]: <4}]({SBA_BASE_URL}/teams/{current.season}/{x["home_team"]["abbrev"]}) ({home_record["wins"]}-{home_record["losses"]})\n\n'
|
||||
|
||||
logger.info(f'standings_slash - this_line:\n{this_line}')
|
||||
embed.add_field(
|
||||
@ -1057,7 +1059,7 @@ class Players(commands.Cog):
|
||||
# string_this_week += this_line
|
||||
# logger.info(f'Adding to string_this_week:\n{this_line}')
|
||||
|
||||
embed.description = f'Games Played: {games_played} / {"32" if current["week"] <= 18 else "??"}'
|
||||
embed.description = f'Games Played: {games_played} / {"32" if current.week <= 18 else "??"}'
|
||||
await interaction.edit_original_response(
|
||||
content=None,
|
||||
embed=embed
|
||||
@ -1134,31 +1136,31 @@ class Players(commands.Cog):
|
||||
|
||||
@commands.command(name='weather', help='Roll ballpark weather')
|
||||
async def weather_command(self, ctx, team_abbrev=None):
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
|
||||
if team_abbrev is not None:
|
||||
t_query = await db_get('teams', params=[('season', current['season']), ('team_abbrev', team_abbrev)])
|
||||
t_query = await db_get('teams', params=[('season', current.season), ('team_abbrev', team_abbrev)])
|
||||
else:
|
||||
t_query = await db_get('teams', params=[
|
||||
('season', current['season']), ('team_abbrev', ctx.channel.name.split('-')[0])
|
||||
('season', current.season), ('team_abbrev', ctx.channel.name.split('-')[0])
|
||||
])
|
||||
if t_query['count'] == 0:
|
||||
t_query = await db_get('teams', params=[('season', current['season']), ('owner_id', ctx.author.id)])
|
||||
t_query = await db_get('teams', params=[('season', current.season), ('owner_id', ctx.author.id)])
|
||||
|
||||
if t_query['count'] == 0:
|
||||
await ctx.send(f'I could not find a weather chart for you.')
|
||||
|
||||
team = t_query['teams'][0]
|
||||
g_query = await db_get('games', params=[('team1_id', team['id']), ('week', current['week'])])
|
||||
g_query = await db_get('games', params=[('team1_id', team['id']), ('week', current.week)])
|
||||
|
||||
night_str = '\U0001F319 Night'
|
||||
day_str = '\U0001F31E Day'
|
||||
|
||||
is_div_week = current['week'] in [1, 3, 6, 14, 16, 18]
|
||||
is_div_week = current.week in [1, 3, 6, 14, 16, 18]
|
||||
season_str = f'\U0001F3D6 **Summer**'
|
||||
if current['week'] <= 5:
|
||||
if current.week <= 5:
|
||||
season_str = f'\U0001F33C **Spring**'
|
||||
elif current['week'] > 14:
|
||||
elif current.week > 14:
|
||||
season_str = f'\U0001F342 **Fall**'
|
||||
|
||||
d_twenty = random.randint(1, 20)
|
||||
@ -1189,19 +1191,19 @@ class Players(commands.Cog):
|
||||
|
||||
async def get_division_standings(self, current) -> discord.Embed:
|
||||
d1_query = await db_get('standings', params=[
|
||||
('season', current['season']), ('division_abbrev', 'SD')
|
||||
('season', current.season), ('division_abbrev', 'SD')
|
||||
])
|
||||
div_one = d1_query['standings']
|
||||
d2_query = await db_get('standings', params=[
|
||||
('season', current['season']), ('division_abbrev', 'DC')
|
||||
('season', current.season), ('division_abbrev', 'DC')
|
||||
])
|
||||
div_two = d2_query['standings']
|
||||
d3_query = await db_get('standings', params=[
|
||||
('season', current['season']), ('division_abbrev', 'FIP')
|
||||
('season', current.season), ('division_abbrev', 'FIP')
|
||||
])
|
||||
div_three = d3_query['standings']
|
||||
d4_query = await db_get('standings', params=[
|
||||
('season', current['season']), ('division_abbrev', 'DOC')
|
||||
('season', current.season), ('division_abbrev', 'DOC')
|
||||
])
|
||||
div_four = d4_query['standings']
|
||||
|
||||
@ -1227,7 +1229,7 @@ class Players(commands.Cog):
|
||||
|
||||
progress = await self.game_progress(current)
|
||||
|
||||
embed = discord.Embed(title=f'Season {current["season"]} | Week {current["week"]} | '
|
||||
embed = discord.Embed(title=f'Season {current.season} | Week {current.week} | '
|
||||
f'{progress["games_played"]}/{progress["game_count"]} games played',
|
||||
color=0xB70000)
|
||||
embed.add_field(name=f'**Full Standings**', value=SBA_STANDINGS_URL, inline=False)
|
||||
@ -1240,11 +1242,11 @@ class Players(commands.Cog):
|
||||
|
||||
async def get_wildcard_standings(self, current) -> discord.Embed:
|
||||
a_query = await db_get('standings', params=[
|
||||
('season', current['season']), ('league_abbrev', 'SBa')
|
||||
('season', current.season), ('league_abbrev', 'SBa')
|
||||
])
|
||||
al_teams = a_query['standings']
|
||||
# n_query = await db_get('standings', params=[
|
||||
# ('season', current['season']), ('league_abbrev', 'nl')
|
||||
# ('season', current.season), ('league_abbrev', 'nl')
|
||||
# ])
|
||||
# nl_teams = n_query['standings']
|
||||
|
||||
@ -1260,7 +1262,7 @@ class Players(commands.Cog):
|
||||
|
||||
progress = await self.game_progress(current)
|
||||
|
||||
embed = discord.Embed(title=f'Season {current["season"]} | Week {current["week"]} | '
|
||||
embed = discord.Embed(title=f'Season {current.season} | Week {current.week} | '
|
||||
f'{progress["games_played"]}/{progress["game_count"]} games played',
|
||||
color=0xB70000)
|
||||
embed.add_field(name=f'**Full Standings**', value=SBA_STANDINGS_URL, inline=False)
|
||||
@ -1271,7 +1273,7 @@ class Players(commands.Cog):
|
||||
|
||||
async def standings_button_loop(self, ctx, start: Literal['division', 'wildcard']):
|
||||
async with ctx.typing():
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
div_embed = await self.get_division_standings(current)
|
||||
wc_embed = await self.get_wildcard_standings(current)
|
||||
logger.info(f'div_embed: {div_embed}\nwc_embed: {wc_embed}')
|
||||
@ -1341,9 +1343,9 @@ class Players(commands.Cog):
|
||||
return
|
||||
|
||||
await interaction.response.defer()
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
|
||||
p_query = await db_get('players', params=[('name', player_name), ('season', current['season'])])
|
||||
p_query = await db_get('players', params=[('name', player_name), ('season', current.season)])
|
||||
if p_query['count'] == 0:
|
||||
await interaction.edit_original_response(content=f'I did not find anybody named **{player_name}**.')
|
||||
return
|
||||
@ -1351,7 +1353,7 @@ class Players(commands.Cog):
|
||||
player = p_query['players'][0]
|
||||
|
||||
# Check if player is on owner's team
|
||||
team = await get_team_by_owner(current['season'], interaction.user.id)
|
||||
team = await get_team_by_owner(current.season, interaction.user.id)
|
||||
if not player['team'] == team and not player['team']['abbrev'][:len(team['abbrev'])] == team['abbrev']:
|
||||
await interaction.edit_original_response(
|
||||
content=f'Is this some kind of tom foolery? {player["name"]} is on {player["team"]["abbrev"]} aka '
|
||||
@ -1383,7 +1385,7 @@ class Players(commands.Cog):
|
||||
)
|
||||
|
||||
await db_post('injuries', payload={
|
||||
'season': current['season'],
|
||||
'season': current.season,
|
||||
'player_id': player['id'],
|
||||
'total_games': inj_games,
|
||||
'start_week': this_week if this_game != 4 else this_week + 1,
|
||||
@ -1402,9 +1404,9 @@ class Players(commands.Cog):
|
||||
@app_commands.checks.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||
async def clear_injury_slash(self, interaction: discord.Interaction, player_name: str):
|
||||
await interaction.response.defer()
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
|
||||
p_query = await db_get('players', params=[('name', player_name), ('season', current['season'])])
|
||||
p_query = await db_get('players', params=[('name', player_name), ('season', current.season)])
|
||||
if p_query['count'] == 0:
|
||||
await interaction.response.send_message(f'I did not find anybody named **{player_name}**.')
|
||||
return
|
||||
@ -1416,7 +1418,7 @@ class Players(commands.Cog):
|
||||
await interaction.edit_original_response(content='Huh? He isn\'t injured, numb nuts.')
|
||||
return
|
||||
|
||||
team = await get_team_by_owner(current['season'], interaction.user.id)
|
||||
team = await get_team_by_owner(current.season, interaction.user.id)
|
||||
if not player['team'] == team and not player['team']['abbrev'][:len(team['abbrev'])] == team['abbrev']:
|
||||
await interaction.edit_original_response(
|
||||
content=f'Is this some kind of tom foolery? {player["name"]} is on {player["team"]["abbrev"]} aka '
|
||||
@ -1498,7 +1500,7 @@ class Players(commands.Cog):
|
||||
@app_commands.command(name='sba-submit', description='Submit scorecard and game result')
|
||||
@app_commands.checks.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||
async def submit_slash(self, interaction: discord.Interaction, sheet_url: str):
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
|
||||
# Go get scorecard
|
||||
await interaction.response.send_message(content='I\'ll go grab that card now...')
|
||||
@ -1518,7 +1520,7 @@ class Players(commands.Cog):
|
||||
setup_tab = scorecard.worksheet_by_title('Setup')
|
||||
|
||||
scorecard_version = setup_tab.get_value('V35')
|
||||
if int(scorecard_version) != current['bet_week']:
|
||||
if int(scorecard_version) != current.bet_week:
|
||||
await interaction.edit_original_response(
|
||||
content=f'It looks like this scorecard is out of date. Did you create a new card at the start of the '
|
||||
f'game? If you did, let Cal know about this error. If not, I\'ll need you to use an up to '
|
||||
@ -1534,8 +1536,8 @@ class Players(commands.Cog):
|
||||
ht_abbrev = g_data[4][0]
|
||||
away_mgr_name = g_data[3][1]
|
||||
home_mgr_name = g_data[4][1]
|
||||
away_team = await get_team_by_abbrev(at_abbrev, current['season'])
|
||||
home_team = await get_team_by_abbrev(ht_abbrev, current['season'])
|
||||
away_team = await get_team_by_abbrev(at_abbrev, current.season)
|
||||
home_team = await get_team_by_abbrev(ht_abbrev, current.season)
|
||||
logger.info(f'away_manager: {away_mgr_name} / home_manager: {home_mgr_name}')
|
||||
if away_team['manager2'] is not None and away_team['manager2']['name'].lower() == away_mgr_name.lower():
|
||||
away_manager = away_team['manager2']
|
||||
@ -1549,7 +1551,7 @@ class Players(commands.Cog):
|
||||
logger.info(f'gdata: {g_data}\nweek/game: {week_num}/{game_num}')
|
||||
|
||||
# Confirm submitting GM
|
||||
if await get_team_by_owner(current['season'], interaction.user.id) not in [home_team, away_team] and \
|
||||
if await get_team_by_owner(current.season, interaction.user.id) not in [home_team, away_team] and \
|
||||
interaction.user.id != self.bot.owner_id:
|
||||
await interaction.edit_original_response(
|
||||
content=f'{await get_emoji(interaction, "squint")} Only a GM of the two teams can submit scorecards.'
|
||||
@ -1558,7 +1560,7 @@ class Players(commands.Cog):
|
||||
|
||||
# Confirm teams and matchup
|
||||
dupe_g_query = await db_get('games', params=[
|
||||
('season', current['season']), ('week', week_num), ('game_num', game_num),
|
||||
('season', current.season), ('week', week_num), ('game_num', game_num),
|
||||
('away_team_id', away_team['id']), ('home_team_id', home_team['id'])
|
||||
])
|
||||
if dupe_g_query['count'] != 0:
|
||||
@ -1592,7 +1594,7 @@ class Players(commands.Cog):
|
||||
return
|
||||
|
||||
g_query = await db_get('games', params=[
|
||||
('season', current['season']), ('week', week_num), ('away_team_id', away_team['id']),
|
||||
('season', current.season), ('week', week_num), ('away_team_id', away_team['id']),
|
||||
('home_team_id', home_team['id']), ('played', False)
|
||||
])
|
||||
if g_query['count'] == 0:
|
||||
@ -1730,7 +1732,7 @@ class Players(commands.Cog):
|
||||
return
|
||||
|
||||
# Post scorecard to news channel
|
||||
card_url = f'<{SBA_BASE_URL}/games/{current["season"]}/{week_num}/{game_num}' \
|
||||
card_url = f'<{SBA_BASE_URL}/games/{current.season}/{week_num}/{game_num}' \
|
||||
f'/{away_team["abbrev"]}/{home_team["abbrev"]}>'
|
||||
extras = ''
|
||||
if int(final_inning) > 9:
|
||||
@ -1994,7 +1996,7 @@ class Players(commands.Cog):
|
||||
)
|
||||
|
||||
update = await interaction.channel.send('I\'m tallying standings now...')
|
||||
if await db_post(f'standings/s{current["season"]}/recalculate', timeout=8):
|
||||
if await db_post(f'standings/s{current.season}/recalculate', timeout=8):
|
||||
await update.delete()
|
||||
await interaction.edit_original_response(content='You are all set!')
|
||||
|
||||
@ -2029,9 +2031,9 @@ class Players(commands.Cog):
|
||||
mil_color_hex: str = None, mil_team_image_url: str = None, mil_team_name: str = None,
|
||||
dice_color_hex: str = None):
|
||||
await interaction.response.defer()
|
||||
current = await db_get('current')
|
||||
team = await get_team_by_owner(current['season'], interaction.user.id)
|
||||
mil_team = await get_team_by_abbrev(f'{team["abbrev"]}MiL', current['season'])
|
||||
current = await get_current()
|
||||
team = await get_team_by_owner(current.season, interaction.user.id)
|
||||
mil_team = await get_team_by_abbrev(f'{team["abbrev"]}MiL', current.season)
|
||||
team_role = get_team_role(interaction, team)
|
||||
errors = []
|
||||
show_mil = False
|
||||
@ -2151,8 +2153,8 @@ class Players(commands.Cog):
|
||||
@commands.command(name='private', help='Get private vc')
|
||||
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||
async def private_vc_command(self, ctx):
|
||||
current = await db_get('current')
|
||||
this_team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
current = await get_current()
|
||||
this_team = await get_team_by_owner(current.season, ctx.author.id)
|
||||
|
||||
async def get_other_team():
|
||||
prompt = f'Please enter the abbrev of the team you are playing.'
|
||||
@ -2163,7 +2165,7 @@ class Players(commands.Cog):
|
||||
await ctx.send('You keep thinking about it and hit me up later if you figure it out.')
|
||||
return None
|
||||
else:
|
||||
other_team = await get_team_by_abbrev(resp, current['season'])
|
||||
other_team = await get_team_by_abbrev(resp, current.season)
|
||||
if not other_team:
|
||||
await ctx.send(f'What\'s a **{resp}**? If you could go ahead and run this command again, that\'d '
|
||||
f'be great.')
|
||||
@ -2176,7 +2178,7 @@ class Players(commands.Cog):
|
||||
return
|
||||
|
||||
g_query = await db_get('games', params=[
|
||||
('season', current['season']), ('week', current['week']), ('team1_id', this_team['id'])
|
||||
('season', current.season), ('week', current.week), ('team1_id', this_team['id'])
|
||||
])
|
||||
if g_query['count'] == 0:
|
||||
other_team = await get_other_team()
|
||||
@ -2238,8 +2240,8 @@ class Players(commands.Cog):
|
||||
await ctx.send('Not in season 6 chat, dumbass.')
|
||||
return
|
||||
|
||||
current = await db_get('current')
|
||||
this_team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
current = await get_current()
|
||||
this_team = await get_team_by_owner(current.season, ctx.author.id)
|
||||
|
||||
if not this_team:
|
||||
await ctx.send('Hmm...I can\'t find your team. Are you from around here?')
|
||||
@ -2248,7 +2250,7 @@ class Players(commands.Cog):
|
||||
p_name = await fuzzy_player_search(
|
||||
ctx, ctx.channel, self.bot, player_name, self.player_list.keys(), author=ctx.author
|
||||
)
|
||||
player = await get_player_by_name(current['season'], p_name)
|
||||
player = await get_player_by_name(current.season, p_name)
|
||||
if player is None:
|
||||
await ctx.send(random_gif('it didn\'t work'))
|
||||
return
|
||||
@ -2274,8 +2276,8 @@ class Players(commands.Cog):
|
||||
await ctx.send('Not in season 6 chat, dumbass.')
|
||||
return
|
||||
|
||||
current = await db_get('current')
|
||||
this_team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
current = await get_current()
|
||||
this_team = await get_team_by_owner(current.season, ctx.author.id)
|
||||
|
||||
if not this_team:
|
||||
await ctx.send('Hmm...I can\'t find your team. Are you from around here?')
|
||||
@ -2284,7 +2286,7 @@ class Players(commands.Cog):
|
||||
p_name = await fuzzy_player_search(
|
||||
ctx, ctx.channel, self.bot, player_name, self.player_list.keys(), author=ctx.author
|
||||
)
|
||||
player = await get_player_by_name(current['season'], p_name)
|
||||
player = await get_player_by_name(current.season, p_name)
|
||||
if player is None:
|
||||
await ctx.send(random_gif('it didn\'t work'))
|
||||
return
|
||||
@ -2310,8 +2312,8 @@ class Players(commands.Cog):
|
||||
await ctx.send('Not in season 5 chat, dumbass.')
|
||||
return
|
||||
|
||||
current = await db_get('current')
|
||||
this_team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
current = await get_current()
|
||||
this_team = await get_team_by_owner(current.season, ctx.author.id)
|
||||
|
||||
if not this_team:
|
||||
await ctx.send('Hmm...I can\'t find your team. Are you from around here?')
|
||||
@ -2320,11 +2322,11 @@ class Players(commands.Cog):
|
||||
p_name = await fuzzy_player_search(
|
||||
ctx, ctx.channel, self.bot, player_name, self.player_list.keys(), author=ctx.author
|
||||
)
|
||||
player = await get_player_by_name(current['season'], p_name)
|
||||
player = await get_player_by_name(current.season, p_name)
|
||||
|
||||
p_query = await db_get('players', params=[('season', current['season'] - 1), ('name', p_name)])
|
||||
p_query = await db_get('players', params=[('season', current.season - 1), ('name', p_name)])
|
||||
if p_query['count'] == 0:
|
||||
await ctx.send(f'I could not find **{p_name}** from Season {current["season"] - 1}')
|
||||
await ctx.send(f'I could not find **{p_name}** from Season {current.season - 1}')
|
||||
return
|
||||
|
||||
player['vanity_card'] = p_query['players'][0]['vanity_card']
|
||||
@ -2391,8 +2393,8 @@ class Players(commands.Cog):
|
||||
# self, interaction: discord.Interaction, team_abbrev: str, keep1: str = None, keep2: str = None,
|
||||
# keep3: str = None, keep4: str = None, keep5: str = None, keep6: str = None, keep7: str = None):
|
||||
# await interaction.response.defer()
|
||||
# current = await db_get('current')
|
||||
# team = await get_team_by_abbrev(team_abbrev, current['season'])
|
||||
# current = await get_current()
|
||||
# team = await get_team_by_abbrev(team_abbrev, current.season)
|
||||
#
|
||||
# keepers = []
|
||||
# keeper_string = ''
|
||||
@ -2414,7 +2416,7 @@ class Players(commands.Cog):
|
||||
# p_name = await fuzzy_player_search(
|
||||
# interaction, interaction.channel, self.bot, x, self.player_list.keys(), author=interaction.user
|
||||
# )
|
||||
# this_p = await get_player_by_name(current['season'], p_name)
|
||||
# this_p = await get_player_by_name(current.season, p_name)
|
||||
# keepers.append(this_p)
|
||||
# keeper_string += f'{get_pos_abbrev(this_p["pos_1"])} - {this_p["name"]} ({this_p["wara"]:.2f})\n'
|
||||
# keeper_swar += this_p['wara']
|
||||
@ -2423,7 +2425,7 @@ class Players(commands.Cog):
|
||||
# all_players = await db_get('players', api_ver=3, params=[('team_abbrev', team['abbrev'])])
|
||||
# logger.info(f'all_players: {all_players}')
|
||||
#
|
||||
# fa = await get_team_by_abbrev('FA', current['season'])
|
||||
# fa = await get_team_by_abbrev('FA', current.season)
|
||||
# for y in all_players['players']:
|
||||
# if y not in keepers:
|
||||
# y['team'] = fa
|
||||
@ -2625,8 +2627,8 @@ class Players(commands.Cog):
|
||||
await interaction.channel.send(content=None, embed=embed)
|
||||
|
||||
# this_roll = {
|
||||
# 'season': self.current['season'],
|
||||
# 'week': self.current['week'],
|
||||
# 'season': self.current.season,
|
||||
# 'week': self.current.week,
|
||||
# 'team_id': team["id"] if team else None,
|
||||
# 'roller': interaction.user.id,
|
||||
# 'threedsix': d_six_one + d_six_two + d_six_three
|
||||
@ -2829,9 +2831,9 @@ class Players(commands.Cog):
|
||||
|
||||
await interaction.response.defer()
|
||||
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
new_season = 10
|
||||
this_team = await get_team_by_owner(current['season'], interaction.user.id)
|
||||
this_team = await get_team_by_owner(current.season, interaction.user.id)
|
||||
|
||||
if not this_team:
|
||||
await interaction.edit_original_response(content='Hmm...I can\'t find your team. Are you from around here?')
|
||||
|
||||
@ -2,6 +2,7 @@ import re
|
||||
import copy
|
||||
|
||||
from helpers import *
|
||||
from api_calls.current import get_current
|
||||
from db_calls import db_get, db_patch, get_team_by_owner, get_team_by_abbrev, get_player_by_name, put_player, db_post
|
||||
from discord.ext import commands, tasks
|
||||
OFFSEASON_FLAG = True
|
||||
@ -17,7 +18,7 @@ class SBaTransaction:
|
||||
self.channel = channel
|
||||
self.gms = []
|
||||
self.current = current
|
||||
self.effective_week = current['week'] + 1 if not this_week else current['week']
|
||||
self.effective_week = current.week + 1 if not this_week else current.week
|
||||
self.move_type = move_type
|
||||
|
||||
if first_team and team_role:
|
||||
@ -125,13 +126,13 @@ class SBaTransaction:
|
||||
async def get_player_moves(self, player, this_week):
|
||||
if this_week:
|
||||
t_query = await db_get('transactions', params=[
|
||||
('season', self.current['season']), ('week_start', self.current['week']),
|
||||
('week_end', self.current['season']), ('player_id', player['id'])
|
||||
('season', self.current.season), ('week_start', self.current.week),
|
||||
('week_end', self.current.season), ('player_id', player['id'])
|
||||
])
|
||||
return t_query['transactions']
|
||||
else:
|
||||
t_query = await db_get('transactions', params=[
|
||||
('season', self.current['season']), ('week_start', self.effective_week),
|
||||
('season', self.current.season), ('week_start', self.effective_week),
|
||||
('week_end', self.effective_week), ('player_id', player['id'])
|
||||
])
|
||||
return t_query['transactions']
|
||||
@ -140,19 +141,19 @@ class SBaTransaction:
|
||||
wara = 0
|
||||
mil_wara = 0
|
||||
this_team = self.teams[team]['team']
|
||||
# team_roster = await get_players(self.current['season'], this_team['abbrev'])
|
||||
# team_roster = await get_players(self.current.season, this_team['abbrev'])
|
||||
t_query = await db_get('players', params=[
|
||||
('season', self.current['season']), ('team_id', this_team['id'])
|
||||
('season', self.current.season), ('team_id', this_team['id'])
|
||||
])
|
||||
team_roster = t_query['players']
|
||||
|
||||
ml_query = await db_get('teams', params=[
|
||||
('season', self.current['season']), ('team_abbrev', f'{this_team["abbrev"]}MiL')
|
||||
('season', self.current.season), ('team_abbrev', f'{this_team["abbrev"]}MiL')
|
||||
])
|
||||
# mil_roster = await get_players(self.current['season'], f'{this_team["abbrev"]}MiL')
|
||||
# mil_roster = await get_players(self.current.season, f'{this_team["abbrev"]}MiL')
|
||||
mil_team = await get_team_by_abbrev(f'{this_team["abbrev"]}MiL', season=this_team['season'])
|
||||
m_query = await db_get('players', params=[
|
||||
('season', self.current['season']), ('team_id', mil_team['id'])
|
||||
('season', self.current.season), ('team_id', mil_team['id'])
|
||||
])
|
||||
mil_roster = m_query['players']
|
||||
|
||||
@ -162,22 +163,22 @@ class SBaTransaction:
|
||||
mil_wara += player['wara']
|
||||
|
||||
logger.info(f'checking future moves')
|
||||
if self.effective_week > self.current['week']:
|
||||
if self.effective_week > self.current.week:
|
||||
# set_moves = await get_transactions(
|
||||
# self.current['season'], team_abbrev=this_team['abbrev'], week_start=self.effective_week,
|
||||
# self.current.season, team_abbrev=this_team['abbrev'], week_start=self.effective_week,
|
||||
# week_end=self.effective_week
|
||||
# )
|
||||
t_query = await db_get('transactions', params=[
|
||||
('season', self.current['season']), ('week_start', self.effective_week),
|
||||
('season', self.current.season), ('week_start', self.effective_week),
|
||||
('week_end', self.effective_week), ('team_abbrev', this_team['abbrev'])
|
||||
])
|
||||
set_moves = t_query['transactions']
|
||||
# freeze_moves = await get_transactions(
|
||||
# self.current['season'], team_abbrev=this_team['abbrev'], week_start=self.effective_week,
|
||||
# self.current.season, team_abbrev=this_team['abbrev'], week_start=self.effective_week,
|
||||
# week_end=self.effective_week, frozen=True
|
||||
# )
|
||||
t_query = await db_get('transactions', params=[
|
||||
('season', self.current['season']), ('week_start', self.effective_week),
|
||||
('season', self.current.season), ('week_start', self.effective_week),
|
||||
('week_end', self.effective_week), ('team_abbrev', this_team['abbrev']), ('frozen', True)
|
||||
])
|
||||
freeze_moves = t_query['transactions']
|
||||
@ -223,7 +224,7 @@ class SBaTransaction:
|
||||
# logger.info(f'team roster: {team_roster}')
|
||||
team_roster.remove(self.players[x]['player'])
|
||||
# 06-13: COMMENTED OUT TO RESOLVE MID-WEEK IL REPLACEMENT BEING SENT BACK DOWN
|
||||
# if self.effective_week != self.current['week']:
|
||||
# if self.effective_week != self.current.week:
|
||||
wara -= self.players[x]['player']['wara']
|
||||
|
||||
# If player is leaving MiL team next week, remove from roster and subtract WARa
|
||||
@ -231,7 +232,7 @@ class SBaTransaction:
|
||||
logger.info(f'minor league player')
|
||||
mil_roster.remove(self.players[x]['player'])
|
||||
# logger.info(f'mil roster: {mil_roster}')
|
||||
if self.effective_week != self.current['week']:
|
||||
if self.effective_week != self.current.week:
|
||||
mil_wara -= self.players[x]['player']['wara']
|
||||
|
||||
return {'roster': team_roster, 'wara': wara, 'mil_roster': mil_roster, 'mil_wara': mil_wara}
|
||||
@ -239,18 +240,18 @@ class SBaTransaction:
|
||||
# async def check_minor_league_errors(self, ml_team_id):
|
||||
# wara = 0
|
||||
# this_team = await get_one_team(ml_team_id + 2)
|
||||
# team_roster = await get_players(self.current['season'], this_team['abbrev'])
|
||||
# team_roster = await get_players(self.current.season, this_team['abbrev'])
|
||||
#
|
||||
# for player in team_roster:
|
||||
# wara += team_roster[player]['wara']
|
||||
#
|
||||
# if self.effective_week > self.current['week']:
|
||||
# if self.effective_week > self.current.week:
|
||||
# set_moves = await get_transactions(
|
||||
# self.current['season'], team_abbrev=this_team['abbrev'], week_start=self.effective_week,
|
||||
# self.current.season, team_abbrev=this_team['abbrev'], week_start=self.effective_week,
|
||||
# week_end=self.effective_week
|
||||
# )
|
||||
# freeze_moves = await get_transactions(
|
||||
# self.current['season'], team_abbrev=this_team['abbrev'], week_start=self.effective_week,
|
||||
# self.current.season, team_abbrev=this_team['abbrev'], week_start=self.effective_week,
|
||||
# week_end=self.effective_week, frozen=True
|
||||
# )
|
||||
# moves = {**set_moves, **freeze_moves}
|
||||
@ -274,19 +275,19 @@ class SBaTransaction:
|
||||
# # If player is leaving this team next week, remove from roster and subtract WARa
|
||||
# elif self.players[x]['player']['team'] == this_team:
|
||||
# team_roster.pop(self.players[x]['player']['name'], None)
|
||||
# if self.effective_week != self.current['week']:
|
||||
# if self.effective_week != self.current.week:
|
||||
# wara -= self.players[x]['player']['wara']
|
||||
#
|
||||
# return {'roster': team_roster, 'wara': wara}
|
||||
|
||||
async def send_transaction(self):
|
||||
team_id = list(self.teams.keys())[0]
|
||||
moveid = f'Season-{self.current["season"]:03d}-Week-{self.effective_week:0>2}-{datetime.datetime.now().strftime("%d-%H:%M:%S")}'
|
||||
moveid = f'Season-{self.current.season:03d}-Week-{self.effective_week:0>2}-{datetime.datetime.now().strftime("%d-%H:%M:%S")}'
|
||||
moves = []
|
||||
|
||||
logger.warning(f'move_id: {moveid} / move_type: {self.move_type} / avoid_freeze: {self.avoid_freeze} / '
|
||||
f'week: {self.current["week"]}')
|
||||
if self.current['freeze'] and not self.avoid_freeze:
|
||||
f'week: {self.current.week}')
|
||||
if self.current.freeze and not self.avoid_freeze:
|
||||
frozen = True
|
||||
else:
|
||||
frozen = False
|
||||
@ -297,7 +298,7 @@ class SBaTransaction:
|
||||
'player_id': self.players[x]['player']['id'],
|
||||
'oldteam_id': self.players[x]['player']['team']['id'],
|
||||
'newteam_id': self.players[x]['to']['id'],
|
||||
'season': self.current['season'],
|
||||
'season': self.current.season,
|
||||
'moveid': moveid,
|
||||
'frozen': frozen
|
||||
})
|
||||
@ -344,19 +345,19 @@ class Transactions(commands.Cog):
|
||||
if OFFSEASON_FLAG:
|
||||
return
|
||||
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
now = datetime.datetime.now()
|
||||
logger.debug(f'Datetime: {now} / weekday: {now.weekday()}')
|
||||
|
||||
# Begin Freeze
|
||||
# if now.weekday() == 0 and now.hour == 5 and not current['freeze']: # Spring/Summer
|
||||
if now.weekday() == 0 and now.hour == 0 and not current['freeze']: # Fall/Winter
|
||||
current['week'] += 1
|
||||
await db_patch('current', object_id=current['id'], params=[('week', current['week']), ('freeze', True)])
|
||||
# if now.weekday() == 0 and now.hour == 5 and not current.freeze: # Spring/Summer
|
||||
if now.weekday() == 0 and now.hour == 0 and not current.freeze: # Fall/Winter
|
||||
current.week += 1
|
||||
await db_patch('current', object_id=current['id'], params=[('week', current.week), ('freeze', True)])
|
||||
await self.run_transactions(current)
|
||||
|
||||
logger.debug(f'Building freeze string')
|
||||
week_num = f'Week {current["week"]}'
|
||||
week_num = f'Week {current.week}'
|
||||
stars = f'{"":*<32}'
|
||||
freeze_message = f'```\n' \
|
||||
f'{stars}\n'\
|
||||
@ -365,15 +366,15 @@ class Transactions(commands.Cog):
|
||||
logger.debug(f'Freeze string:\n\n{freeze_message}')
|
||||
await send_to_channel(self.bot, 'transaction-log', freeze_message)
|
||||
|
||||
if current['week'] > 0 and current['week'] <= 18:
|
||||
if current.week > 0 and current.week <= 18:
|
||||
await self.post_weekly_info(current)
|
||||
|
||||
# End Freeze
|
||||
# elif now.weekday() == 5 and now.hour == 5 and current['freeze']: # Spring/Summer
|
||||
elif now.weekday() == 5 and now.hour == 0 and current['freeze']: # Fall/Winter
|
||||
# elif now.weekday() == 5 and now.hour == 5 and current.freeze: # Spring/Summer
|
||||
elif now.weekday() == 5 and now.hour == 0 and current.freeze: # Fall/Winter
|
||||
await db_patch('current', object_id=current['id'], params=[('freeze', False)])
|
||||
|
||||
week_num = f'Week {current["week"]}'
|
||||
week_num = f'Week {current.week}'
|
||||
stars = f'{"":*<30}'
|
||||
freeze_message = f'```\n' \
|
||||
f'{stars}\n'\
|
||||
@ -389,7 +390,7 @@ class Transactions(commands.Cog):
|
||||
|
||||
async def run_transactions(self, current):
|
||||
m_query = await db_get('transactions', params=[
|
||||
('season', current['season']), ('week_start', current['week']), ('week_end', current['week'])
|
||||
('season', current.season), ('week_start', current.week), ('week_end', current.week)
|
||||
])
|
||||
if m_query['count'] == 0:
|
||||
return
|
||||
@ -399,9 +400,9 @@ class Transactions(commands.Cog):
|
||||
# try:
|
||||
# if (move['newteam']['abbrev'][-3:] == 'MiL' and move['oldteam']['abbrev'] == 'FA') or \
|
||||
# move['newteam']['abbrev'][-2:] == 'IL' or move['newteam']['abbrev'].lower() == 'fa':
|
||||
# dem_week = current['week']
|
||||
# dem_week = current.week
|
||||
# else:
|
||||
# dem_week = current['week'] + 1
|
||||
# dem_week = current.week + 1
|
||||
#
|
||||
# await patch_player(
|
||||
# move['player']['id'],
|
||||
@ -414,9 +415,9 @@ class Transactions(commands.Cog):
|
||||
for x in all_moves:
|
||||
if (x['newteam']['abbrev'][-3:] == 'MiL' and x['oldteam']['abbrev'] == 'FA') or \
|
||||
x['newteam']['abbrev'][-2:] == 'IL' or x['newteam']['abbrev'] == 'FA':
|
||||
dem_week = current['week']
|
||||
dem_week = current.week
|
||||
else:
|
||||
dem_week = current['week'] + 1
|
||||
dem_week = current.week + 1
|
||||
|
||||
x['player']['team'] = x['newteam']
|
||||
x['player']['demotion_week'] = dem_week
|
||||
@ -444,17 +445,17 @@ class Transactions(commands.Cog):
|
||||
|
||||
async def process_freeze_moves(self, current):
|
||||
# all_moves = await get_transactions(
|
||||
# season=current['season'],
|
||||
# week_start=current['week'],
|
||||
# week_end=current['week'] + 1,
|
||||
# season=current.season,
|
||||
# week_start=current.week,
|
||||
# week_end=current.week + 1,
|
||||
# frozen=True
|
||||
# )
|
||||
m_query = await db_get('transactions', params=[
|
||||
('season', current['season']), ('week_start', current['week']), ('week_end', current['week'] + 1),
|
||||
('season', current.season), ('week_start', current.week), ('week_end', current.week + 1),
|
||||
('frozen', True)
|
||||
])
|
||||
if m_query['count'] == 0:
|
||||
logger.warning(f'No transactions to process for the freeze in week {current["week"]}')
|
||||
logger.warning(f'No transactions to process for the freeze in week {current.week}')
|
||||
return
|
||||
|
||||
moves = m_query['transactions']
|
||||
@ -466,16 +467,16 @@ class Transactions(commands.Cog):
|
||||
|
||||
for move in moves:
|
||||
if move['newteam']['abbrev'][-3:] == 'MiL':
|
||||
new_team = await get_team_by_abbrev(move['newteam']['abbrev'][:-3], current['season'])
|
||||
new_team = await get_team_by_abbrev(move['newteam']['abbrev'][:-3], current.season)
|
||||
else:
|
||||
new_team = move['newteam']
|
||||
# team_record = await get_team_record(new_team, week_num=current["week"])
|
||||
# team_record = await get_team_record(new_team, week_num=current.week)
|
||||
|
||||
if new_team['abbrev'] == 'FA':
|
||||
win_pct = 0
|
||||
else:
|
||||
r_query = await db_get('standings', params=[
|
||||
('season', current['season']), ('team_id', new_team['id'])
|
||||
('season', current.season), ('team_id', new_team['id'])
|
||||
])
|
||||
win_pct = r_query['standings'][0]['wins'] / (
|
||||
r_query['standings'][0]['wins'] + r_query['standings'][0]['losses'])
|
||||
@ -515,13 +516,13 @@ class Transactions(commands.Cog):
|
||||
|
||||
# Post transactions that are not cancelled
|
||||
# final_moves = await get_transactions(
|
||||
# season=current['season'],
|
||||
# week_start=current["week"],
|
||||
# week_end=current["week"] + 1,
|
||||
# season=current.season,
|
||||
# week_start=current.week,
|
||||
# week_end=current.week + 1,
|
||||
# frozen=True
|
||||
# )
|
||||
m_query = await db_get('transactions', params=[
|
||||
('season', current['season']), ('week_start', current['week']), ('week_end', current['week'] + 1),
|
||||
('season', current.season), ('week_start', current.week), ('week_end', current.week + 1),
|
||||
('frozen', True)
|
||||
])
|
||||
final_moves = m_query['transactions']
|
||||
@ -538,13 +539,13 @@ class Transactions(commands.Cog):
|
||||
await self.post_move_to_transaction_log(move_id)
|
||||
|
||||
async def post_move_to_transaction_log(self, move_id):
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
# all_moves = await get_transactions(
|
||||
# season=current['season'],
|
||||
# season=current.season,
|
||||
# move_id=move_id
|
||||
# )
|
||||
m_query = await db_get('transactions', params=[
|
||||
('season', current['season']), ('move_id', move_id)
|
||||
('season', current.season), ('move_id', move_id)
|
||||
])
|
||||
all_moves = m_query['transactions']
|
||||
|
||||
@ -584,12 +585,12 @@ class Transactions(commands.Cog):
|
||||
day_str = '\U0001F31E Day'
|
||||
|
||||
season_str = f'\U0001F3D6 **Summer**'
|
||||
if current['week'] <= 5:
|
||||
if current.week <= 5:
|
||||
season_str = f'\U0001F33C **Spring**'
|
||||
elif current['week'] > 14:
|
||||
elif current.week > 14:
|
||||
season_str = f'\U0001F342 **Fall**'
|
||||
|
||||
is_div_week = current['week'] in [1, 3, 6, 14, 16, 18]
|
||||
is_div_week = current.week in [1, 3, 6, 14, 16, 18]
|
||||
|
||||
weekly_str = f'**Season**: {season_str}\n' \
|
||||
f'**Time of Day**: {night_str} / {night_str if is_div_week else day_str} / ' \
|
||||
@ -615,14 +616,14 @@ class Transactions(commands.Cog):
|
||||
@commands.command(name='run_transactions')
|
||||
@commands.is_owner()
|
||||
async def run_transactions_helper_command(self, ctx):
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
await self.run_transactions(current)
|
||||
await ctx.send(new_rand_conf_gif())
|
||||
|
||||
@commands.command(name='process_freeze')
|
||||
@commands.is_owner()
|
||||
async def process_freeze_helper_command(self, ctx):
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
await self.process_freeze_moves(current)
|
||||
await ctx.send(random_conf_gif())
|
||||
|
||||
@ -635,19 +636,19 @@ class Transactions(commands.Cog):
|
||||
name='trade', aliases=['tradeplz', 'pleasetrade', 'tradeplease', 'plztrade'], help='Trade players')
|
||||
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||
async def trade_command(self, ctx):
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
|
||||
if current['week'] > current['trade_deadline']:
|
||||
if current.week > current.trade_deadline:
|
||||
await ctx.send(await get_emoji(ctx, 'oof', False))
|
||||
await ctx.send(f'The trade deadline is **week {current["trade_deadline"]}**. Since it is currently **week '
|
||||
f'{current["week"]}** I am just going to stop you right there.')
|
||||
await ctx.send(f'The trade deadline is **week {current.trade_deadline}**. Since it is currently **week '
|
||||
f'{current.week}** I am just going to stop you right there.')
|
||||
return
|
||||
if current['week'] < -2:
|
||||
if current.week < -2:
|
||||
await ctx.send(await get_emoji(ctx, 'oof', False))
|
||||
await ctx.send(f'Patience, grasshopper. Trades open soon.')
|
||||
return
|
||||
|
||||
team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
team = await get_team_by_owner(current.season, ctx.author.id)
|
||||
if team is None:
|
||||
await ctx.send(f'Who are you? Why are you talking to me, you don\'t have a team.')
|
||||
return
|
||||
@ -721,7 +722,7 @@ class Transactions(commands.Cog):
|
||||
await trade.timed_delete()
|
||||
return
|
||||
else:
|
||||
next_team = await get_team_by_abbrev(resp, current['season'])
|
||||
next_team = await get_team_by_abbrev(resp, current.season)
|
||||
if next_team is None:
|
||||
await trade.send('Who the fuck even is that? Try again.')
|
||||
else:
|
||||
@ -753,7 +754,7 @@ class Transactions(commands.Cog):
|
||||
else:
|
||||
try:
|
||||
player = await get_player_by_name(
|
||||
current['season'],
|
||||
current.season,
|
||||
await fuzzy_player_search(ctx, trade.channel, self.bot, resp, player_cog.player_list.keys())
|
||||
)
|
||||
except ValueError as e:
|
||||
@ -778,7 +779,7 @@ class Transactions(commands.Cog):
|
||||
await trade.send('RIP this move. Maybe next time.')
|
||||
await trade.timed_delete()
|
||||
else:
|
||||
dest_team = await get_team_by_abbrev(resp, current['season'])
|
||||
dest_team = await get_team_by_abbrev(resp, current.season)
|
||||
if dest_team is None:
|
||||
await trade.send(f'{await get_emoji(ctx, "facepalm")} They aren\'t even part of '
|
||||
f'this trade. Come on.')
|
||||
@ -795,12 +796,12 @@ class Transactions(commands.Cog):
|
||||
await trade.show_moves()
|
||||
|
||||
# Get pick trades
|
||||
# while True and current['pick_trade_end'] >= current['week'] >= current['pick_trade_start']:
|
||||
# while True and current.pick_trade_end >= current.week >= current.pick_trade_start:
|
||||
# prompt = f'Are you trading any draft picks?'
|
||||
# this_q = Question(self.bot, trade.channel, prompt, 'yesno', 300)
|
||||
# resp = await this_q.ask(trade.get_gms(self.bot))
|
||||
# effective_season = current['season'] if OFFSEASON_FLAG else current['season'] + 1
|
||||
# team_season = current['season']
|
||||
# effective_season = current.season if OFFSEASON_FLAG else current.season + 1
|
||||
# team_season = current.season
|
||||
#
|
||||
# if resp is None:
|
||||
# await trade.send('RIP this move. Maybe next time.')
|
||||
@ -878,7 +879,7 @@ class Transactions(commands.Cog):
|
||||
|
||||
# FA drops per team
|
||||
|
||||
if current['week'] > 0:
|
||||
if current.week > 0:
|
||||
for team in trade.teams:
|
||||
while True:
|
||||
this_q.prompt = f'{trade.teams[team]["role"].mention}\nAre you making an FA drop?'
|
||||
@ -903,7 +904,7 @@ class Transactions(commands.Cog):
|
||||
else:
|
||||
try:
|
||||
player = await get_player_by_name(
|
||||
current['season'],
|
||||
current.season,
|
||||
await fuzzy_player_search(ctx, trade.channel, self.bot, resp, player_cog.player_list.keys())
|
||||
)
|
||||
except ValueError as e:
|
||||
@ -916,11 +917,11 @@ class Transactions(commands.Cog):
|
||||
if not trade.included_team(player['team']):
|
||||
await t_channel.send(f'It looks like {player.name} is on {player.team.abbrev} '
|
||||
f'so I can\'t let you do that.')
|
||||
# elif player['demotion_week'] > current['week']:
|
||||
# elif player['demotion_week'] > current.week:
|
||||
# await trade.send(f'Oof. {player["name"]} cannot be dropped until week '
|
||||
# f'{player["demotion_week"]}.')
|
||||
else:
|
||||
dest_team = await get_team_by_abbrev('FA', current['season'])
|
||||
dest_team = await get_team_by_abbrev('FA', current.season)
|
||||
await trade.add_player(player, dest_team)
|
||||
|
||||
await trade.show_moves()
|
||||
@ -983,7 +984,7 @@ class Transactions(commands.Cog):
|
||||
await trade.send(f'All done! Your transaction id is: {trans_id}')
|
||||
try:
|
||||
choas = get_role(ctx, 'CHOAS ALERT')
|
||||
await send_to_channel(self.bot, f'season-{current["season"]}-chat', f'{choas.mention}')
|
||||
await send_to_channel(self.bot, f'season-{current.season}-chat', f'{choas.mention}')
|
||||
except Exception as e:
|
||||
logger.error(f'Couldn\'t ping chaos for a trade')
|
||||
await trade.timed_delete()
|
||||
@ -991,9 +992,9 @@ 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 db_get('current')
|
||||
# current = await get_current()
|
||||
#
|
||||
# if current['week'] < -2:
|
||||
# if current.week < -2:
|
||||
# await ctx.send(await get_emoji(ctx, 'oof', False))
|
||||
# await ctx.send(f'Patience, grasshopper. Trades open up Monday.')
|
||||
# return
|
||||
@ -1002,7 +1003,7 @@ class Transactions(commands.Cog):
|
||||
# await ctx.send(f'You\'ll have to wait, hoss. No pick trades until the offseason.')
|
||||
# return
|
||||
#
|
||||
# team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
# team = await get_team_by_owner(current.season, ctx.author.id)
|
||||
# team_role = get_team_role(ctx, team)
|
||||
# player_cog = self.bot.get_cog('Players')
|
||||
#
|
||||
@ -1062,7 +1063,7 @@ class Transactions(commands.Cog):
|
||||
# return
|
||||
# else:
|
||||
# try:
|
||||
# next_team = await get_team_by_abbrev(resp, current['season'])
|
||||
# next_team = await get_team_by_abbrev(resp, current.season)
|
||||
# except ValueError:
|
||||
# await trade.send('Who the fuck even is that? Try again.')
|
||||
# else:
|
||||
@ -1077,8 +1078,8 @@ class Transactions(commands.Cog):
|
||||
# prompt = f'Are you trading any draft picks?'
|
||||
# this_q = Question(self.bot, trade.channel, prompt, 'yesno', 300)
|
||||
# resp = await this_q.ask(trade.get_gms(self.bot))
|
||||
# effective_season = current['season'] if OFFSEASON_FLAG else current['season'] + 1
|
||||
# team_season = current['season']
|
||||
# effective_season = current.season if OFFSEASON_FLAG else current.season + 1
|
||||
# team_season = current.season
|
||||
#
|
||||
# if resp is None:
|
||||
# await trade.send('RIP this move. Maybe next time.')
|
||||
@ -1198,7 +1199,7 @@ class Transactions(commands.Cog):
|
||||
# await trade.send(f'All done! Your transaction id is: {trans_id}')
|
||||
# try:
|
||||
# choas = get_role(ctx, 'CHOAS ALERT')
|
||||
# await send_to_channel(self.bot, f'season-{current["season"]}-chat', f'{choas.mention}')
|
||||
# await send_to_channel(self.bot, f'season-{current.season}-chat', f'{choas.mention}')
|
||||
# except Exception as e:
|
||||
# logger.error('I was not able to ping CHOAS ALERT')
|
||||
# await trade.timed_delete()
|
||||
@ -1206,22 +1207,22 @@ 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 db_get('current')
|
||||
team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
current = await get_current()
|
||||
team = await get_team_by_owner(current.season, ctx.author.id)
|
||||
# team_schedule = await get_schedule(
|
||||
# current['season'],
|
||||
# current.season,
|
||||
# team_abbrev1=team["abbrev"],
|
||||
# week_start=current['week'] + 1,
|
||||
# week_end=current['week'] + 1,
|
||||
# week_start=current.week + 1,
|
||||
# week_end=current.week + 1,
|
||||
# )
|
||||
s_query = await db_get('games', params=[
|
||||
('season', current['season']), ('team1_id', team['id']), ('week', current['week'] + 1)
|
||||
('season', current.season), ('team1_id', team['id']), ('week', current.week + 1)
|
||||
])
|
||||
team_role = get_team_role(ctx, team)
|
||||
player_cog = self.bot.get_cog('Players')
|
||||
poke_role = get_role(ctx, 'Pokétwo')
|
||||
|
||||
if s_query['count'] == 0 and not OFFSEASON_FLAG and current['week'] != 18:
|
||||
if s_query['count'] == 0 and not OFFSEASON_FLAG and current.week != 18:
|
||||
await ctx.send('It looks like your season is over so transactions are locked.')
|
||||
return
|
||||
|
||||
@ -1247,7 +1248,7 @@ class Transactions(commands.Cog):
|
||||
await dropadd.send(f'Let\'s start here, {team_role.mention}')
|
||||
await ctx.send(f'Take my hand... {dropadd.channel.mention}')
|
||||
await dropadd.send(f'This transaction is for __next week__. It will go into effect for '
|
||||
f'week {current["week"] + 1}.')
|
||||
f'week {current.week + 1}.')
|
||||
|
||||
# Get MiL moves
|
||||
while True and not OFFSEASON_FLAG:
|
||||
@ -1273,7 +1274,7 @@ class Transactions(commands.Cog):
|
||||
else:
|
||||
try:
|
||||
player = await get_player_by_name(
|
||||
current['season'],
|
||||
current.season,
|
||||
await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys())
|
||||
)
|
||||
except ValueError as e:
|
||||
@ -1283,16 +1284,16 @@ class Transactions(commands.Cog):
|
||||
await dropadd.send(f'{await get_emoji(ctx, "squint")}')
|
||||
await dropadd.send('Who even is that? Try again.')
|
||||
else:
|
||||
fa_team = await get_team_by_abbrev('FA', current['season'])
|
||||
dest_team = await get_team_by_abbrev(f'{team["abbrev"]}MiL', current['season'])
|
||||
if current['week'] >= FA_LOCK_WEEK and player['team'] == fa_team:
|
||||
fa_team = await get_team_by_abbrev('FA', current.season)
|
||||
dest_team = await get_team_by_abbrev(f'{team["abbrev"]}MiL', current.season)
|
||||
if current.week >= FA_LOCK_WEEK and player['team'] == fa_team:
|
||||
await dropadd.send(f'FA transactions are locked starting in Week {FA_LOCK_WEEK} so I gotta say no. For more information, search for Rule 34 Draft.')
|
||||
elif not dropadd.included_team(player['team']) and player['team'] != fa_team:
|
||||
await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} '
|
||||
f'so I can\'t let you do that.')
|
||||
elif await dropadd.not_available(player):
|
||||
await dropadd.send(f'Uh oh, looks like {player["name"]} is already on the move next week.')
|
||||
elif player['demotion_week'] > current['week']:
|
||||
elif player['demotion_week'] > current.week:
|
||||
await dropadd.send(f'Oof. {player["name"]} cannot be dropped until week '
|
||||
f'{player["demotion_week"]}.')
|
||||
else:
|
||||
@ -1326,7 +1327,7 @@ class Transactions(commands.Cog):
|
||||
else:
|
||||
try:
|
||||
player = await get_player_by_name(
|
||||
current['season'],
|
||||
current.season,
|
||||
await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys())
|
||||
)
|
||||
except ValueError as e:
|
||||
@ -1343,8 +1344,8 @@ class Transactions(commands.Cog):
|
||||
else:
|
||||
await dropadd.add_player(player, team)
|
||||
else:
|
||||
fa_team = await get_team_by_abbrev('FA', current['season'])
|
||||
if current['week'] >= FA_LOCK_WEEK and player['team'] == fa_team:
|
||||
fa_team = await get_team_by_abbrev('FA', current.season)
|
||||
if current.week >= FA_LOCK_WEEK and player['team'] == fa_team:
|
||||
await dropadd.send(f'FA transactions are locked starting in Week {FA_LOCK_WEEK} so I gotta say no. For more information, run !rule34 <player name>.')
|
||||
elif player['team'] != fa_team and not self.on_team_il(team, player):
|
||||
await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} '
|
||||
@ -1352,7 +1353,7 @@ class Transactions(commands.Cog):
|
||||
elif await dropadd.not_available(player):
|
||||
await dropadd.send(f'Uh oh, looks like {player["name"]} is already on the move '
|
||||
f'next week.')
|
||||
elif player['demotion_week'] > current['week']:
|
||||
elif player['demotion_week'] > current.week:
|
||||
await dropadd.send(f'Oof. {player["name"]} cannot be dropped until week '
|
||||
f'{player["demotion_week"]}.')
|
||||
else:
|
||||
@ -1386,7 +1387,7 @@ class Transactions(commands.Cog):
|
||||
else:
|
||||
try:
|
||||
player = await get_player_by_name(
|
||||
current['season'],
|
||||
current.season,
|
||||
await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys())
|
||||
)
|
||||
except ValueError as e:
|
||||
@ -1401,11 +1402,11 @@ class Transactions(commands.Cog):
|
||||
f'so I can\'t let you do that.')
|
||||
elif await dropadd.not_available(player):
|
||||
await dropadd.send(f'Uh oh, looks like {player["name"]} is already on the move next week.')
|
||||
elif player['demotion_week'] > current['week']:
|
||||
elif player['demotion_week'] > current.week:
|
||||
await dropadd.send(f'Oof. {player["name"]} cannot be dropped until week '
|
||||
f'{player["demotion_week"]}.')
|
||||
else:
|
||||
dest_team = await get_team_by_abbrev('FA', current['season'])
|
||||
dest_team = await get_team_by_abbrev('FA', current.season)
|
||||
await dropadd.add_player(player, dest_team)
|
||||
|
||||
await dropadd.show_moves()
|
||||
@ -1438,7 +1439,7 @@ class Transactions(commands.Cog):
|
||||
errors.append(f'- This is the roster I have for {dropadd.teams[team]["team"]["abbrev"]}:\n'
|
||||
f'```\n{roster_string}```')
|
||||
|
||||
mil_cap = 6 if current['week'] <= FA_LOCK_WEEK else 14
|
||||
mil_cap = 6 if current.week <= FA_LOCK_WEEK else 14
|
||||
if len(data['mil_roster']) > mil_cap:
|
||||
errors.append(
|
||||
f'- {dropadd.teams[team]["team"]["abbrev"]}MiL would have {len(data["mil_roster"])} players'
|
||||
@ -1469,7 +1470,7 @@ class Transactions(commands.Cog):
|
||||
# Run moves
|
||||
trans_id = await dropadd.send_transaction()
|
||||
|
||||
if not current['freeze'] or dropadd.avoid_freeze:
|
||||
if not current.freeze or dropadd.avoid_freeze:
|
||||
await send_to_channel(self.bot, 'transaction-log', embed=await dropadd.show_moves(here=False))
|
||||
|
||||
await dropadd.send(f'All done! Your transaction id is: {trans_id}')
|
||||
@ -1492,7 +1493,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 db_get('current')
|
||||
current = await get_current()
|
||||
|
||||
if OFFSEASON_FLAG:
|
||||
await ctx.send(await get_emoji(ctx, 'oof', False))
|
||||
@ -1500,12 +1501,12 @@ class Transactions(commands.Cog):
|
||||
f'trade and drop players to FA, though!')
|
||||
return
|
||||
|
||||
team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
# team = await get_team_by_abbrev('VA', current['season'])
|
||||
team = await get_team_by_owner(current.season, ctx.author.id)
|
||||
# team = await get_team_by_abbrev('VA', current.season)
|
||||
s_query = await db_get('games', params=[
|
||||
('season', current['season']), ('team1_id', team['id']), ('week', current['week'])
|
||||
('season', current.season), ('team1_id', team['id']), ('week', current.week)
|
||||
])
|
||||
if s_query['count'] == 0 and current['week'] != 18:
|
||||
if s_query['count'] == 0 and current.week != 18:
|
||||
await ctx.send('It looks like your season is over so transactions are locked.')
|
||||
return
|
||||
|
||||
@ -1533,7 +1534,7 @@ class Transactions(commands.Cog):
|
||||
|
||||
await dropadd.send(f'Let\'s start here, {team_role.mention}')
|
||||
await ctx.send(f'Take my hand... {dropadd.channel.mention}')
|
||||
await dropadd.send(f'This transaction is for __this week__. It will go into effect for week {current["week"]}.')
|
||||
await dropadd.send(f'This transaction is for __this week__. It will go into effect for week {current.week}.')
|
||||
|
||||
# Get IL moves
|
||||
while True:
|
||||
@ -1559,7 +1560,7 @@ class Transactions(commands.Cog):
|
||||
else:
|
||||
try:
|
||||
player = await get_player_by_name(
|
||||
current['season'],
|
||||
current.season,
|
||||
await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys())
|
||||
)
|
||||
except ValueError as e:
|
||||
@ -1573,7 +1574,7 @@ class Transactions(commands.Cog):
|
||||
await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} '
|
||||
f'so I can\'t let you do that.')
|
||||
else:
|
||||
dest_team = await get_team_by_abbrev(f'{team["abbrev"]}IL', current['season'])
|
||||
dest_team = await get_team_by_abbrev(f'{team["abbrev"]}IL', current.season)
|
||||
await dropadd.add_player(player, dest_team)
|
||||
|
||||
await dropadd.show_moves()
|
||||
@ -1602,7 +1603,7 @@ class Transactions(commands.Cog):
|
||||
else:
|
||||
try:
|
||||
player = await get_player_by_name(
|
||||
current['season'],
|
||||
current.season,
|
||||
await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys())
|
||||
)
|
||||
except ValueError as e:
|
||||
@ -1644,7 +1645,7 @@ class Transactions(commands.Cog):
|
||||
else:
|
||||
try:
|
||||
player = await get_player_by_name(
|
||||
current['season'],
|
||||
current.season,
|
||||
await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys())
|
||||
)
|
||||
except ValueError as e:
|
||||
@ -1657,11 +1658,11 @@ class Transactions(commands.Cog):
|
||||
if not dropadd.included_team(player['team']):
|
||||
await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} '
|
||||
f'so I can\'t let you do that.')
|
||||
# elif player['demotion_week'] > current['week']:
|
||||
# elif player['demotion_week'] > current.week:
|
||||
# await dropadd.send(f'Oof. {player["name"]} cannot be dropped until week '
|
||||
# f'{player["demotion_week"]}.')
|
||||
else:
|
||||
dest_team = await get_team_by_abbrev(f'{team["abbrev"]}MiL', current['season'])
|
||||
dest_team = await get_team_by_abbrev(f'{team["abbrev"]}MiL', current.season)
|
||||
await dropadd.add_player(player, dest_team)
|
||||
|
||||
await dropadd.show_moves()
|
||||
@ -1690,7 +1691,7 @@ class Transactions(commands.Cog):
|
||||
else:
|
||||
try:
|
||||
player = await get_player_by_name(
|
||||
current['season'],
|
||||
current.season,
|
||||
await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys())
|
||||
)
|
||||
except ValueError as e:
|
||||
@ -1703,11 +1704,11 @@ class Transactions(commands.Cog):
|
||||
if not dropadd.included_team(player['team']):
|
||||
await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} '
|
||||
f'so I can\'t let you do that.')
|
||||
# elif player['demotion_week'] > current['week']:
|
||||
# elif player['demotion_week'] > current.week:
|
||||
# await dropadd.send(f'Oof. {player["name"]} cannot be dropped until week '
|
||||
# f'{player["demotion_week"]}.')
|
||||
else:
|
||||
dest_team = await get_team_by_abbrev('FA', current['season'])
|
||||
dest_team = await get_team_by_abbrev('FA', current.season)
|
||||
await dropadd.add_player(player, dest_team)
|
||||
|
||||
await dropadd.show_moves()
|
||||
@ -1767,7 +1768,7 @@ class Transactions(commands.Cog):
|
||||
for player_move in [*dropadd.players.values()]:
|
||||
this_guy = copy.deepcopy(player_move['player'])
|
||||
this_guy['team'] = player_move['to']
|
||||
this_guy['demotion_week'] = current['week']
|
||||
this_guy['demotion_week'] = current.week
|
||||
await put_player(this_guy)
|
||||
|
||||
await send_to_channel(self.bot, 'transaction-log', embed=await dropadd.show_moves(here=False))
|
||||
@ -1778,35 +1779,35 @@ 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 db_get('current')
|
||||
team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
current = await get_current()
|
||||
team = await get_team_by_owner(current.season, ctx.author.id)
|
||||
# set_moves = await get_transactions(
|
||||
# current['season'],
|
||||
# current.season,
|
||||
# team_abbrev=team['abbrev'],
|
||||
# week_start=current['week']+1,
|
||||
# week_end=current['week']+1
|
||||
# week_start=current.week+1,
|
||||
# week_end=current.week+1
|
||||
# )
|
||||
t_query = await db_get('transactions', params=[
|
||||
('season', current['season']), ('week_start', current['week']),
|
||||
('week_end', current['season']), ('team_abbrev', team['abbrev'])
|
||||
('season', current.season), ('week_start', current.week),
|
||||
('week_end', current.season), ('team_abbrev', team['abbrev'])
|
||||
])
|
||||
set_moves = t_query['transactions']
|
||||
# frozen_moves = await get_transactions(
|
||||
# current['season'],
|
||||
# current.season,
|
||||
# team_abbrev=team['abbrev'],
|
||||
# week_start=current['week']+1,
|
||||
# week_end=current['week']+1,
|
||||
# week_start=current.week+1,
|
||||
# week_end=current.week+1,
|
||||
# frozen=True
|
||||
# )
|
||||
t_query = await db_get('transactions', params=[
|
||||
('season', current['season']), ('week_start', current['week']),
|
||||
('week_end', current['season']), ('team_abbrev', team['abbrev']), ('frozen', True)
|
||||
('season', current.season), ('week_start', current.week),
|
||||
('week_end', current.season), ('team_abbrev', team['abbrev']), ('frozen', True)
|
||||
])
|
||||
frozen_moves = t_query['transactions']
|
||||
logger.info(f'Num Moves: {len(set_moves)}')
|
||||
|
||||
embed = get_team_embed(f'{team["lname"]} Guaranteed Transactions', team=team)
|
||||
embed.description = f'Week {current["week"] + 1} Moves'
|
||||
embed.description = f'Week {current.week + 1} Moves'
|
||||
guaranteed = {}
|
||||
frozen = {}
|
||||
|
||||
@ -1843,11 +1844,11 @@ 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: str):
|
||||
current = await db_get('current')
|
||||
current = await get_current()
|
||||
if team_abbrev:
|
||||
this_team = await get_team_by_abbrev(team_abbrev, current['season'])
|
||||
this_team = await get_team_by_abbrev(team_abbrev, current.season)
|
||||
else:
|
||||
this_team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
this_team = await get_team_by_owner(current.season, ctx.author.id)
|
||||
|
||||
# this_week_team = await get_team_roster(this_team, 'current')
|
||||
# next_week_team = await get_team_roster(this_team, 'next')
|
||||
@ -1860,9 +1861,9 @@ class Transactions(commands.Cog):
|
||||
for roster in [this_week_team, next_week_team]:
|
||||
embed = get_team_embed(f'{this_team["lname"]} Roster Check', team=this_team)
|
||||
if count == 0:
|
||||
embed.description = f'Week {current["week"]}'
|
||||
embed.description = f'Week {current.week}'
|
||||
else:
|
||||
embed.description = f'Week {current["week"] + 1}'
|
||||
embed.description = f'Week {current.week + 1}'
|
||||
|
||||
errors = []
|
||||
|
||||
@ -1909,11 +1910,11 @@ 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 db_get('current')
|
||||
team = await get_team_by_owner(current['season'], owner_id=ctx.author.id)
|
||||
il_team = await get_team_by_abbrev(f'{team["abbrev"]}MiL', current['season'])
|
||||
current = await get_current()
|
||||
team = await get_team_by_owner(current.season, owner_id=ctx.author.id)
|
||||
il_team = await get_team_by_abbrev(f'{team["abbrev"]}MiL', current.season)
|
||||
|
||||
if current['week'] != 0:
|
||||
if current.week != 0:
|
||||
logger.info('entering the thot check')
|
||||
await react_and_reply(ctx, '👀', 'https://c.tenor.com/FCAj8xDvEHwAAAAC/be-gone-thot.gif')
|
||||
player_role = get_role(ctx, SBA_PLAYERS_ROLE_NAME)
|
||||
@ -1947,7 +1948,7 @@ class Transactions(commands.Cog):
|
||||
logger.error(f'Could not demote {x} for {team["abbrev"]}: {e}')
|
||||
errors.append(x)
|
||||
else:
|
||||
player = await get_player_by_name(current['season'], player_name)
|
||||
player = await get_player_by_name(current.season, player_name)
|
||||
if player['team']['id'] != team['id']:
|
||||
await ctx.send(f'Omg stop trying to make {player["name"]} happen. It\'s not going to happen.')
|
||||
else:
|
||||
@ -1958,8 +1959,8 @@ class Transactions(commands.Cog):
|
||||
'player_id': player['id'],
|
||||
'oldteam_id': team['id'],
|
||||
'newteam_id': il_team['id'],
|
||||
'season': current['season'],
|
||||
'moveid': f's{current["season"]}-draft-tomil-{team["abbrev"]}'
|
||||
'season': current.season,
|
||||
'moveid': f's{current.season}-draft-tomil-{team["abbrev"]}'
|
||||
})
|
||||
|
||||
if len(moves) == 0:
|
||||
@ -1978,8 +1979,8 @@ class Transactions(commands.Cog):
|
||||
|
||||
@commands.command(name='calisamazing', help='Make up for your idiocy')
|
||||
async def cal_is_amazing_command(self, ctx):
|
||||
current = await db_get('current')
|
||||
team = await get_team_by_owner(current['season'], owner_id=ctx.author.id)
|
||||
current = await get_current()
|
||||
team = await get_team_by_owner(current.season, owner_id=ctx.author.id)
|
||||
|
||||
if not team:
|
||||
await ctx.send(random_conf_gif())
|
||||
|
||||
21
helpers.py
21
helpers.py
@ -655,7 +655,7 @@ async def team_emoji(ctx, team):
|
||||
return emoji
|
||||
|
||||
|
||||
async def fuzzy_player_search(ctx, channel, bot, name, master_list, author = None):
|
||||
async def fuzzy_player_search(ctx, channel, bot, name, master_list, author = None) -> str:
|
||||
"""
|
||||
Takes a name to search and returns the name of the best match
|
||||
|
||||
@ -702,7 +702,7 @@ async def fuzzy_player_search(ctx, channel, bot, name, master_list, author = Non
|
||||
if not resp:
|
||||
return None
|
||||
if resp < count:
|
||||
return matches[resp - 1]
|
||||
return matches[resp - 1] # type: ignore
|
||||
else:
|
||||
raise ValueError(f'{resp} is not a valid response.')
|
||||
|
||||
@ -790,6 +790,7 @@ def get_role(ctx, role_name, bot=None):
|
||||
|
||||
|
||||
def get_team_role(ctx, team, bot=None):
|
||||
logger.info(f'getting team role for: {team}')
|
||||
return get_role(ctx, team['lname'], bot)
|
||||
|
||||
|
||||
@ -811,7 +812,7 @@ async def send_to_channel(bot, channel_name, content=None, embed=None):
|
||||
|
||||
async def get_player_embed(player, current, ctx=None, season=None):
|
||||
if season is None:
|
||||
season = current['season']
|
||||
season = current.season
|
||||
player_name = player['name']
|
||||
if player['il_return']:
|
||||
if player['team']['abbrev'][-2:].lower() == 'il':
|
||||
@ -819,7 +820,7 @@ async def get_player_embed(player, current, ctx=None, season=None):
|
||||
else:
|
||||
player_name = f'{await get_emoji(ctx, "WeenieHut", False)}{player_name}'
|
||||
embed = get_team_embed(f'{player_name}', player["team"])
|
||||
embed.set_footer(text=f'SBa Season {current["season"]}', icon_url=LOGO)
|
||||
embed.set_footer(text=f'SBa Season {current.season}', icon_url=LOGO)
|
||||
embed.add_field(name='Player ID', value=f'{player["id"]}')
|
||||
embed.set_image(url=player['image'])
|
||||
# embed.description = f'Player ID {player["id"]}'
|
||||
@ -834,11 +835,11 @@ async def get_player_embed(player, current, ctx=None, season=None):
|
||||
embed.set_thumbnail(url=player_photo)
|
||||
|
||||
t_query = await db_get('transactions', params=[
|
||||
('season', current['season']), ('week_start', current['week']), ('week_end', current['week'] + 1),
|
||||
('season', current.season), ('week_start', current.week), ('week_end', current.week + 1),
|
||||
('player_id', player['id'])
|
||||
])
|
||||
d_query = await db_get('draftpicks', params=[
|
||||
('season', current['season']), ('player_id', player['id'])
|
||||
('season', current.season), ('player_id', player['id'])
|
||||
])
|
||||
|
||||
positions = get_player_positions(player)
|
||||
@ -876,14 +877,14 @@ async def get_player_embed(player, current, ctx=None, season=None):
|
||||
major_team = await get_team_by_abbrev(player['team']['abbrev'][:-3], season=player['season'])
|
||||
embed.add_field(name='SBa Affiliate', value=major_team['sname'])
|
||||
if player['demotion_week'] is not None:
|
||||
if player['demotion_week'] > current['week']:
|
||||
if player['demotion_week'] > current.week:
|
||||
embed.add_field(name='Dem Week', value=player["demotion_week"])
|
||||
if player['il_return']:
|
||||
embed.add_field(name='IL Return', value=player['il_return'])
|
||||
for x in t_query['transactions']:
|
||||
if x['week'] == current['week']:
|
||||
if x['week'] == current.week:
|
||||
embed.add_field(name='Last Week', value=f'{x["oldteam"]["sname"]}')
|
||||
if x['week'] == current['week'] + 1:
|
||||
if x['week'] == current.week + 1:
|
||||
embed.add_field(name='Next Week', value=f'To {x["newteam"]["sname"]}')
|
||||
|
||||
if player['season'] < 8:
|
||||
@ -1103,7 +1104,7 @@ async def log_injury(current: dict, inj_dict: dict) -> None:
|
||||
crange=f'A{current["injury_count"]+2}',
|
||||
values=[[
|
||||
datetime.datetime.now().strftime('%Y-%m-%d, %H:%M:%S'), inj_dict['player']['name'], inj_dict['type'],
|
||||
inj_dict['player']['team']['abbrev'], current['week'], inj_dict['current_game'],
|
||||
inj_dict['player']['team']['abbrev'], current.week, inj_dict['current_game'],
|
||||
inj_dict['injury_length']
|
||||
]]
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user