Updating cogs for new v3 API
This commit is contained in:
parent
09aad6acc3
commit
3cc12d2cf1
@ -1,7 +1,7 @@
|
||||
import copy
|
||||
|
||||
from helpers import *
|
||||
from db_calls import db_get, db_post, patch_player, get_player_by_name
|
||||
from db_calls import db_get, db_patch, db_post, patch_player, get_player_by_name, patch_draftpick
|
||||
|
||||
import csv
|
||||
import math
|
||||
@ -233,6 +233,7 @@ class Admins(commands.Cog):
|
||||
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
|
||||
|
||||
def get_pos_nickname(position):
|
||||
if 'B' in position:
|
||||
@ -252,6 +253,13 @@ class Admins(commands.Cog):
|
||||
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', 2),
|
||||
('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:
|
||||
@ -266,6 +274,11 @@ class Admins(commands.Cog):
|
||||
f'{this_player["name"]} ({this_player["wara"]:.2f})\n'
|
||||
keeper_swar += this_player['wara']
|
||||
|
||||
this_pick = picks[count]
|
||||
this_pick['player'] = this_player
|
||||
await patch_draftpick(this_pick)
|
||||
count += 1
|
||||
|
||||
resp = await db_post('keepers', payload={
|
||||
'count': len(k_list),
|
||||
'keepers': k_list
|
||||
|
||||
43
cogs/dice.py
43
cogs/dice.py
@ -24,7 +24,7 @@ class Dice(commands.Cog):
|
||||
try:
|
||||
team_abbrev = re.split('-', channel.name)
|
||||
if len(team_abbrev[0]) <= 4 and team_abbrev not in ['the', 'city']:
|
||||
team = await get_team_by_abbrev(team_abbrev[0])
|
||||
team = await get_team_by_abbrev(team_abbrev[0], SBA_SEASON)
|
||||
else:
|
||||
team = None
|
||||
except (ValueError, AttributeError, requests.ReadTimeout) as e:
|
||||
@ -240,6 +240,7 @@ class Dice(commands.Cog):
|
||||
])
|
||||
async def injury_roll_slash(self, interaction: discord.Interaction, rating: Choice[int], games: Choice[int]):
|
||||
team = None
|
||||
await interaction.response.defer()
|
||||
|
||||
d_six_one = random.randint(1, 6)
|
||||
d_six_two = random.randint(1, 6)
|
||||
@ -317,18 +318,34 @@ class Dice(commands.Cog):
|
||||
|
||||
injury_list = inj_data[p_ratings[rating.value - 1]][f'p{games.value}']
|
||||
injury_result = injury_list[injury_roll - 3]
|
||||
logging.info(f'injury rating: {rating.value}p{games.value} / array: {injury_list}[{injury_roll - 2}] / result: {injury_result}')
|
||||
logging.info(
|
||||
f'injury rating: {rating.value}p{games.value} / array: {injury_list}[{injury_roll - 2}] / result: {injury_result}')
|
||||
|
||||
if isinstance(injury_result, int):
|
||||
await interaction.response.send_message(random_salute_gif())
|
||||
try:
|
||||
await interaction.edit_original_response(
|
||||
content=random_gif(random_from_list(['salute', 'press f', 'pay respects']))
|
||||
)
|
||||
except Exception as e:
|
||||
logging.info(f'failed to post funny gif')
|
||||
injury_string += f'With a roll of {injury_roll}, the injury length is **{injury_result} ' \
|
||||
f'game{"s" if injury_result > 1 else ""}**.'
|
||||
elif injury_result == 'REM':
|
||||
await interaction.response.send_message(random_salute_gif())
|
||||
try:
|
||||
await interaction.edit_original_response(
|
||||
content=random_gif(random_from_list(['could be worse', 'not too bad']))
|
||||
)
|
||||
except Exception as e:
|
||||
logging.info(f'failed to post funny gif')
|
||||
injury_string += f'With a roll of {injury_roll}, the injury length is **REMAINDER OF GAME** for batters ' \
|
||||
f'or **FATIGUED** for pitchers'
|
||||
else:
|
||||
await interaction.response.send_message(random_conf_gif())
|
||||
try:
|
||||
await interaction.edit_original_response(
|
||||
content=random_gif(random_from_list(['it is fine', 'nothing to see here', 'i wasn\'t worried']))
|
||||
)
|
||||
except Exception as e:
|
||||
logging.info(f'failed to post funny gif')
|
||||
injury_string += f'With a roll of {injury_roll}, the player is **OKAY** - no injury!'
|
||||
|
||||
embed = await self.get_dice_embed(
|
||||
@ -340,14 +357,14 @@ class Dice(commands.Cog):
|
||||
|
||||
await interaction.channel.send(content=None, embed=embed)
|
||||
|
||||
this_roll = {
|
||||
'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
|
||||
}
|
||||
self.rolls.append(this_roll)
|
||||
# this_roll = {
|
||||
# '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
|
||||
# }
|
||||
# self.rolls.append(this_roll)
|
||||
|
||||
@commands.command(name='c', aliases=['chaos', 'choas'], help='c, chaos, or choas')
|
||||
async def chaos_roll(self, ctx):
|
||||
|
||||
231
cogs/draft.py
231
cogs/draft.py
@ -12,6 +12,7 @@ class Draft(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.warnings = 0
|
||||
self.pick_lock = False
|
||||
|
||||
self.draft_loop.start()
|
||||
|
||||
@ -38,7 +39,7 @@ class Draft(commands.Cog):
|
||||
current = await db_get('current')
|
||||
# draft_pick = await get_one_draftpick_byoverall(current['season'], draft_data['currentpick'])
|
||||
p_query = await db_get('draftpicks', params=[
|
||||
('season', current['season']), ('overall', draft_data['currentpick'])
|
||||
('season', current['season']), ('overall', draft_data['currentpick']), ('short_output', False)
|
||||
])
|
||||
if p_query['count'] == 0:
|
||||
raise ValueError(f'No pick found for overall #{draft_data["currentpick"]}')
|
||||
@ -147,10 +148,11 @@ class Draft(commands.Cog):
|
||||
logging.info(f'current: {current}\nd_data: {draft_data}')
|
||||
# this_pick = await get_one_draftpick_byoverall(current['season'], draft_data['currentpick'])
|
||||
p_query = await db_get('draftpicks', params=[
|
||||
('season', current['season']), ('overall', draft_data['currentpick'])
|
||||
('season', current['season']), ('overall', draft_data['currentpick']), ('short_output', False)
|
||||
])
|
||||
if p_query['count'] == 0:
|
||||
raise ValueError(f'No pick found for overall #{draft_data["currentpick"]}')
|
||||
|
||||
this_pick = p_query['picks'][0]
|
||||
logging.info(f'pick: {this_pick}')
|
||||
this_team = await db_get('teams', object_id=this_pick['owner']['id'])
|
||||
@ -172,7 +174,7 @@ class Draft(commands.Cog):
|
||||
|
||||
# players = await get_players(current['season'], team_abbrev=this_team['abbrev'], sort='wara-desc')
|
||||
p_query = await db_get('players', params=[
|
||||
('season', current['season']), ('team_abbrev', this_team['abbrev']), ('sort', 'cost-desc')
|
||||
('season', current['season']), ('team_id', this_team['id']), ('sort', 'cost-desc')
|
||||
])
|
||||
if p_query['count'] > 0:
|
||||
count = 0
|
||||
@ -192,16 +194,15 @@ class Draft(commands.Cog):
|
||||
if 'active' in r_query:
|
||||
embed.add_field(name=f'{this_team["sname"]} sWAR', value=f'{r_query["active"]["WARa"]:.2f}')
|
||||
|
||||
embed.add_field(
|
||||
name=f'{this_team["abbrev"]} Roster Page',
|
||||
value=f'https://sombaseball.ddns.net/teams?abbrev={this_team["abbrev"]}',
|
||||
inline=False
|
||||
)
|
||||
# embed.add_field(
|
||||
# name=f'{this_team["abbrev"]} Roster Page',
|
||||
# value=f'https://sombaseball.ddns.net/teams?abbrev={this_team["abbrev"]}',
|
||||
# inline=False
|
||||
# )
|
||||
|
||||
embed.add_field(
|
||||
name=f'Draft Sheet',
|
||||
value=f'https://docs.google.com/spreadsheets/d/1BgySsUlQf9K21_uOjQOY7O0GrRfF6zt1BBaEFlvBokY/'
|
||||
f'edit#gid=937613012',
|
||||
value=f'https://docs.google.com/spreadsheets/d/{SBA_SEASON8_DRAFT_KEY}',
|
||||
inline=False
|
||||
)
|
||||
|
||||
@ -211,7 +212,8 @@ class Draft(commands.Cog):
|
||||
# )
|
||||
# last_five = dict(sorted(all_picks.items(), key=lambda item: item[1]["overall"], reverse=True))
|
||||
l_query = await db_get('draftpicks', params=[
|
||||
('season', current['season']), ('sort', 'order-desc'), ('limit', 5)
|
||||
('season', current['season']), ('sort', 'order-desc'), ('limit', 5), ('short_output', False),
|
||||
('overall_end', this_pick['overall'] - 1), ('player_taken', True)
|
||||
])
|
||||
last_string = ''
|
||||
count = 0
|
||||
@ -231,16 +233,12 @@ class Draft(commands.Cog):
|
||||
# )
|
||||
# next_five = dict(sorted(all_picks.items(), key=lambda item: item[1]["overall"]))
|
||||
n_query = await db_get('draftpicks', params=[
|
||||
('season', current['season']), ('sort', 'order-asc'), ('limit', 5)
|
||||
('season', current['season']), ('sort', 'order-asc'), ('limit', 5), ('short_output', False),
|
||||
('overall_start', this_pick['overall'] + 1)
|
||||
])
|
||||
next_string = ''
|
||||
count = 0
|
||||
for x in n_query['picks']:
|
||||
if x['player'] is not None:
|
||||
next_string += f'Pick #{x["overall"]}: {x["owner"]["sname"]}\n'
|
||||
count += 1
|
||||
if count >= 5:
|
||||
break
|
||||
next_string += f'Pick #{x["overall"]}: {x["owner"]["sname"]}\n'
|
||||
if len(next_string) == 0:
|
||||
next_string = 'None, yet'
|
||||
embed.add_field(name='Next 5', value=next_string)
|
||||
@ -248,8 +246,9 @@ class Draft(commands.Cog):
|
||||
# Pick Deadline
|
||||
if draft_data['pick_deadline']:
|
||||
deadline = datetime.datetime.strptime(draft_data['pick_deadline'], '%Y-%m-%dT%H:%M:%S.%f')
|
||||
deadline = deadline - datetime.timedelta(hours=6)
|
||||
# deadline = deadline - datetime.timedelta(hours=6)
|
||||
dead_string = deadline.strftime("%b %d @ %H:%M Central")
|
||||
# dead_string = f'<t:{deadline.timestamp()}>'
|
||||
else:
|
||||
dead_string = 'None'
|
||||
embed.add_field(name='Pick Deadline', value=dead_string, inline=False)
|
||||
@ -257,17 +256,20 @@ class Draft(commands.Cog):
|
||||
await send_to_channel(self.bot, draft_data['ping_channel'], content=team_ping, embed=embed)
|
||||
|
||||
async def advance_pick(self):
|
||||
self.pick_lock = True
|
||||
current = await db_get('current')
|
||||
draft_data = await db_get('draftdata')
|
||||
starting_round = math.ceil(draft_data['currentpick'] / 16)
|
||||
|
||||
# draft_pick = await get_one_draftpick_byoverall(current['season'], draft_data['currentpick'])
|
||||
p_query = await db_get('draftpicks', params=[
|
||||
('season', current['season']), ('overall', draft_data['currentpick'])
|
||||
('season', current['season']), ('overall', draft_data['currentpick']), ('short_output', False)
|
||||
])
|
||||
if p_query['count'] == 0:
|
||||
raise ValueError(f'No pick found for overall #{draft_data["currentpick"]}')
|
||||
draft_pick = p_query['picks'][0]
|
||||
|
||||
if not draft_pick['player']:
|
||||
if draft_pick['player'] is None:
|
||||
await send_to_channel(
|
||||
self.bot,
|
||||
draft_data['ping_channel'],
|
||||
@ -275,35 +277,40 @@ class Draft(commands.Cog):
|
||||
)
|
||||
self.warnings = 0
|
||||
# await patch_draftdata(currentpick=draft_data['currentpick'] + 1)
|
||||
await db_patch('draftdata', object_id=draft_data['id'], params=[('currentpick', draft_data['currentpick'] + 1)])
|
||||
|
||||
draft_data = await db_patch('draftdata', object_id=draft_data['id'], params=[
|
||||
('currentpick', draft_data['currentpick'] + 1)
|
||||
])
|
||||
# Advance the current pick until a selection is possible
|
||||
while True:
|
||||
draft_data = await db_get('draftdata')
|
||||
# draft_data = await db_get('draftdata')
|
||||
# draft_pick = await get_one_draftpick_byoverall(current['season'], draft_data['currentpick'])
|
||||
if draft_data['currentpick'] > 512:
|
||||
await send_to_channel(self.bot, draft_data['ping_channel'], 'Looks like that is the end of the draft!')
|
||||
await db_patch('draftdata', object_id=draft_data['id'], params=[('timer', False)])
|
||||
self.pick_lock = False
|
||||
return
|
||||
|
||||
p_query = await db_get('draftpicks', params=[
|
||||
('season', current['season']), ('overall', draft_data['currentpick'])
|
||||
('season', current['season']), ('overall', draft_data['currentpick']), ('short_output', False)
|
||||
])
|
||||
if p_query['count'] == 0:
|
||||
raise ValueError(f'No pick found for overall #{draft_data["currentpick"]}')
|
||||
draft_pick = p_query['picks'][0]
|
||||
|
||||
# Check that selection has been made for current pick, advance if so
|
||||
if not draft_pick:
|
||||
await send_to_channel(self.bot, draft_data['ping_channel'], 'Looks like that is the end of the draft!')
|
||||
# await patch_draftdata(timer=False)
|
||||
await db_patch('draftdata', object_id=draft_data['id'], params=[('timer', False)])
|
||||
return
|
||||
elif draft_pick['player']:
|
||||
if draft_pick['player'] is not None:
|
||||
# await patch_draftdata(currentpick=draft_data['currentpick'] + 1)
|
||||
await db_patch('draftdata', object_id=draft_data['id'], params=[
|
||||
draft_data = await db_patch('draftdata', object_id=draft_data['id'], params=[
|
||||
('currentpick', draft_data['currentpick'] + 1)
|
||||
])
|
||||
else:
|
||||
round_num = math.ceil(draft_data['currentpick'] / 16)
|
||||
if round_num > starting_round:
|
||||
await send_to_channel(self.bot, draft_data['result_channel'], f'# Round {round_num}')
|
||||
break
|
||||
|
||||
# If timer is true, set new deadline
|
||||
draft_data = await db_get('draftdata')
|
||||
# draft_data = await db_get('draftdata') # No longer needed
|
||||
if draft_data['timer']:
|
||||
await self.update_timer(draft_data)
|
||||
else:
|
||||
@ -313,6 +320,7 @@ class Draft(commands.Cog):
|
||||
|
||||
# Post splash screen to ping_channel
|
||||
await self.send_draft_ping()
|
||||
self.pick_lock = False
|
||||
|
||||
async def send_pick_to_sheets(self, draft_pick, player, pick_num):
|
||||
sheets = pygsheets.authorize(service_file='storage/major-domo-service-creds.json')
|
||||
@ -326,7 +334,7 @@ class Draft(commands.Cog):
|
||||
player['wara']
|
||||
]]
|
||||
|
||||
sheets.open_by_key(SBA_SEASON7_DRAFT_KEY).worksheet_by_title('Ordered List').update_values(
|
||||
sheets.open_by_key(SBA_SEASON8_DRAFT_KEY).worksheet_by_title('Ordered List').update_values(
|
||||
crange=f'D{draft_pick["overall"] + 1}',
|
||||
values=this_pick
|
||||
)
|
||||
@ -351,7 +359,7 @@ class Draft(commands.Cog):
|
||||
total_swar = 0
|
||||
count = 0
|
||||
|
||||
for x in reversed(team_roster['active']['players']):
|
||||
for x in team_roster['active']['players']:
|
||||
count += 1
|
||||
if count > max_counted:
|
||||
break
|
||||
@ -379,12 +387,12 @@ class Draft(commands.Cog):
|
||||
)
|
||||
# await patch_draftpick(draft_pick['id'], player_id=player['id'])
|
||||
draft_pick['player'] = player
|
||||
await patch_draftpick(draft_pick)
|
||||
await patch_draftpick(draft_pick) # TODO: uncomment for live draft
|
||||
|
||||
player['team'] = draft_pick['owner']
|
||||
player['demotion_week'] = 2
|
||||
# await patch_player(player['id'], team_id=draft_pick['owner']['id'], demotion_week=2)
|
||||
await patch_player(player)
|
||||
await patch_player(player) # TODO: uncomment for live draft
|
||||
|
||||
# await post_transactions([{
|
||||
# 'week': -1,
|
||||
@ -397,7 +405,7 @@ class Draft(commands.Cog):
|
||||
await db_post('transactions', payload={'count': 1, 'moves': [{
|
||||
'week': 0,
|
||||
'player_id': player['id'],
|
||||
'oldteam_id': 201, # FA team ID
|
||||
'oldteam_id': 302, # FA team ID
|
||||
'newteam_id': draft_pick['owner']['id'],
|
||||
'season': current['season'],
|
||||
'moveid': f'draft-overall-{draft_pick["overall"]}'
|
||||
@ -431,17 +439,15 @@ class Draft(commands.Cog):
|
||||
return {'success': True}
|
||||
|
||||
async def draftdata_to_string(self, current, draft_data):
|
||||
try:
|
||||
# draft_pick = await get_one_draftpick_byoverall(current['season'], draft_data['currentpick'])
|
||||
p_query = await db_get('draftpicks', params=[
|
||||
('season', current['season']), ('overall', draft_data['currentpick'])
|
||||
])
|
||||
if p_query['count'] == 0:
|
||||
raise ValueError(f'No pick found for overall #{draft_data["currentpick"]}')
|
||||
draft_pick = p_query['picks'][0]
|
||||
except Exception as e:
|
||||
logging.error(f'draft cog - Could not get current draft pick: {e}')
|
||||
draft_pick = None
|
||||
p_query = await db_get('draftpicks', params=[
|
||||
('season', current['season']), ('overall', draft_data['currentpick']), ('short_output', False)
|
||||
])
|
||||
if p_query['count'] == 0:
|
||||
raise ValueError(f'No pick found for overall #{draft_data["currentpick"]}')
|
||||
|
||||
draft_pick = p_query['picks'][0]
|
||||
logging.info(f'draft_pick: {draft_pick}')
|
||||
|
||||
if draft_data['pick_deadline']:
|
||||
deadline = datetime.datetime.strptime(draft_data['pick_deadline'], '%Y-%m-%dT%H:%M:%S.%f')
|
||||
deadline = deadline - datetime.timedelta(hours=6)
|
||||
@ -450,15 +456,18 @@ class Draft(commands.Cog):
|
||||
dead_string = 'None'
|
||||
|
||||
guild = self.bot.get_guild(int(os.environ.get('GUILD_ID')))
|
||||
|
||||
p_channel = discord.utils.get(guild.text_channels, id=draft_data["ping_channel"])
|
||||
r_channel = discord.utils.get(guild.text_channels, id=draft_data["result_channel"])
|
||||
|
||||
draft_string = f'Current Pick: {draft_data["currentpick"]}\n' \
|
||||
f'Pick Owner: {draft_pick["owner"]["sname"] if draft_pick else "N/A"}\n' \
|
||||
f'Timer: {"Active" if draft_data["timer"] else "Inactive"} ' \
|
||||
f'({draft_data["pick_minutes"]} min total)\n' \
|
||||
f'Pick Deadline: {dead_string}\n' \
|
||||
f'Ping Channel: ' \
|
||||
f'{discord.utils.get(guild.text_channels, id=draft_data["ping_channel"]).mention}\n' \
|
||||
f'Result Channel: ' \
|
||||
f'{discord.utils.get(guild.text_channels, id=draft_data["result_channel"]).mention}\n'
|
||||
f'Ping Channel: {p_channel.mention}\n' \
|
||||
f'Result Channel: {r_channel.mention}\n'
|
||||
logging.info(f'draft_string: {draft_string}')
|
||||
|
||||
return draft_string
|
||||
|
||||
@ -485,17 +494,31 @@ class Draft(commands.Cog):
|
||||
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||
async def draft_command(self, ctx, *, name):
|
||||
cal_can_pick_for_all = True
|
||||
|
||||
if 'strider' in name.lower():
|
||||
await ctx.send(f'Ope. Strider has been reserved for Cal.')
|
||||
|
||||
if self.pick_lock:
|
||||
await react_and_reply(ctx, '❌', 'Another pick is already in the works.')
|
||||
return
|
||||
else:
|
||||
self.pick_lock = True
|
||||
|
||||
current = await db_get('current')
|
||||
team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
if not team:
|
||||
await ctx.message.add_reaction('❌')
|
||||
await ctx.send('I don\'t know youuuuuuuuu')
|
||||
return
|
||||
if ctx.author.id == 403294362550796299:
|
||||
team = await get_team_by_abbrev('HAM', current['season'])
|
||||
else:
|
||||
await ctx.message.add_reaction('❌')
|
||||
await ctx.send('I don\'t know youuuuuuuuu')
|
||||
self.pick_lock = False
|
||||
return
|
||||
|
||||
draft_data = await db_get('draftdata')
|
||||
# draft_pick = await get_one_draftpick_byoverall(current['season'], draft_data['currentpick'])
|
||||
p_query = await db_get('draftpicks', params=[
|
||||
('season', current['season']), ('overall', draft_data['currentpick'])
|
||||
('season', current['season']), ('overall', draft_data['currentpick']), ('short_output', False)
|
||||
])
|
||||
if p_query['count'] == 0:
|
||||
raise ValueError(f'No pick found for overall #{draft_data["currentpick"]}')
|
||||
@ -511,35 +534,36 @@ class Draft(commands.Cog):
|
||||
# )
|
||||
p_query = await db_get('draftpicks', params=[
|
||||
('season', current['season']), ('owner_team_id', team['id']), ('round_start', 1),
|
||||
('round_end', math.ceil(draft_pick['overall'] / 16)), ('sort', 'overall-asc')
|
||||
]) # TODO: finish updating this query for raw_picks
|
||||
('round_end', math.ceil(draft_pick['overall'] / 16)), ('sort', 'overall-asc'), ('short_output', False)
|
||||
])
|
||||
if p_query['count'] == 0:
|
||||
raise ValueError(f'Draft picks for {team["abbrev"]} not found')
|
||||
|
||||
new_pick = None
|
||||
for x in p_query['picks']:
|
||||
if not x["player"] and x['overall'] < draft_pick['overall']:
|
||||
if x["player"] is None and x['overall'] < draft_pick['overall']:
|
||||
# new_pick = await get_one_draftpick_byoverall(current['season'], team_picks[x]['overall'])
|
||||
p_query = await db_get('draftpicks', params=[
|
||||
('season', current['season']), ('overall', x['overall'])
|
||||
])
|
||||
if p_query['count'] == 0:
|
||||
raise ValueError(f'No pick found for overall #{x["overall"]}')
|
||||
new_pick = p_query['picks'][0]
|
||||
# p_query = await db_get('draftpicks', params=[
|
||||
# ('season', current['season']), ('overall', x['overall']), ('short_output', False)
|
||||
# ])
|
||||
# if p_query['count'] == 0:
|
||||
# raise ValueError(f'No pick found for overall #{x["overall"]}')
|
||||
new_pick = x
|
||||
break
|
||||
|
||||
if new_pick:
|
||||
if new_pick is not None:
|
||||
draft_pick = new_pick
|
||||
else:
|
||||
mil_team = await get_team_by_abbrev(f'{team["abbrev"]}MiL', current['season'])
|
||||
if mil_team == draft_pick['owner']:
|
||||
team = mil_team
|
||||
elif ctx.author.id == self.bot.owner_id and cal_can_pick_for_all:
|
||||
# mil_team = await get_team_by_abbrev(f'{team["abbrev"]}MiL', current['season'])
|
||||
# if mil_team == draft_pick['owner']:
|
||||
# team = mil_team
|
||||
if ctx.author.id == self.bot.owner_id and cal_can_pick_for_all:
|
||||
alt_pick_flag = False
|
||||
else:
|
||||
await ctx.message.add_reaction('❌')
|
||||
await ctx.send(f'You are not on the clock {ctx.author.mention}. **{draft_pick["owner"]["abbrev"]}** is '
|
||||
f'up right now.')
|
||||
self.pick_lock = False
|
||||
return
|
||||
|
||||
player_cog = self.bot.get_cog('Players')
|
||||
@ -547,6 +571,7 @@ class Draft(commands.Cog):
|
||||
player = await get_player_by_name(current['season'], player_name)
|
||||
|
||||
the_pick = await self.draft_player(current, draft_data, draft_pick, player)
|
||||
self.pick_lock = False
|
||||
if the_pick['success']:
|
||||
await ctx.message.add_reaction('✅')
|
||||
if not alt_pick_flag:
|
||||
@ -555,7 +580,7 @@ class Draft(commands.Cog):
|
||||
await react_and_reply(ctx, '❌', the_pick['error'])
|
||||
|
||||
@commands.command(name='list', aliases=['draftlist', 'mylist'], help='Set your draft list')
|
||||
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||
# @commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||
async def draft_list_command(self, ctx, *player_list):
|
||||
current = await db_get('current')
|
||||
team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
@ -626,12 +651,10 @@ class Draft(commands.Cog):
|
||||
current = await db_get('current')
|
||||
draft_data = await db_get('draftdata')
|
||||
|
||||
logging.info(f'building draft string')
|
||||
await ctx.send(await self.draftdata_to_string(current, draft_data))
|
||||
if draft_data["ping_channel"]:
|
||||
try:
|
||||
await self.send_draft_ping(ping=False)
|
||||
except Exception as e:
|
||||
logging.error(f'!whomst - Could not post current draft ping: {e}')
|
||||
if draft_data["ping_channel"] is not None:
|
||||
await self.send_draft_ping(ping=False)
|
||||
|
||||
@app_commands.command(name='draft-mod', description='Mod commands for draft administration')
|
||||
@app_commands.checks.has_any_role('Da Commish')
|
||||
@ -647,7 +670,7 @@ class Draft(commands.Cog):
|
||||
async def draftmod_slash_command(
|
||||
self, interaction: discord.Interaction, result_channel: TextChannel = None,
|
||||
ping_channel: TextChannel = None, current_overall: int = None, timer_master: int = None,
|
||||
timer_this_pick: int = None, timer_active: bool = None, wipe_pick: int = None):
|
||||
timer_this_pick: int = None, timer_active: bool = None, wipe_pick: int = None, pick_lock: bool = None):
|
||||
await interaction.response.defer()
|
||||
current = await db_get('current')
|
||||
draft_data = await db_get('draftdata')
|
||||
@ -659,7 +682,7 @@ class Draft(commands.Cog):
|
||||
if wipe_pick is not None:
|
||||
# this_pick = await get_one_draftpick_byoverall(current['season'], overall=wipe_pick)
|
||||
p_query = await db_get('draftpicks', params=[
|
||||
('season', current['season']), ('overall', wipe_pick)
|
||||
('season', current['season']), ('overall', wipe_pick), ('short_output', False)
|
||||
])
|
||||
if p_query['count'] == 0:
|
||||
raise ValueError(f'No pick found for overall #{wipe_pick}')
|
||||
@ -682,22 +705,41 @@ class Draft(commands.Cog):
|
||||
)
|
||||
return
|
||||
|
||||
if timer_this_pick is not None:
|
||||
pick_deadline = datetime.datetime.now() + datetime.timedelta(minutes=timer_this_pick)
|
||||
if timer_active is True:
|
||||
if timer_this_pick is not None:
|
||||
timer = timer_this_pick
|
||||
elif timer_master is not None:
|
||||
timer = timer_master
|
||||
if pick_lock is not None:
|
||||
if pick_lock:
|
||||
self.pick_lock = True
|
||||
else:
|
||||
timer = draft_data['pick_minutes']
|
||||
pick_deadline = datetime.datetime.now() + datetime.timedelta(minutes=timer)
|
||||
self.pick_lock = False
|
||||
|
||||
params = []
|
||||
if timer_this_pick is not None:
|
||||
params.append(('pick_deadline', datetime.datetime.now() + datetime.timedelta(minutes=timer_this_pick)))
|
||||
if timer_active is not None:
|
||||
params.append(('timer', timer_active))
|
||||
if timer_active is True:
|
||||
if timer_this_pick is not None:
|
||||
timer = timer_this_pick
|
||||
elif timer_master is not None:
|
||||
timer = timer_master
|
||||
params.append(('pick_minutes', timer_master))
|
||||
else:
|
||||
timer = draft_data['pick_minutes']
|
||||
deadline = datetime.datetime.now() + datetime.timedelta(minutes=timer)
|
||||
else:
|
||||
deadline = datetime.datetime.now() + datetime.timedelta(weeks=1)
|
||||
params.append(('pick_deadline', deadline))
|
||||
if result_channel is not None:
|
||||
res_channel_id = result_channel.id
|
||||
params.append(('result_channel', result_channel.id))
|
||||
if ping_channel is not None:
|
||||
ping_channel_id = ping_channel.id
|
||||
params.append(('ping_channel', ping_channel.id))
|
||||
if current_overall is not None and draft_data['timer'] and timer_active is None:
|
||||
pick_deadline = datetime.datetime.now() + datetime.timedelta(minutes=draft_data['pick_minutes'])
|
||||
params.append(
|
||||
('pick_deadline', datetime.datetime.now() + datetime.timedelta(minutes=draft_data['pick_minutes']))
|
||||
)
|
||||
if current_overall is not None:
|
||||
params.append(('currentpick', current_overall))
|
||||
if timer_master is not None:
|
||||
params.append(('pick_minutes', timer_master))
|
||||
|
||||
# await patch_draftdata(
|
||||
# currentpick=current_overall,
|
||||
@ -707,10 +749,7 @@ class Draft(commands.Cog):
|
||||
# ping_channel=ping_channel_id,
|
||||
# pick_minutes=timer_master
|
||||
# )
|
||||
await db_patch('draftdata', object_id=draft_data['id'], params=[
|
||||
('currentpick', current_overall), ('timer', timer_active), ('pick_deadline', pick_deadline),
|
||||
('result_channel', res_channel_id), ('ping_channel', ping_channel_id), ('pick_minutes', timer_master)
|
||||
])
|
||||
await db_patch('draftdata', object_id=draft_data['id'], params=params)
|
||||
|
||||
draft_data = await db_get('draftdata')
|
||||
await interaction.edit_original_response(content=await self.draftdata_to_string(current, draft_data))
|
||||
@ -719,7 +758,7 @@ class Draft(commands.Cog):
|
||||
self.warnings = 0
|
||||
# draft_pick = await get_one_draftpick_byoverall(current['season'], draft_data['currentpick'])
|
||||
p_query = await db_get('draftpicks', params=[
|
||||
('season', current['season']), ('overall', wipe_pick)
|
||||
('season', current['season']), ('overall', draft_data['currentpick']), ('short_output', False)
|
||||
])
|
||||
if p_query['count'] == 0:
|
||||
raise ValueError(f'No pick found for overall #{wipe_pick}')
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import discord.ext.commands
|
||||
from discord.ext import commands
|
||||
from discord import Interaction
|
||||
from discord.app_commands import AppCommandError
|
||||
@ -10,7 +11,9 @@ class ExceptionHandler(commands.Cog):
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_command_error(self, ctx: commands.Context, error) -> None:
|
||||
if error[:7] == 'Command' and 'not found' in error:
|
||||
e_string = f'{error}'
|
||||
logging.error(e_string)
|
||||
if 'Command' in e_string and 'not found' in e_string:
|
||||
pass
|
||||
else:
|
||||
await ctx.send(f'Hmm...do you know what this error means:\n\n{error}')
|
||||
|
||||
@ -172,7 +172,6 @@ class Fun(commands.Cog):
|
||||
async def on_message_listener(self, message):
|
||||
if message.author.bot or message.channel.guild.id != int(os.environ.get('GUILD_ID')) \
|
||||
or message.content[:1] == '!':
|
||||
logging.info(f'skipping mention of soaking')
|
||||
return
|
||||
|
||||
tm = message.content.lower()
|
||||
|
||||
373
cogs/players.py
373
cogs/players.py
@ -8,9 +8,8 @@ from discord import app_commands
|
||||
from discord.ext import tasks
|
||||
from discord.app_commands import Choice
|
||||
|
||||
from db_calls_gameplay import get_one_game
|
||||
from helpers import *
|
||||
from db_calls import db_get, db_patch, get_team_by_abbrev, get_team_by_owner, patch_player, get_player_by_name
|
||||
from db_calls import db_get, db_patch, get_team_by_abbrev, get_team_by_owner, patch_player, get_player_by_name, db_post
|
||||
from typing import Literal
|
||||
|
||||
|
||||
@ -373,7 +372,7 @@ class Players(commands.Cog):
|
||||
f'Streak: {team_standings["streak_wl"].upper()}{team_standings["streak_num"]}'
|
||||
|
||||
embed.add_field(name=f'{team["sname"]} Overview', value=overview_string, inline=False)
|
||||
except ValueError as e:
|
||||
except (ValueError, TypeError) as e:
|
||||
logging.info(f'Could not pull standings for season {team["season"]} {team["abbrev"]}')
|
||||
|
||||
# Get player info
|
||||
@ -468,6 +467,9 @@ class Players(commands.Cog):
|
||||
current = await db_get('current')
|
||||
season = current['season']
|
||||
|
||||
if 'strider' in name.lower():
|
||||
await ctx.send(f'Ope. Strider has been reserved for Cal.')
|
||||
|
||||
name_reg = re.compile(r'(s\d+)* *(.*)', re.IGNORECASE)
|
||||
player_search = name_reg.search(name)
|
||||
logging.info(f'player_search: {player_search}')
|
||||
@ -1709,360 +1711,10 @@ class Players(commands.Cog):
|
||||
|
||||
await interaction.edit_original_response(content=None, embeds=embeds)
|
||||
|
||||
# @commands.command(name='setcolor', help='Set team color')
|
||||
# @commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||
# async def set_color_command(self, ctx, color_code):
|
||||
# current = await db_get('current')
|
||||
# team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
# team_role = get_team_role(ctx, team)
|
||||
# color_int = int(color_code, 16)
|
||||
#
|
||||
# if not team or not team_role:
|
||||
# await ctx.send(f'Do you have a team here? You don\'t look familiar. {await get_emoji(ctx, "realeyes")}')
|
||||
# return
|
||||
#
|
||||
# await team_role.edit(colour=color_int)
|
||||
# await patch_team(team, color=color_code)
|
||||
# team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
#
|
||||
# embed = get_team_embed(f'{team["lname"]} Test', team=team)
|
||||
# embed.add_field(
|
||||
# name='Reminder',
|
||||
# value='Don\'t forget to set your team thumbnail image with the !setthumbnail command!'
|
||||
# )
|
||||
# await ctx.send(content='Got it! What do you think?', embed=embed)
|
||||
#
|
||||
# @commands.command(name='setthumbnail', help='Set team pic')
|
||||
# @commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||
# async def set_thumbnail_command(self, ctx, thumbnail_url):
|
||||
# current = await db_get('current')
|
||||
# team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
# team_role = get_team_role(ctx, team)
|
||||
#
|
||||
# if not team or not team_role:
|
||||
# await ctx.send(f'Do you have a team here? You don\'t look familiar. {await get_emoji(ctx, "realeyes")}')
|
||||
# return
|
||||
#
|
||||
# if requests.get(thumbnail_url, timeout=0.5).status_code != 200:
|
||||
# await ctx.send('I wasn\'t able to pull that thumbnail. Was it a public URL?')
|
||||
#
|
||||
# await patch_team(team, thumbnail=thumbnail_url)
|
||||
# team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
#
|
||||
# embed = get_team_embed(f'{team["lname"]} Test', team=team)
|
||||
# embed.add_field(
|
||||
# name='Reminder',
|
||||
# value='Don\'t forget to set your team color with the !setcolor command!'
|
||||
# )
|
||||
#
|
||||
# await ctx.send(content='Got it! What do you think?', embed=embed)
|
||||
#
|
||||
# @commands.command(name='setminorthumbnail', help='Set minor team pic')
|
||||
# @commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||
# async def set_minor_pic_command(self, ctx, thumbnail_url):
|
||||
# current = await db_get('current')
|
||||
# team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
# minor_team = await get_one_team(team['id'] + 2)
|
||||
#
|
||||
# if not minor_team:
|
||||
# await ctx.send(f'Do you have a team here? You don\'t look familiar. {await get_emoji(ctx, "realeyes")}')
|
||||
# return
|
||||
#
|
||||
# if requests.get(thumbnail_url, timeout=0.5).status_code != 200:
|
||||
# await ctx.send('I wasn\'t able to pull that thumbnail. Was it a public URL?')
|
||||
#
|
||||
# await patch_team(minor_team, thumbnail=thumbnail_url)
|
||||
# minor_team = await get_one_team(team['id'] + 2)
|
||||
#
|
||||
# embed = get_team_embed(f'{minor_team["sname"]} Test', team=minor_team)
|
||||
# embed.add_field(
|
||||
# name='Reminder',
|
||||
# value='Don\'t forget to set your team color with the !setminorcolor command!'
|
||||
# )
|
||||
# await ctx.send(content='Got it! What do you think?', embed=embed)
|
||||
#
|
||||
# @commands.command(name='setminorcolor', help='Set minor team color')
|
||||
# @commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||
# async def set_minor_color_command(self, ctx, color_code):
|
||||
# current = await db_get('current')
|
||||
# team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
# minor_team = await get_one_team(team['id'] + 2)
|
||||
#
|
||||
# if not minor_team:
|
||||
# await ctx.send(f'Do you have a team here? You don\'t look familiar. {await get_emoji(ctx, "realeyes")}')
|
||||
# return
|
||||
#
|
||||
# await patch_team(minor_team, color=color_code)
|
||||
# minor_team = await get_one_team(team['id'] + 2)
|
||||
# team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
#
|
||||
# embed = get_team_embed(f'{minor_team["sname"]} Test', team=minor_team)
|
||||
# embed.add_field(
|
||||
# name='Reminder',
|
||||
# value='Don\'t forget to set your team thumbnail image with the !setminorthumbnail command!'
|
||||
# )
|
||||
# await ctx.send(content='Got it! What do you think?', embed=embed)
|
||||
#
|
||||
# @commands.command(name='setdicecolor', help='Set dice embed color')
|
||||
# @commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||
# async def set_dice_color_command(self, ctx, color_code):
|
||||
# current = await db_get('current')
|
||||
# team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
#
|
||||
# await patch_team(team, dice_color=color_code)
|
||||
# embed = discord.Embed(
|
||||
# title=f'Dice Color: {color_code}',
|
||||
# color=int(color_code, 16)
|
||||
# )
|
||||
# embed.add_field(
|
||||
# name='Reminder',
|
||||
# value='Any dice rolled in your home stadium will use this color!'
|
||||
# )
|
||||
# await ctx.send(content=None, embed=embed)
|
||||
|
||||
@commands.command(name='picks', aliases=['mypicks', 'draftpicks'], help='See your picks')
|
||||
async def picks_command(self, ctx, *team_abbrev):
|
||||
await ctx.send('Go away.')
|
||||
return
|
||||
# current = await db_get('current')
|
||||
#
|
||||
# if team_abbrev:
|
||||
# team = await get_one_team(team_abbrev[0])
|
||||
# else:
|
||||
# team = await get_team_by_owner(current['season'], ctx.author.id)
|
||||
#
|
||||
# if not team:
|
||||
# await ctx.send('I don\'t know what team you\'re looking for.')
|
||||
# return
|
||||
#
|
||||
# raw_picks = await get_draftpicks(season=5, owner_team=team, team_season=5)
|
||||
# logging.info(f'raw_picks: {raw_picks}')
|
||||
# try:
|
||||
# all_picks = dict(sorted(raw_picks.items(), key=lambda item: item[1]["overall"]))
|
||||
# except TypeError as e:
|
||||
# all_picks = dict(sorted(raw_picks.items(), key=lambda item: item[1]["round"]))
|
||||
# pick_string = ''
|
||||
#
|
||||
# for x in all_picks:
|
||||
# squiggles = '~~' if all_picks[x]['player'] else ''
|
||||
# selection = f'- {all_picks[x]["player"]["name"]}' if all_picks[x]["player"] else ''
|
||||
# overall = f'#{all_picks[x]["overall"]} - ' if all_picks[x]["overall"] else ''
|
||||
# pick_string += f'{squiggles}{overall}{all_picks[x]["origowner"]["abbrev"]} {all_picks[x]["round"]}' \
|
||||
# f'{squiggles} {selection}\n'
|
||||
#
|
||||
# embed = get_team_embed(f'{team["lname"]}', team=team)
|
||||
# embed.add_field(name=f'Season {current["season"]} Draft Picks', value=pick_string)
|
||||
#
|
||||
# await ctx.send(content=None, embed=embed)
|
||||
|
||||
# @commands.command(name='fixscore', help='Change result')
|
||||
# @commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||
# async def fix_score_command(
|
||||
# self, ctx, away_team, away_score: int, home_team, home_score: int, week_num: int, game_num: int):
|
||||
# current = await db_get('current')
|
||||
# week_games = await get_results(current['season'], away_abbrev=away_team, home_abbrev=home_team, week=week_num)
|
||||
# this_game = None
|
||||
#
|
||||
# for x in week_games:
|
||||
# if week_games[x]['game'] == game_num:
|
||||
# this_game = week_games[x]
|
||||
# break
|
||||
#
|
||||
# if this_game is None:
|
||||
# await ctx.send('I don\'t see a record of that game. Make sure you\'ve got the week and game number right. '
|
||||
# 'If so, go ahead and log it with the !result command')
|
||||
# return
|
||||
#
|
||||
# if this_game['awayscore'] == away_score and this_game['homescore'] == home_score:
|
||||
# await ctx.send('Good news, everyone! That is already the score I have listed!')
|
||||
# return
|
||||
#
|
||||
# await ctx.send(f'I\'ve got that game listed as {this_game["awayteam"]["abbrev"]} '
|
||||
# f'{await team_emoji(ctx, this_game["awayteam"])} {this_game["awayscore"]} @ '
|
||||
# f'{this_game["homescore"]} {await team_emoji(ctx, this_game["hometeam"])} '
|
||||
# f'{this_game["hometeam"]["abbrev"]}')
|
||||
# prompt = f'Would you like to change this to {this_game["awayteam"]["abbrev"]} ' \
|
||||
# f'{await team_emoji(ctx, this_game["awayteam"])} {away_score} @ ' \
|
||||
# f'{home_score} {await team_emoji(ctx, this_game["hometeam"])} {this_game["hometeam"]["abbrev"]}?'
|
||||
# this_q = Question(self.bot, ctx.channel, prompt, 'yesno', 30)
|
||||
# resp = await this_q.ask([ctx.author])
|
||||
#
|
||||
# if not resp:
|
||||
# await ctx.send('Mmkay. I\'ll leave it alone for now.')
|
||||
# return
|
||||
# else:
|
||||
# if await patch_result(this_game['id'], away_score=away_score, home_score=home_score):
|
||||
# await ctx.message.add_reaction('✅')
|
||||
# await ctx.send(f'{get_team_role(ctx, this_game["awayteam"]).mention} '
|
||||
# f'{get_team_role(ctx, this_game["hometeam"]).mention}')
|
||||
# await ctx.send(random_conf_gif())
|
||||
|
||||
# @commands.command(name='newaward', help='Grant award')
|
||||
# @commands.has_any_role('Awards Team', 'Da Commish')
|
||||
# async def new_award_command(self, ctx, *, award_name):
|
||||
# # f'{"In-Season" if in_or_off.lower() == "in" else "Off-Season"}'
|
||||
# current = await db_get('current')
|
||||
# award = {
|
||||
# 'name': award_name,
|
||||
# 'season': None,
|
||||
# 'timing': None,
|
||||
# 'manager1': None,
|
||||
# 'manager2': None,
|
||||
# 'player': None,
|
||||
# 'team': None,
|
||||
# 'image': None,
|
||||
# 'invalid': False
|
||||
# }
|
||||
#
|
||||
# async def add_recipient(search_string):
|
||||
# try:
|
||||
# this_team = await get_one_team(search_string, season=award['season'])
|
||||
# award['team'] = this_team
|
||||
# except ValueError:
|
||||
# try:
|
||||
# this_manager = await get_one_manager(search_string)
|
||||
# if not award['manager1']:
|
||||
# award['manager1'] = this_manager
|
||||
# else:
|
||||
# award['manager2'] = this_manager
|
||||
# except ValueError:
|
||||
# try:
|
||||
# search_name = await fuzzy_player_search(
|
||||
# ctx, ctx.channel, self.bot, search_string, self.player_list)
|
||||
# this_player = await get_one_player(search_name, season=award['season'])
|
||||
# award['player'] = this_player
|
||||
# except ValueError:
|
||||
# try:
|
||||
# this_player = await get_one_player(search_string, season=award['season'])
|
||||
# award['player'] = this_player
|
||||
# except ValueError:
|
||||
# await ctx.send(f'I do not recognize **{search_string}**. Will you check the spelling and '
|
||||
# f'try again?')
|
||||
#
|
||||
# def get_embed():
|
||||
# this_embed = discord.Embed(title=award['name'])
|
||||
# this_embed.description = f'{award["timing"]} - S{award["season"]}'
|
||||
# if award['manager1']:
|
||||
# this_embed.add_field(name='Manager', value=award['manager1'])
|
||||
# if award['manager2']:
|
||||
# this_embed.add_field(name='Manager', value=award['manager2'])
|
||||
# if award['player']:
|
||||
# this_embed.add_field(name='Player', value=f'{award["player"]["name"]}')
|
||||
# if award['team']:
|
||||
# this_embed.add_field(name='Team', value=f'{award["team"]["lname"]}')
|
||||
# if award['image']:
|
||||
# try:
|
||||
# this_embed.set_image(url=award['image'])
|
||||
# except:
|
||||
# award['invalid'] = True
|
||||
# this_embed.add_field(name='Image', value='Invalid URL')
|
||||
# return this_embed
|
||||
#
|
||||
# prompt = f'Is this for season {current["season"]}?'
|
||||
# this_q = Question(self.bot, ctx.channel, prompt, 'yesno', timeout=45)
|
||||
# resp = await this_q.ask([ctx.author])
|
||||
#
|
||||
# if resp is None:
|
||||
# await ctx.send('Think on it. Get back to me.')
|
||||
# return
|
||||
# elif resp:
|
||||
# award['season'] = current['season']
|
||||
# else:
|
||||
# prompt = 'Please enter the season for this award.'
|
||||
# this_q = Question(self.bot, ctx.channel, prompt, 'int', timeout=45)
|
||||
# resp = await this_q.ask([ctx.author])
|
||||
#
|
||||
# if not resp:
|
||||
# await ctx.send('Think on it. Get back to me.')
|
||||
# return
|
||||
# else:
|
||||
# award['season'] = resp
|
||||
#
|
||||
# prompt = f'Is this an In-Season award (as opposed to off-season)?'
|
||||
# this_q = Question(self.bot, ctx.channel, prompt, 'yesno', timeout=45)
|
||||
# resp = await this_q.ask([ctx.author])
|
||||
#
|
||||
# if resp is None:
|
||||
# await ctx.send('Think on it. Get back to me.')
|
||||
# return
|
||||
# elif resp:
|
||||
# award['timing'] = 'In-Season'
|
||||
# else:
|
||||
# award['timing'] = 'Off-Season'
|
||||
# await ctx.send('Got it - I\'ll put this down as an Off-Season award')
|
||||
#
|
||||
# prompt = 'Is this the start you wanted?'
|
||||
# this_q = Question(self.bot, ctx.channel, prompt, 'yesno', timeout=45, embed=get_embed())
|
||||
# resp = await this_q.ask([ctx.author])
|
||||
#
|
||||
# if not resp:
|
||||
# await ctx.send('No worries - run `!newaward Award_Name` again to rename it.')
|
||||
# return
|
||||
#
|
||||
# # Get team/player/managers
|
||||
# while True:
|
||||
# prompt = 'Please enter the team abbreviation, player name, or manager name of the recipient.'
|
||||
# this_q = Question(self.bot, ctx.channel, prompt, 'text', timeout=45)
|
||||
# resp = await this_q.ask([ctx.author])
|
||||
#
|
||||
# if resp is None:
|
||||
# await ctx.send('You think on it and hit me up when you\'re ready.')
|
||||
# return
|
||||
# else:
|
||||
# await add_recipient(resp)
|
||||
#
|
||||
# await ctx.send('Here is the current award', embed=get_embed())
|
||||
#
|
||||
# prompt = 'Would you like to (re)enter a recipient?'
|
||||
# this_q = Question(self.bot, ctx.channel, prompt, 'yesno', timeout=45)
|
||||
# resp = await this_q.ask([ctx.author])
|
||||
#
|
||||
# if resp is None:
|
||||
# await ctx.send('We can hold off on this for now. Let me know when you\'re ready to start again.')
|
||||
# return
|
||||
# elif not resp:
|
||||
# break
|
||||
#
|
||||
# # Get image URL
|
||||
# while True:
|
||||
# prompt = 'Would you like to (re)enter an image URL for this award?'
|
||||
# this_q = Question(self.bot, ctx.channel, prompt, 'yesno', timeout=45, embed=get_embed())
|
||||
# resp = await this_q.ask([ctx.author])
|
||||
#
|
||||
# if not resp:
|
||||
# break
|
||||
# else:
|
||||
# prompt = 'Please enter the image URL.'
|
||||
# this_q = Question(self.bot, ctx.channel, prompt, 'url', timeout=45)
|
||||
# resp = await this_q.ask([ctx.author])
|
||||
#
|
||||
# if resp is None:
|
||||
# await ctx.send('Okey doke, nevermind. I get it. It\'s fine. We only did all this work for nothing. '
|
||||
# 'Let me know when you want to start again.')
|
||||
# return
|
||||
# elif not resp:
|
||||
# await ctx.send(f'**{resp}** is not a valid URL.')
|
||||
# else:
|
||||
# award['image'] = resp
|
||||
#
|
||||
# prompt = 'Would you like to submit this award?'
|
||||
# this_q = Question(self.bot, ctx.channel, prompt, 'yesno', timeout=45, embed=get_embed())
|
||||
# resp = await this_q.ask([ctx.author])
|
||||
#
|
||||
# if not resp:
|
||||
# await ctx.send('Really? After all the ti- nevermind. Fine. Kill it. It\'s over. Bye.')
|
||||
# return
|
||||
# else:
|
||||
# await post_award(award)
|
||||
# await ctx.send(random_conf_gif())
|
||||
#
|
||||
# @commands.command(name='record', help='Record through week num')
|
||||
# async def record_command(self, ctx, team_abbrev, week_num: int):
|
||||
# this_team = await get_one_team(team_abbrev)
|
||||
# this_record = await get_team_record(this_team, week_num)
|
||||
#
|
||||
# await ctx.send(f'The {this_team["sname"]} were ({this_record["w"]}-{this_record["l"]}) through '
|
||||
# f'week {week_num}.')
|
||||
|
||||
@commands.command(name='vc', aliases=['voice', 'gameplay'], help='Get voice channel')
|
||||
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME, 'Paper Dynasty Players')
|
||||
@ -2415,18 +2067,15 @@ class Players(commands.Cog):
|
||||
|
||||
this_scorecard = self.scorecards[f'{interaction.channel_id}']
|
||||
if not this_scorecard:
|
||||
this_game = get_one_game(channel_id=interaction.channel_id)
|
||||
if not this_game:
|
||||
await interaction.response.send_message(
|
||||
'Uhh...I don\'t see any games in this channel. You in the right place?'
|
||||
)
|
||||
return
|
||||
await interaction.response.send_message(
|
||||
'Uhh...I don\'t see any games in this channel. You in the right place?'
|
||||
)
|
||||
return
|
||||
|
||||
embed = self.bot.get_cog('Gameplay').get_game_state_embed(this_game, full_length=False)
|
||||
await interaction.response.send_message(content=None, embed=embed)
|
||||
await interaction.response.send_message(f'I am checking sheets now...', ephemeral=True)
|
||||
|
||||
score_text = this_scorecard.get_value('A1')
|
||||
await interaction.response.send_message(score_text)
|
||||
await interaction.edit_original_response(content=score_text)
|
||||
|
||||
@app_commands.command(name='injury', description='Make an injury check; rating = left of "p", games = right')
|
||||
@app_commands.guilds(discord.Object(id=os.environ.get('GUILD_ID')))
|
||||
|
||||
@ -150,7 +150,7 @@ class SBaTransaction:
|
||||
])
|
||||
# mil_roster = await get_players(self.current['season'], f'{this_team["abbrev"]}MiL')
|
||||
m_query = await db_get('players', params=[
|
||||
('season', self.current['season']), ('team_id', ml_query['teams'][0])
|
||||
('season', self.current['season']), ('team_id', f'{this_team["abbrev"]}MiL')
|
||||
])
|
||||
mil_roster = m_query['players']
|
||||
|
||||
@ -159,6 +159,7 @@ class SBaTransaction:
|
||||
for player in mil_roster:
|
||||
mil_wara += player['wara']
|
||||
|
||||
logging.info(f'checking future moves')
|
||||
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,
|
||||
@ -175,7 +176,7 @@ class SBaTransaction:
|
||||
# )
|
||||
t_query = await db_get('transactions', params=[
|
||||
('season', self.current['season']), ('week_start', self.effective_week),
|
||||
('week_end', self.effective_week), ('team_abbrev', this_team['abbrev'])
|
||||
('week_end', self.effective_week), ('team_abbrev', this_team['abbrev']), ('frozen', True)
|
||||
])
|
||||
freeze_moves = t_query['transactions']
|
||||
moves = set_moves + freeze_moves
|
||||
@ -199,6 +200,7 @@ class SBaTransaction:
|
||||
mil_roster.remove(x['player'])
|
||||
mil_wara -= x['player']['wara']
|
||||
|
||||
logging.info(f'updating rosters')
|
||||
for x in self.players:
|
||||
# If player is joining this team, add to roster and add WARa
|
||||
if self.players[x]['to'] == this_team:
|
||||
@ -322,9 +324,6 @@ class Transactions(commands.Cog):
|
||||
|
||||
self.weekly_loop.start()
|
||||
|
||||
async def cog_command_error(self, ctx, error):
|
||||
await ctx.send(f'{error}')
|
||||
|
||||
@tasks.loop(minutes=1)
|
||||
async def weekly_loop(self):
|
||||
try:
|
||||
@ -1008,28 +1007,32 @@ class Transactions(commands.Cog):
|
||||
|
||||
# Check legality for all teams
|
||||
errors = []
|
||||
roster_errors = []
|
||||
for team in trade.teams:
|
||||
data = await trade.check_major_league_errors(team)
|
||||
logging.warning(f'Done checking data - checking WARa now ({data["wara"]}')
|
||||
|
||||
if data['wara'] > 38.001:
|
||||
if data['wara'] > 38.001 and not OFFSEASON_FLAG:
|
||||
errors.append(f'- {trade.teams[team]["team"]["abbrev"]} would have {data["wara"]:.2f} WARa')
|
||||
|
||||
logging.warning(f'Now checking roster {len(data["roster"])}')
|
||||
if len(data['roster']) > 26:
|
||||
if len(data['roster']) > 26 and not OFFSEASON_FLAG:
|
||||
errors.append(f'- {trade.teams[team]["team"]["abbrev"]} would have {len(data["roster"])} players')
|
||||
|
||||
logging.warning(f'Any errors? {errors}')
|
||||
if data['wara'] > 38.001 or len(data['roster']) > 26:
|
||||
if (data['wara'] > 38.001 or len(data['roster']) > 26) and not OFFSEASON_FLAG:
|
||||
roster_string = ''
|
||||
for x in data['roster']:
|
||||
roster_string += f'{data["roster"][x]["wara"]: >5} - {data["roster"][x]["name"]}\n'
|
||||
errors.append(f'- This is the roster I have for {trade.teams[team]["team"]["abbrev"]}:\n'
|
||||
roster_string += f'{x["wara"]: >5} - {x["name"]}\n'
|
||||
roster_errors.append(f'- This is the roster I have for {trade.teams[team]["team"]["abbrev"]}:\n'
|
||||
f'```\n{roster_string}```')
|
||||
|
||||
if len(errors) > 0:
|
||||
if len(errors) + len(roster_errors) > 0:
|
||||
error_message = '\n'.join(errors)
|
||||
await trade.send(f'Yikes. I\'m gonna put the kibosh on this trade. Below is why:\n\n{error_message}')
|
||||
if len(roster_errors) > 0:
|
||||
for x in roster_errors:
|
||||
await trade.send(x)
|
||||
await trade.timed_delete()
|
||||
return
|
||||
|
||||
@ -1495,6 +1498,7 @@ class Transactions(commands.Cog):
|
||||
|
||||
# Check legality
|
||||
errors = []
|
||||
roster_errors = []
|
||||
for team in dropadd.teams:
|
||||
data = await dropadd.check_major_league_errors(team)
|
||||
logging.warning(f'Done checking data - checking WARa now ({data["wara"]})')
|
||||
@ -1503,14 +1507,14 @@ class Transactions(commands.Cog):
|
||||
errors.append(f'- {dropadd.teams[team]["team"]["abbrev"]} would have {data["wara"]:.2f} sWAR')
|
||||
|
||||
logging.warning(f'Now checking roster {len(data["roster"])}')
|
||||
if len(data['roster']) > 26:
|
||||
if len(data['roster']) > 26 and not OFFSEASON_FLAG:
|
||||
errors.append(f'- {dropadd.teams[team]["team"]["abbrev"]} would have {len(data["roster"])} players')
|
||||
|
||||
logging.warning(f'Any errors? {errors}')
|
||||
if (data['wara'] > 38.001 and not OFFSEASON_FLAG) or len(data['roster']) > 26:
|
||||
if (data['wara'] > 38.001 or len(data['roster']) > 26) and not OFFSEASON_FLAG:
|
||||
roster_string = ''
|
||||
for x in data['roster']:
|
||||
roster_string += f'{data["roster"][x]["wara"]: >5} - {data["roster"][x]["name"]}\n'
|
||||
roster_string += f'{x["wara"]: >5} - {x["name"]}\n'
|
||||
errors.append(f'- This is the roster I have for {dropadd.teams[team]["team"]["abbrev"]}:\n'
|
||||
f'```\n{roster_string}```')
|
||||
|
||||
@ -1519,9 +1523,12 @@ class Transactions(commands.Cog):
|
||||
f'- {dropadd.teams[team]["team"]["abbrev"]}MiL would have {len(data["mil_roster"])} players'
|
||||
)
|
||||
|
||||
if len(errors) > 0:
|
||||
error_string = "\n".join(errors)
|
||||
await dropadd.send(f'Woof. Gotta say no to this one. Below is why.\n\n{error_string}')
|
||||
if len(errors) + len(roster_errors) > 0:
|
||||
error_message = '\n'.join(errors)
|
||||
await dropadd.send(f'Yikes. I\'m gonna put the kibosh on this move. Below is why:\n\n{error_message}')
|
||||
if len(roster_errors) > 0:
|
||||
for x in roster_errors:
|
||||
await dropadd.send(x)
|
||||
await dropadd.timed_delete()
|
||||
return
|
||||
|
||||
@ -1790,25 +1797,29 @@ class Transactions(commands.Cog):
|
||||
|
||||
# Check legality
|
||||
errors = []
|
||||
roster_errors = []
|
||||
for team in dropadd.teams:
|
||||
data = await dropadd.check_major_league_errors(team)
|
||||
|
||||
if data['wara'] > 38.001:
|
||||
if data['wara'] > 38.001 and not OFFSEASON_FLAG:
|
||||
errors.append(f'- {dropadd.teams[team]["team"]["abbrev"]} would have {data["wara"]:.2f} WARa')
|
||||
|
||||
if len(data['roster']) > 26:
|
||||
if len(data['roster']) > 26 and not OFFSEASON_FLAG:
|
||||
errors.append(f'- {dropadd.teams[team]["team"]["abbrev"]} would have {len(data["roster"])} players')
|
||||
|
||||
if data['wara'] > 38.001 or len(data['roster']) > 26:
|
||||
if (data['wara'] > 38.001 or len(data['roster']) > 26) and not OFFSEASON_FLAG:
|
||||
roster_string = ''
|
||||
for x in data['roster']:
|
||||
roster_string += f'{data["roster"][x]["wara"]: >5} - {data["roster"][x]["name"]}\n'
|
||||
roster_string += f'{x["wara"]: >5} - {x["name"]}\n'
|
||||
errors.append(f'- This is the roster I have for {dropadd.teams[team]["team"]["abbrev"]}:\n'
|
||||
f'```\n{roster_string}```')
|
||||
|
||||
if len(errors) > 0:
|
||||
error_string = "\n".join(errors)
|
||||
await dropadd.send(f'Woof. Gotta say no to this one. Below is why.\n\n{error_string}')
|
||||
if len(errors) + len(roster_errors) > 0:
|
||||
error_message = '\n'.join(errors)
|
||||
await dropadd.send(f'Yikes. I\'m gonna put the kibosh on this move. Below is why:\n\n{error_message}')
|
||||
if len(roster_errors) > 0:
|
||||
for x in roster_errors:
|
||||
await dropadd.send(x)
|
||||
await dropadd.timed_delete()
|
||||
return
|
||||
|
||||
@ -1833,11 +1844,8 @@ class Transactions(commands.Cog):
|
||||
for player_move in [*dropadd.players.values()]:
|
||||
this_guy = copy.deepcopy(player_move['player'])
|
||||
this_guy['team'] = player_move['to']
|
||||
await patch_player(
|
||||
player_move['player']['id'],
|
||||
team_id=player_move['to']['id'],
|
||||
demotion_week=current['week']
|
||||
)
|
||||
this_guy['demotion_week'] = current['week']
|
||||
await patch_player(this_guy)
|
||||
|
||||
await send_to_channel(self.bot, 'transaction-log', embed=await dropadd.show_moves(here=False))
|
||||
|
||||
|
||||
@ -198,6 +198,7 @@ async def patch_player(this_player: dict):
|
||||
|
||||
|
||||
async def patch_draftpick(this_pick: dict):
|
||||
logging.info(f'attempting to patch draftpick:\n{this_pick}')
|
||||
this_pick['player_id'] = None if this_pick['player'] is None else this_pick['player']['id']
|
||||
this_pick['origowner_id'] = None if this_pick['origowner'] is None else this_pick['origowner']['id']
|
||||
this_pick['owner_id'] = None if this_pick['owner'] is None else this_pick['owner']['id']
|
||||
|
||||
12
helpers.py
12
helpers.py
@ -18,7 +18,7 @@ from discord.ext import commands
|
||||
from difflib import get_close_matches
|
||||
|
||||
|
||||
SBA_SEASON = 7
|
||||
SBA_SEASON = 8
|
||||
PD_SEASON = 4
|
||||
SBA_COLOR = 'a6ce39'
|
||||
|
||||
@ -31,6 +31,7 @@ SBA_SEASON4_DRAFT_KEY = '1lztxahGRypykfWGKd2duDGFH0omclLqFLSt-vwqdSu8'
|
||||
SBA_SEASON5_DRAFT_KEY = '1euuKeWqQEUmE9OiF9wihO5LMERWP3Zwg_KsG2w-Kx54'
|
||||
SBA_SEASON6_DRAFT_KEY = '13_xWG1wQy7G4UJvohD8JIUBE-7yuWT9lVta1rkAlHQE'
|
||||
SBA_SEASON7_DRAFT_KEY = '1BgySsUlQf9K21_uOjQOY7O0GrRfF6zt1BBaEFlvBokY'
|
||||
SBA_SEASON8_DRAFT_KEY = '1FG4cAs8OeTdrreRqu8D-APxibjB3RiEzn34KTTBLLDk'
|
||||
SBA_STANDINGS_URL = f'{SBA_BASE_URL}/standings'
|
||||
SBA_SCHEDULE_URL = f'{SBA_BASE_URL}/schedule'
|
||||
SBA_IMAGE_URL = f'{SBA_BASE_URL}/static/images'
|
||||
@ -658,6 +659,9 @@ async def fuzzy_player_search(ctx, channel, bot, name, master_list, author = Non
|
||||
if name.lower() in master_list:
|
||||
return name.lower()
|
||||
|
||||
if author is None:
|
||||
author = ctx.author
|
||||
|
||||
great_matches = get_close_matches(name, master_list, cutoff=0.8)
|
||||
if len(great_matches) == 1:
|
||||
return great_matches[0]
|
||||
@ -933,7 +937,11 @@ async def get_player_embed(player, current, ctx=None, season=None):
|
||||
def get_player_url(player, which="sba"):
|
||||
stub_name = player["name"].replace(" ", "%20")
|
||||
if which == 'bbref':
|
||||
return f'https://www.baseball-reference.com/search/search.fcgi?search={stub_name}'
|
||||
if player['bbref_id'] is not None:
|
||||
br_id = player['bbref_id']
|
||||
return f'https://www.baseball-reference.com/players/{br_id[0]}/{br_id}.shtml'
|
||||
else:
|
||||
return f'https://www.baseball-reference.com/search/search.fcgi?search={stub_name}'
|
||||
else:
|
||||
return f'https://sombaseball.ddns.net/players?name={stub_name}'
|
||||
|
||||
|
||||
@ -16,11 +16,11 @@ logging.basicConfig(
|
||||
|
||||
COGS = [
|
||||
'cogs.owner',
|
||||
'cogs.players',
|
||||
'cogs.transactions',
|
||||
'cogs.admins',
|
||||
'cogs.dice',
|
||||
'cogs.fun',
|
||||
'cogs.players',
|
||||
'cogs.exception-handler'
|
||||
# 'cogs.gameday',
|
||||
# 'cogs.gameplay'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user