Just begun new-game command
This commit is contained in:
parent
033b028b85
commit
9dda254421
@ -0,0 +1,62 @@
|
||||
import logging
|
||||
from typing import Literal
|
||||
|
||||
import discord
|
||||
from discord import app_commands
|
||||
from discord.ext import commands
|
||||
|
||||
from helpers import PD_PLAYERS_ROLE_NAME
|
||||
from in_game.game_helpers import PUBLIC_FIELDS_CATEGORY_NAME
|
||||
from in_game.gameplay_db import Session, engine, select, Game
|
||||
|
||||
|
||||
def get_games_by_channel(session: Session, channel_id: int):
|
||||
return session.exec(select(Game).where(Game.channel_id == channel_id)).all()
|
||||
|
||||
|
||||
class Gameplay(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
async def cog_command_error(self, ctx, error):
|
||||
await ctx.send(f'{error}\n\nRun !help <command_name> to see the command requirements')
|
||||
|
||||
async def slash_error(self, ctx, error):
|
||||
await ctx.send(f'{error[:1600]}')
|
||||
|
||||
group_new_game = app_commands.Group(name='new-game', description='Start a new baseball game')
|
||||
|
||||
@group_new_game.command(name='mlb-campaign', description='Start a new MLB campaign game against an AI')
|
||||
@app_commands.rename(
|
||||
league='Campaign',
|
||||
away_team_abbrev='Away Team Abbrev',
|
||||
home_team_abbrev='Home Team Abbrev',
|
||||
sp_card_id='SP Card ID',
|
||||
num_innings='Number of Innings'
|
||||
)
|
||||
@app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME)
|
||||
async def new_game_mlb_campaign_command(
|
||||
self, interaction: discord.Interaction,
|
||||
league: Literal['Minor League', 'Flashback', 'Major League', 'Hall of Fame'],
|
||||
away_team_abbrev: str, home_team_abbrev: str, sp_card_id: int, num_innings: Literal[9, 3] = 9
|
||||
):
|
||||
await interaction.response.defer()
|
||||
|
||||
with Session(engine) as session:
|
||||
conflict = get_games_by_channel(session, channel_id=interaction.channel_id)
|
||||
if len(conflict) > 0:
|
||||
await interaction.edit_original_response(
|
||||
content=f'Ope. There is already a game going on in this channel. Please wait for it to complete '
|
||||
f'before starting a new one.'
|
||||
)
|
||||
|
||||
if interaction.channel.category is None or interaction.channel.category.name != PUBLIC_FIELDS_CATEGORY_NAME:
|
||||
await interaction.response.send_message(
|
||||
f'Why don\'t you head down to one of the Public Fields that way other humans can help if anything '
|
||||
f'pops up?'
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(Gameplay(bot))
|
||||
@ -4,13 +4,15 @@ import random
|
||||
|
||||
import discord
|
||||
|
||||
from db_calls_gameplay import StratGame, StratPlay, StratLineup, StratManagerAi, patch_play, advance_runners, \
|
||||
complete_play, get_team_lineups, get_or_create_bullpen, get_player, get_sheets, make_sub, get_one_lineup, \
|
||||
advance_one_runner, get_one_lineup, ai_batting, get_manager
|
||||
from db_calls import db_get, db_post
|
||||
# from db_calls_gameplay import StratGame, StratPlay, StratLineup, StratManagerAi, patch_play, advance_runners, \
|
||||
# complete_play, get_team_lineups, get_or_create_bullpen, get_player, get_sheets, make_sub, get_one_lineup, \
|
||||
# advance_one_runner, get_one_lineup, ai_batting, get_manager
|
||||
# from db_calls import db_get, db_post
|
||||
from helpers import Pagination, get_team_embed, image_embed, Confirm
|
||||
from typing import Literal, Optional
|
||||
|
||||
PUBLIC_FIELDS_CATEGORY_NAME = 'Public Fields'
|
||||
|
||||
|
||||
def single_onestar(this_play: StratPlay, comp_play: bool = True):
|
||||
patch_play(this_play.id, locked=True)
|
||||
|
||||
@ -129,6 +129,9 @@ def select_speed_testing():
|
||||
print(f'Query Shortstops: time: {query_time.microseconds} ms / {query_ss}')
|
||||
print(f'Game: {game_1}')
|
||||
|
||||
games = session.exec(select(Game).where(Game.active == True)).all()
|
||||
print(f'len(games): {len(games)}')
|
||||
|
||||
|
||||
def main():
|
||||
# create_db_and_tables()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user