S10 Draft Updates
This commit is contained in:
parent
24ee04d7a1
commit
abeb2ecb0f
178
cogs/draft.py
178
cogs/draft.py
@ -1,3 +1,4 @@
|
||||
import copy
|
||||
import math
|
||||
import re
|
||||
|
||||
@ -12,7 +13,7 @@ class Draft(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.warnings = 0
|
||||
self.pick_lock = False
|
||||
self.pick_lock = True
|
||||
# self.sheets = pygsheets.authorize(service_file='storage/major-domo-service-creds.json')
|
||||
|
||||
self.draft_loop.start()
|
||||
@ -335,10 +336,12 @@ class Draft(commands.Cog):
|
||||
player['wara']
|
||||
]]
|
||||
|
||||
logging.info(f'sending pick to sheets')
|
||||
sheets.open_by_key(SBA_SEASON9_DRAFT_KEY).worksheet_by_title('Ordered List').update_values(
|
||||
crange=f'D{draft_pick["overall"] + 1}',
|
||||
values=this_pick
|
||||
)
|
||||
logging.info(f'pick has been sent to sheets')
|
||||
|
||||
async def draft_player(self, current, draft_data, draft_pick, player):
|
||||
# Is this player available to be drafted?
|
||||
@ -655,7 +658,6 @@ class Draft(commands.Cog):
|
||||
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')
|
||||
@app_commands.describe(
|
||||
result_channel='Text Channel: where Major Domo posts draft results',
|
||||
ping_channel='Text Channel: where Major Domo pings for draft picks',
|
||||
@ -669,6 +671,10 @@ class Draft(commands.Cog):
|
||||
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, pick_lock: bool = None):
|
||||
if interaction.user.id != 258104532423147520:
|
||||
await interaction.send_message(random_gif('you\'re not my dad'))
|
||||
return
|
||||
|
||||
await interaction.response.defer()
|
||||
current = await db_get('current')
|
||||
draft_data = await db_get('draftdata')
|
||||
@ -1141,72 +1147,108 @@ class Draft(commands.Cog):
|
||||
#
|
||||
# await ctx.send(return_string)
|
||||
#
|
||||
# @commands.command(name='keepers', help='Set keepers', hidden=True)
|
||||
# @commands.is_owner()
|
||||
# async def keepers_command(self, ctx, team_abbrev, *, player_names):
|
||||
# current = await db_get('current')
|
||||
# player_list = []
|
||||
#
|
||||
# this_team = await get_one_team(team_abbrev)
|
||||
# player_names = re.split(',', player_names)
|
||||
# keepers = []
|
||||
# keeper_count = 1
|
||||
#
|
||||
# for x in player_names:
|
||||
# player_cog = self.bot.get_cog('Players')
|
||||
# player_name = await fuzzy_player_search(ctx, ctx.channel, self.bot, x, player_cog.player_list.keys())
|
||||
# player = await get_one_player(player_name)
|
||||
# keepers.append(player["name"])
|
||||
#
|
||||
# all_players = []
|
||||
#
|
||||
# active_roster = await get_players(season=current['season'], team_abbrev=team_abbrev)
|
||||
# il_players = await get_players(season=current['season'], team_abbrev=f'{team_abbrev}IL')
|
||||
# mil_players = await get_players(season=current['season'], team_abbrev=f'{team_abbrev}MiL')
|
||||
#
|
||||
# for guy in active_roster.values():
|
||||
# all_players.append(guy)
|
||||
# for guy in il_players.values():
|
||||
# all_players.append(guy)
|
||||
# for guy in mil_players.values():
|
||||
# all_players.append(guy)
|
||||
#
|
||||
# all_picks = await get_draftpicks(season=current['season'], owner_team=this_team, round_end=7)
|
||||
# # logging.info(f'\n{all_picks}\n')
|
||||
# # sorted_picks = sorted(all_picks.items(), key=lambda item: item[1]["overall"])
|
||||
# sorted_picks = []
|
||||
# for p in all_picks:
|
||||
# sorted_picks.append(all_picks[p])
|
||||
# # logging.info(f'{sorted_picks}')
|
||||
#
|
||||
# for x in all_players:
|
||||
# logging.info(f'Checking {x["name"]} for keeper status')
|
||||
# if x["name"] in keepers:
|
||||
# logging.info(f'{x["name"]} is a keeper')
|
||||
# draft_pick = sorted_picks[keeper_count - 1]
|
||||
# logging.info(f'Setting {x["name"]} as {this_team["abbrev"]}\'s #{keeper_count} keeper with overall '
|
||||
# f'pick #{draft_pick["overall"]}')
|
||||
#
|
||||
# await patch_draftpick(draft_pick['id'], player_id=x['id'])
|
||||
# await patch_player(x['id'], team_id=this_team['id'], demotion_week=2)
|
||||
# await post_transactions([{
|
||||
# 'week': -1,
|
||||
# 'player_id': x['id'],
|
||||
# 'oldteam_id': 201, # FA team ID
|
||||
# 'newteam_id': this_team['id'],
|
||||
# 'season': current['season'],
|
||||
# 'moveid': f'keeper-{this_team["abbrev"]}-{keeper_count}'
|
||||
# }])
|
||||
# pick_num = draft_pick['overall'] % 16
|
||||
# if pick_num == 0:
|
||||
# pick_num = 16
|
||||
# try:
|
||||
# await self.send_pick_to_sheets(draft_pick, x, pick_num)
|
||||
# except Exception as e:
|
||||
# logging.error(f'{e}')
|
||||
# keeper_count += 1
|
||||
# else:
|
||||
# await patch_player(x['id'], team_id=201)
|
||||
@commands.command(name='keepers', help='Set keepers', hidden=True)
|
||||
@commands.is_owner()
|
||||
async def keepers_command(self, ctx, team_abbrev, *, player_names):
|
||||
current = await db_get('current')
|
||||
player_list = []
|
||||
|
||||
this_team = await get_team_by_abbrev(team_abbrev, current['season'])
|
||||
player_names = re.split(',', player_names)
|
||||
keepers = []
|
||||
keeper_count = 1
|
||||
|
||||
for x in player_names:
|
||||
player_cog = self.bot.get_cog('Players')
|
||||
player_name = await fuzzy_player_search(ctx, ctx.channel, self.bot, x, player_cog.player_list.keys())
|
||||
player = await get_player_by_name(current['season'], player_name)
|
||||
keepers.append(player["name"])
|
||||
|
||||
all_players = []
|
||||
|
||||
# active_roster = await get_players(season=current['season'], team_abbrev=team_abbrev)
|
||||
# il_players = await get_players(season=current['season'], team_abbrev=f'{team_abbrev}IL')
|
||||
# mil_players = await get_players(season=current['season'], team_abbrev=f'{team_abbrev}MiL')
|
||||
active_roster = await db_get('players', params=[('season', current['season']), ('team_id', this_team['id'])])
|
||||
il_players = await db_get('players', params=[('season', current['season']), ('team_id', this_team['id'] + 1)])
|
||||
mil_players = await db_get('players', params=[('season', current['season']), ('team_id', this_team['id'] + 2)])
|
||||
|
||||
for guy in active_roster['players']:
|
||||
all_players.append(guy)
|
||||
for guy in il_players['players']:
|
||||
all_players.append(guy)
|
||||
for guy in mil_players['players']:
|
||||
all_players.append(guy)
|
||||
|
||||
# all_picks = await get_draftpicks(season=current['season'], owner_team=this_team, round_end=7)
|
||||
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')]
|
||||
)
|
||||
# logging.info(f'\n{all_picks}\n')
|
||||
# sorted_picks = sorted(all_picks.items(), key=lambda item: item[1]["overall"])
|
||||
sorted_picks = p_query['picks']
|
||||
# for p in all_picks:
|
||||
# sorted_picks.append(all_picks[p])
|
||||
# logging.info(f'{sorted_picks}')
|
||||
all_moves = []
|
||||
all_keepers = []
|
||||
|
||||
for x in all_players:
|
||||
logging.info(f'Checking {x["name"]} for keeper status')
|
||||
this_player = copy.deepcopy(x)
|
||||
|
||||
if x["name"] in keepers:
|
||||
logging.info(f'{x["name"]} is a keeper')
|
||||
|
||||
draft_pick = sorted_picks[keeper_count - 1]
|
||||
this_player['demotion_week'] = 2
|
||||
draft_pick['player'] = this_player
|
||||
|
||||
logging.info(f'Setting {x["name"]} as {this_team["abbrev"]}\'s #{keeper_count} keeper with overall '
|
||||
f'pick #{draft_pick["overall"]}')
|
||||
|
||||
await patch_draftpick(draft_pick)
|
||||
await patch_player(this_player)
|
||||
# await post_transactions([{
|
||||
# 'week': -1,
|
||||
# 'player_id': x['id'],
|
||||
# 'oldteam_id': 201, # FA team ID
|
||||
# 'newteam_id': this_team['id'],
|
||||
# 'season': current['season'],
|
||||
# 'moveid': f'keeper-{this_team["abbrev"]}-{keeper_count}'
|
||||
# }])
|
||||
|
||||
all_moves.append({
|
||||
'week': -1,
|
||||
'player_id': x['id'],
|
||||
'oldteam_id': 400, # FA team ID
|
||||
'newteam_id': this_team['id'],
|
||||
'season': current['season'],
|
||||
'moveid': f'keeper-{this_team["abbrev"]}-{keeper_count}'
|
||||
})
|
||||
all_keepers.append({
|
||||
'season': current['season'],
|
||||
'team_id': this_team['id'],
|
||||
'player_id': this_player['id']
|
||||
})
|
||||
|
||||
pick_num = draft_pick['overall'] % 16
|
||||
if pick_num == 0:
|
||||
pick_num = 16
|
||||
try:
|
||||
await self.send_pick_to_sheets(draft_pick, this_player)
|
||||
except Exception as e:
|
||||
logging.error(f'{e}')
|
||||
keeper_count += 1
|
||||
else:
|
||||
this_player['team'] = {'id': 400}
|
||||
await patch_player(this_player)
|
||||
|
||||
await db_post('transactions', payload={'count': len(all_moves), 'moves': all_moves})
|
||||
await db_post('keepers', payload={'count': len(all_keepers), 'keepers': all_keepers})
|
||||
await ctx.send(f'Posted {len(all_moves)} transactions with {len(all_keepers)} keepers for {this_team["lname"]}')
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user