Starting games functional
This commit is contained in:
parent
f9e222d2f1
commit
ae18790279
@ -223,6 +223,8 @@ def build_lineup(team_object: dict, game_id: int, league_name: str, vs_hand: str
|
|||||||
set_params = MINOR_CARDSET_PARAMS
|
set_params = MINOR_CARDSET_PARAMS
|
||||||
elif league_name == 'major-league':
|
elif league_name == 'major-league':
|
||||||
set_params = MAJOR_CARDSET_PARAMS
|
set_params = MAJOR_CARDSET_PARAMS
|
||||||
|
elif league_name == 'gauntlet-1':
|
||||||
|
set_params = MINOR_CARDSET_PARAMS
|
||||||
|
|
||||||
# Pull players sorted by current cost
|
# Pull players sorted by current cost
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import discord
|
|||||||
import pygsheets
|
import pygsheets
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
import gauntlets
|
||||||
from helpers import *
|
from helpers import *
|
||||||
from db_calls import *
|
from db_calls import *
|
||||||
from discord import Member
|
from discord import Member
|
||||||
@ -278,10 +279,9 @@ class Admins(commands.Cog):
|
|||||||
# )
|
# )
|
||||||
# await interaction.edit_original_response(content=f'The choice was: {choice}')
|
# await interaction.edit_original_response(content=f'The choice was: {choice}')
|
||||||
|
|
||||||
pass
|
await interaction.response.defer()
|
||||||
# Delete cards
|
draft_team = db_get('teams', params=[('abbrev', f'Gauntlet-NCB')])
|
||||||
# Delete packs
|
await gauntlets.wipe_team(draft_team['teams'][0], interaction)
|
||||||
# Delete team
|
|
||||||
|
|
||||||
# @commands.command(name='refresh')
|
# @commands.command(name='refresh')
|
||||||
# @commands.is_owner()
|
# @commands.is_owner()
|
||||||
|
|||||||
@ -1450,7 +1450,7 @@ class Economy(commands.Cog):
|
|||||||
values=[[f'{team["id"]}'], [f'\'{team_hash(team)}']]
|
values=[[f'{team["id"]}'], [f'\'{team_hash(team)}']]
|
||||||
)
|
)
|
||||||
|
|
||||||
if copy_rosters and team['gsheet'] != 'None':
|
if copy_rosters and team['gsheet'].lower() != 'none':
|
||||||
old_sheet = sheets.open_by_key(team['gsheet'])
|
old_sheet = sheets.open_by_key(team['gsheet'])
|
||||||
r_sheet = old_sheet.worksheet_by_title(f'My Rosters')
|
r_sheet = old_sheet.worksheet_by_title(f'My Rosters')
|
||||||
roster_ids = r_sheet.range('B3:B80')
|
roster_ids = r_sheet.range('B3:B80')
|
||||||
|
|||||||
@ -162,10 +162,10 @@ class Gameplay(commands.Cog):
|
|||||||
outs = ''
|
outs = ''
|
||||||
|
|
||||||
game_string = f'```\n' \
|
game_string = f'```\n' \
|
||||||
f'{away_team["abbrev"]: ^4}{curr_play.away_score: ^3} {second_base}' \
|
f'{away_team["abbrev"].replace("Gauntlet-", ""): ^4}{curr_play.away_score: ^3} {second_base}' \
|
||||||
f'{inning: >10}\n' \
|
f'{inning: >10}\n' \
|
||||||
f'{home_team["abbrev"]: ^4}{curr_play.home_score: ^3} {third_base} {first_base}' \
|
f'{home_team["abbrev"].replace("Gauntlet-", ""): ^4}{curr_play.home_score: ^3} {third_base} ' \
|
||||||
f'{outs: >8}\n```'
|
f'{first_base}{outs: >8}\n```'
|
||||||
|
|
||||||
return game_string
|
return game_string
|
||||||
|
|
||||||
@ -1368,13 +1368,13 @@ class Gameplay(commands.Cog):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f'Failed to run {event_name} draft for the {main_team["sname"]}: {e}')
|
logging.error(f'Failed to run {event_name} draft for the {main_team["sname"]}: {e}')
|
||||||
draft_team = db_get('teams', params=[('abbrev', f'Gauntlet-{main_team["abbrev"]}')])
|
draft_team = db_get('teams', params=[('abbrev', f'Gauntlet-{main_team["abbrev"]}')])
|
||||||
for x in draft_team['teams']:
|
await gauntlets.wipe_team(draft_team, interaction)
|
||||||
db_delete('teams', object_id=x['id'])
|
|
||||||
await interaction.channel.send(
|
await interaction.channel.send(
|
||||||
content=f'Shoot - it looks like we ran into an issue running the draft. I had to clear it all out '
|
content=f'Shoot - it looks like we ran into an issue running the draft. I had to clear it all out '
|
||||||
f'for now. I let {get_cal_user(interaction).mention} know what happened so he better '
|
f'for now. I let {get_cal_user(interaction).mention} know what happened so he better '
|
||||||
f'fix it quick.'
|
f'fix it quick.'
|
||||||
)
|
)
|
||||||
|
return
|
||||||
|
|
||||||
await interaction.channel.send(
|
await interaction.channel.send(
|
||||||
f'Good luck, champ in the making! To start playing, follow these steps:\n\n'
|
f'Good luck, champ in the making! To start playing, follow these steps:\n\n'
|
||||||
@ -1460,7 +1460,7 @@ class Gameplay(commands.Cog):
|
|||||||
else:
|
else:
|
||||||
patch_game(this_game.id, home_roster_num=69, ai_team='home')
|
patch_game(this_game.id, home_roster_num=69, ai_team='home')
|
||||||
|
|
||||||
starter = gauntlets.get_starting_pitcher(opponent, this_game, this_event)
|
starter = gauntlets.get_starting_pitcher(opponent, this_game, this_event, this_run)
|
||||||
all_lineups.append(starter)
|
all_lineups.append(starter)
|
||||||
|
|
||||||
this_card = db_get(f'cards', object_id=starter['card_id'])
|
this_card = db_get(f'cards', object_id=starter['card_id'])
|
||||||
@ -2067,13 +2067,13 @@ class Gameplay(commands.Cog):
|
|||||||
@app_commands.describe(
|
@app_commands.describe(
|
||||||
team_abbrev='The 2- to 4-digit abbreviation for the team being set',
|
team_abbrev='The 2- to 4-digit abbreviation for the team being set',
|
||||||
roster_num='1, 2, or 3: 1 is Primary, 2 is Secondary, 3 is Tertiary; Enter 1 for AI team',
|
roster_num='1, 2, or 3: 1 is Primary, 2 is Secondary, 3 is Tertiary; Enter 1 for AI team',
|
||||||
lineup_num='1 or 2: 1 is top lineup in sheet, 2 is bottom; Enter 1 for AI team',
|
lineup_num='Technically not a number anymore, huh?',
|
||||||
sp_card_id='Light gray number to the left of the pitcher\'s name on your depth chart'
|
sp_card_id='Light gray number to the left of the pitcher\'s name on your depth chart'
|
||||||
)
|
)
|
||||||
@app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME)
|
@app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME)
|
||||||
async def read_lineup_command(
|
async def read_lineup_command(
|
||||||
self, interaction: discord.Interaction, team_abbrev: str, roster_num: Literal[1, 2, 3],
|
self, interaction: discord.Interaction, team_abbrev: str, roster_num: Literal[1, 2, 3],
|
||||||
lineup_num: Literal[1, 2], sp_card_id: int):
|
lineup_num: Literal['v Right', 'v Left'], sp_card_id: int):
|
||||||
this_game = get_one_game(channel_id=interaction.channel_id, active=True)
|
this_game = get_one_game(channel_id=interaction.channel_id, active=True)
|
||||||
if not this_game:
|
if not this_game:
|
||||||
await interaction.response.send_message(f'I dont\'t see an active game in this channel!')
|
await interaction.response.send_message(f'I dont\'t see an active game in this channel!')
|
||||||
@ -2085,9 +2085,12 @@ class Gameplay(commands.Cog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
owner_team = await get_game_team(this_game, interaction.user.id)
|
owner_team = await get_game_team(this_game, interaction.user.id)
|
||||||
lineup_team = await get_game_team(this_game, team_abbrev=team_abbrev)
|
if 'gauntlet' in this_game.game_type:
|
||||||
|
lineup_team = await get_game_team(this_game, team_abbrev=f'Gauntlet-{owner_team["abbrev"]}')
|
||||||
|
else:
|
||||||
|
lineup_team = await get_game_team(this_game, team_abbrev=team_abbrev)
|
||||||
|
|
||||||
if not owner_team['id'] in [this_game.away_team_id, this_game.home_team_id]:
|
if owner_team['gmid'] != lineup_team['gmid']:
|
||||||
await interaction.response.send_message('Bruh. Only GMs of the active teams can set lineups.')
|
await interaction.response.send_message('Bruh. Only GMs of the active teams can set lineups.')
|
||||||
return
|
return
|
||||||
if not lineup_team['id'] in [this_game.away_team_id, this_game.home_team_id]:
|
if not lineup_team['id'] in [this_game.away_team_id, this_game.home_team_id]:
|
||||||
@ -2104,12 +2107,11 @@ class Gameplay(commands.Cog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
await interaction.response.send_message(f'Let\'s put this lineup card together...')
|
await interaction.response.send_message(f'Let\'s put this lineup card together...')
|
||||||
lineup_cells = get_roster_lineups(
|
if lineup_num == 'v Right':
|
||||||
lineup_team,
|
l_num = 1
|
||||||
self.bot,
|
else:
|
||||||
roster_num,
|
l_num = 2
|
||||||
lineup_num if not lineup_team['is_ai'] else 1
|
lineup_cells = get_roster_lineups(lineup_team, self.bot, roster_num, l_num)
|
||||||
)
|
|
||||||
|
|
||||||
all_lineups = []
|
all_lineups = []
|
||||||
all_pos = []
|
all_pos = []
|
||||||
@ -2323,14 +2325,16 @@ class Gameplay(commands.Cog):
|
|||||||
|
|
||||||
this_game = get_one_game(channel_id=interaction.channel.id, active=True)
|
this_game = get_one_game(channel_id=interaction.channel.id, active=True)
|
||||||
if not this_game:
|
if not this_game:
|
||||||
await interaction.response.send_message('I don\'t see a game in this channel.')
|
await interaction.edit_original_response(content='I don\'t see a game in this channel.')
|
||||||
return False, False, False
|
return False, False, False
|
||||||
|
|
||||||
owner_team = await get_game_team(this_game, interaction.user.id)
|
owner_team = await get_game_team(this_game, interaction.user.id)
|
||||||
|
if 'gauntlet' in this_game.game_type:
|
||||||
|
owner_team = await get_game_team(this_game, team_abbrev=f'Gauntlet-{owner_team["abbrev"]}')
|
||||||
if not owner_team['id'] in [this_game.away_team_id, this_game.home_team_id]:
|
if not owner_team['id'] in [this_game.away_team_id, this_game.home_team_id]:
|
||||||
logging.info(f'{interaction.user.display_name} tried to run a command in Game {this_game.id} when they '
|
logging.info(f'{interaction.user.display_name} tried to run a command in Game {this_game.id} when they '
|
||||||
f'aren\'t a GM in the game.')
|
f'aren\'t a GM in the game.')
|
||||||
await interaction.response.send_message('Bruh. Only GMs of the active teams can log plays.')
|
await interaction.edit_original_response(content='Bruh. Only GMs of the active teams can log plays.')
|
||||||
# return this_game, False, False
|
# return this_game, False, False
|
||||||
|
|
||||||
this_play = get_current_play(this_game.id)
|
this_play = get_current_play(this_game.id)
|
||||||
@ -2348,7 +2352,7 @@ class Gameplay(commands.Cog):
|
|||||||
if not this_play.pitcher:
|
if not this_play.pitcher:
|
||||||
logging.info(f'{interaction.user.display_name} tried to run a command in Game {this_game.id} without a '
|
logging.info(f'{interaction.user.display_name} tried to run a command in Game {this_game.id} without a '
|
||||||
f'pitcher in the lineup.')
|
f'pitcher in the lineup.')
|
||||||
await interaction.response.send_message(f'Please sub in a pitcher before logging a new play.')
|
await interaction.edit_original_response(content=f'Please sub in a pitcher before logging a new play.')
|
||||||
this_play = None
|
this_play = None
|
||||||
|
|
||||||
return this_game, owner_team, this_play
|
return this_game, owner_team, this_play
|
||||||
|
|||||||
62
gauntlets.py
62
gauntlets.py
@ -8,8 +8,34 @@ from peewee import DatabaseError
|
|||||||
|
|
||||||
import ai_manager
|
import ai_manager
|
||||||
import helpers
|
import helpers
|
||||||
from helpers import RARITY
|
from helpers import RARITY, get_cal_user
|
||||||
from db_calls import db_get, db_post
|
from db_calls import db_get, db_post, db_delete
|
||||||
|
|
||||||
|
|
||||||
|
async def wipe_team(this_team, interaction: discord.Interaction):
|
||||||
|
await interaction.edit_original_response(content=f'Looking for cards...')
|
||||||
|
# Delete cards
|
||||||
|
c_query = db_get('cards', params=[('team_id', this_team['id'])])
|
||||||
|
await interaction.edit_original_response(content=f'Found {c_query["count"]} cards; deleting cards...')
|
||||||
|
for x in c_query['cards']:
|
||||||
|
db_delete('cards', object_id=x['id'])
|
||||||
|
|
||||||
|
# Delete packs
|
||||||
|
await interaction.edit_original_response(content=f'Done deleting cards; searching for packs...')
|
||||||
|
p_query = db_get('packs', params=[('team_id', this_team['id'])])
|
||||||
|
await interaction.edit_original_response(content=f'Found {p_query["count"]} packs; deleting packs...')
|
||||||
|
for x in p_query['packs']:
|
||||||
|
db_delete('packs', object_id=x['id'])
|
||||||
|
|
||||||
|
# Delete team
|
||||||
|
await interaction.edit_original_response(content=f'Done deleting packs; now deleting team...')
|
||||||
|
db_delete('teams', object_id=this_team['id'])
|
||||||
|
await interaction.edit_original_response(content=f'Team is deleted; now finding the run...')
|
||||||
|
|
||||||
|
r_query = db_get('gauntletruns', params=[('team_id', this_team['id']), ('is_active', True)])
|
||||||
|
await interaction.edit_original_response(content=f'Found {r_query["count"]} runs; deleting now...')
|
||||||
|
for x in r_query['runs']:
|
||||||
|
db_delete('gauntletruns', object_id=x['id'])
|
||||||
|
|
||||||
|
|
||||||
def get_game_code(this_team, this_event, this_run):
|
def get_game_code(this_team, this_event, this_run):
|
||||||
@ -29,10 +55,31 @@ def is_home_team(this_team, this_event, this_run):
|
|||||||
def get_opponent(this_team, this_event, this_run):
|
def get_opponent(this_team, this_event, this_run):
|
||||||
if this_event['id'] == 1:
|
if this_event['id'] == 1:
|
||||||
gp = games_played(this_run)
|
gp = games_played(this_run)
|
||||||
if gp == 1:
|
if gp == 0:
|
||||||
return db_get('teams', object_id=3, none_okay=False)
|
t_id = 20
|
||||||
|
elif gp == 1:
|
||||||
|
t_id = 9
|
||||||
|
elif gp == 2:
|
||||||
|
t_id = 5
|
||||||
|
elif gp == 3:
|
||||||
|
t_id = 17
|
||||||
|
elif gp == 4:
|
||||||
|
t_id = 3
|
||||||
|
elif gp == 5:
|
||||||
|
t_id = 21
|
||||||
|
elif gp == 6:
|
||||||
|
t_id = 24
|
||||||
|
elif gp == 7:
|
||||||
|
t_id = 23
|
||||||
|
elif gp == 8:
|
||||||
|
t_id = 18
|
||||||
|
elif gp == 9:
|
||||||
|
t_id = 11
|
||||||
|
elif gp == 10:
|
||||||
|
t_id = 14
|
||||||
else:
|
else:
|
||||||
return db_get('teams', object_id=19, none_okay=False)
|
raise KeyError(f'Huh...I have no idea who you should be playing right now.')
|
||||||
|
return db_get('teams', object_id=t_id, none_okay=False)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -44,7 +91,7 @@ def build_lineup(this_team, this_game, this_event):
|
|||||||
raise KeyError(f'Lineups not found for Gauntlet {this_event["id"]}')
|
raise KeyError(f'Lineups not found for Gauntlet {this_event["id"]}')
|
||||||
|
|
||||||
|
|
||||||
def get_starting_pitcher(this_team, this_game, this_event):
|
def get_starting_pitcher(this_team, this_game, this_event, this_run):
|
||||||
if this_event['id'] == 1:
|
if this_event['id'] == 1:
|
||||||
set_params = ai_manager.MINOR_CARDSET_PARAMS
|
set_params = ai_manager.MINOR_CARDSET_PARAMS
|
||||||
params = [
|
params = [
|
||||||
@ -68,7 +115,8 @@ def get_starting_pitcher(this_team, this_game, this_event):
|
|||||||
|
|
||||||
if pitchers['count'] == 0:
|
if pitchers['count'] == 0:
|
||||||
raise DatabaseError(f'Could not find any SP for {this_team["abbrev"]}. Seems like a Cal issue.')
|
raise DatabaseError(f'Could not find any SP for {this_team["abbrev"]}. Seems like a Cal issue.')
|
||||||
card_id = ai_manager.get_or_create_card(pitchers['players'][0], this_team)
|
pitcher_num = games_played(this_run) % 5
|
||||||
|
card_id = ai_manager.get_or_create_card(pitchers['players'][pitcher_num], this_team)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'game_id': this_game.id,
|
'game_id': this_game.id,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user