diff --git a/cogs/players.py b/cogs/players.py index 4dfc233..093e254 100644 --- a/cogs/players.py +++ b/cogs/players.py @@ -3,7 +3,7 @@ import math import os import random -import requests +import aiohttp import discord import pygsheets @@ -19,6 +19,7 @@ from sqlmodel import Session import gauntlets import helpers + # import in_game.data_cache # import in_game.simulations # import in_game @@ -28,210 +29,389 @@ from in_game.gameplay_queries import get_team_or_none from in_game.simulations import get_pos_embeds, get_result from in_game.gameplay_models import Lineup, Play, Session, engine from api_calls import db_get, db_post, db_patch, get_team_by_abbrev -from helpers import ACTIVE_EVENT_LITERAL, PD_PLAYERS_ROLE_NAME, IMAGES, PD_SEASON, random_conf_gif, fuzzy_player_search, ALL_MLB_TEAMS, \ - fuzzy_search, get_channel, display_cards, get_card_embeds, get_team_embed, cardset_search, get_blank_team_card, \ - get_team_by_owner, get_rosters, get_roster_sheet, legal_channel, app_legal_channel, random_conf_word, embed_pagination, get_cal_user, \ - team_summary_embed, SelectView, SelectPaperdexCardset, SelectPaperdexTeam, get_context_user +from helpers import ( + ACTIVE_EVENT_LITERAL, + PD_PLAYERS_ROLE_NAME, + IMAGES, + PD_SEASON, + random_conf_gif, + fuzzy_player_search, + ALL_MLB_TEAMS, + fuzzy_search, + get_channel, + display_cards, + get_card_embeds, + get_team_embed, + cardset_search, + get_blank_team_card, + get_team_by_owner, + get_rosters, + get_roster_sheet, + legal_channel, + app_legal_channel, + random_conf_word, + embed_pagination, + get_cal_user, + team_summary_embed, + SelectView, + SelectPaperdexCardset, + SelectPaperdexTeam, + get_context_user, +) from utilities.buttons import ask_with_buttons from utilities.autocomplete import cardset_autocomplete, player_autocomplete - -logger = logging.getLogger('discord_app') +logger = logging.getLogger("discord_app") def get_ai_records(short_games, long_games): all_results = { - 'ARI': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'ATL': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'BAL': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'BOS': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'CHC': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'CHW': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'CIN': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'CLE': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'COL': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'DET': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'HOU': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'KCR': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'LAA': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'LAD': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'MIA': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'MIL': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'MIN': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'NYM': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'NYY': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'OAK': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'PHI': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'PIT': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'SDP': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'SEA': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'SFG': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'STL': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'TBR': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'TEX': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'TOR': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, - 'WSN': { - 'short': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'minor': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, - 'major': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}, 'hof': {'w': 0, 'l': 0, 'rd': 0, 'points': 0}}, + "ARI": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "ATL": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "BAL": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "BOS": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "CHC": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "CHW": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "CIN": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "CLE": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "COL": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "DET": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "HOU": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "KCR": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "LAA": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "LAD": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "MIA": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "MIL": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "MIN": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "NYM": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "NYY": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "OAK": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "PHI": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "PIT": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "SDP": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "SEA": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "SFG": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "STL": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "TBR": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "TEX": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "TOR": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, + "WSN": { + "short": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "minor": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "major": {"w": 0, "l": 0, "rd": 0, "points": 0}, + "hof": {"w": 0, "l": 0, "rd": 0, "points": 0}, + }, } - logger.debug(f'running short games...') + logger.debug(f"running short games...") for line in short_games: - home_win = True if line['home_score'] > line['away_score'] else False + home_win = True if line["home_score"] > line["away_score"] else False - if line['away_team']['is_ai']: - all_results[line['away_team']['abbrev']]['short']['w'] += 1 if home_win else 0 - all_results[line['away_team']['abbrev']]['short']['l'] += 1 if not home_win else 0 - all_results[line['away_team']['abbrev']]['short']['points'] += 2 if home_win else 1 - all_results[line['away_team']['abbrev']]['short']['rd'] += line['home_score'] - line['away_score'] - elif line['home_team']['is_ai']: - all_results[line['home_team']['abbrev']]['short']['w'] += 1 if not home_win else 0 - all_results[line['home_team']['abbrev']]['short']['l'] += 1 if home_win else 0 - all_results[line['home_team']['abbrev']]['short']['points'] += 2 if not home_win else 1 - all_results[line['home_team']['abbrev']]['short']['rd'] += line['away_score'] - line['home_score'] - logger.debug(f'done short games') + if line["away_team"]["is_ai"]: + all_results[line["away_team"]["abbrev"]]["short"]["w"] += ( + 1 if home_win else 0 + ) + all_results[line["away_team"]["abbrev"]]["short"]["l"] += ( + 1 if not home_win else 0 + ) + all_results[line["away_team"]["abbrev"]]["short"]["points"] += ( + 2 if home_win else 1 + ) + all_results[line["away_team"]["abbrev"]]["short"]["rd"] += ( + line["home_score"] - line["away_score"] + ) + elif line["home_team"]["is_ai"]: + all_results[line["home_team"]["abbrev"]]["short"]["w"] += ( + 1 if not home_win else 0 + ) + all_results[line["home_team"]["abbrev"]]["short"]["l"] += ( + 1 if home_win else 0 + ) + all_results[line["home_team"]["abbrev"]]["short"]["points"] += ( + 2 if not home_win else 1 + ) + all_results[line["home_team"]["abbrev"]]["short"]["rd"] += ( + line["away_score"] - line["home_score"] + ) + logger.debug(f"done short games") - logger.debug(f'running league games...') - league = {None: 'minor', 'minor-league': 'minor', 'major-league': 'major', 'hall-of-fame': 'hof'} + logger.debug(f"running league games...") + league = { + None: "minor", + "minor-league": "minor", + "major-league": "major", + "hall-of-fame": "hof", + } for line in long_games: - home_win = True if line['home_score'] > line['away_score'] else False + home_win = True if line["home_score"] > line["away_score"] else False - if line['away_team']['is_ai']: - all_results[line['away_team']['abbrev']][league[line['game_type']]]['w'] += 1 if home_win else 0 - all_results[line['away_team']['abbrev']][league[line['game_type']]]['l'] += 1 if not home_win else 0 - all_results[line['away_team']['abbrev']][league[line['game_type']]]['points'] += 2 if home_win else 1 - all_results[line['away_team']['abbrev']][league[line['game_type']]]['rd'] += \ - line['home_score'] - line['away_score'] - elif line['home_team']['is_ai']: - all_results[line['home_team']['abbrev']][league[line['game_type']]]['w'] += 1 if not home_win else 0 - all_results[line['home_team']['abbrev']][league[line['game_type']]]['l'] += 1 if home_win else 0 - all_results[line['home_team']['abbrev']][league[line['game_type']]]['points'] += 2 if not home_win else 1 - all_results[line['home_team']['abbrev']][league[line['game_type']]]['rd'] += \ - line['away_score'] - line['home_score'] - logger.debug(f'done league games') + if line["away_team"]["is_ai"]: + all_results[line["away_team"]["abbrev"]][league[line["game_type"]]][ + "w" + ] += (1 if home_win else 0) + all_results[line["away_team"]["abbrev"]][league[line["game_type"]]][ + "l" + ] += (1 if not home_win else 0) + all_results[line["away_team"]["abbrev"]][league[line["game_type"]]][ + "points" + ] += (2 if home_win else 1) + all_results[line["away_team"]["abbrev"]][league[line["game_type"]]][ + "rd" + ] += (line["home_score"] - line["away_score"]) + elif line["home_team"]["is_ai"]: + all_results[line["home_team"]["abbrev"]][league[line["game_type"]]][ + "w" + ] += (1 if not home_win else 0) + all_results[line["home_team"]["abbrev"]][league[line["game_type"]]][ + "l" + ] += (1 if home_win else 0) + all_results[line["home_team"]["abbrev"]][league[line["game_type"]]][ + "points" + ] += (2 if not home_win else 1) + all_results[line["home_team"]["abbrev"]][league[line["game_type"]]][ + "rd" + ] += (line["away_score"] - line["home_score"]) + logger.debug(f"done league games") return all_results def get_record_embed_legacy(embed: discord.Embed, results: dict, league: str): - ale_points = results["BAL"][league]["points"] + results["BOS"][league]["points"] + \ - results["NYY"][league]["points"] + results["TBR"][league]["points"] + results["TOR"][league]["points"] - alc_points = results["CLE"][league]["points"] + results["CHW"][league]["points"] + \ - results["DET"][league]["points"] + results["KCR"][league]["points"] + results["MIN"][league]["points"] - alw_points = results["HOU"][league]["points"] + results["LAA"][league]["points"] + \ - results["OAK"][league]["points"] + results["SEA"][league]["points"] + results["TEX"][league]["points"] - nle_points = results["ATL"][league]["points"] + results["MIA"][league]["points"] + \ - results["NYM"][league]["points"] + results["PHI"][league]["points"] + results["WSN"][league]["points"] - nlc_points = results["CHC"][league]["points"] + results["CIN"][league]["points"] + \ - results["MIL"][league]["points"] + results["PIT"][league]["points"] + results["STL"][league]["points"] - nlw_points = results["ARI"][league]["points"] + results["COL"][league]["points"] + \ - results["LAD"][league]["points"] + results["SDP"][league]["points"] + results["SFG"][league]["points"] + ale_points = ( + results["BAL"][league]["points"] + + results["BOS"][league]["points"] + + results["NYY"][league]["points"] + + results["TBR"][league]["points"] + + results["TOR"][league]["points"] + ) + alc_points = ( + results["CLE"][league]["points"] + + results["CHW"][league]["points"] + + results["DET"][league]["points"] + + results["KCR"][league]["points"] + + results["MIN"][league]["points"] + ) + alw_points = ( + results["HOU"][league]["points"] + + results["LAA"][league]["points"] + + results["OAK"][league]["points"] + + results["SEA"][league]["points"] + + results["TEX"][league]["points"] + ) + nle_points = ( + results["ATL"][league]["points"] + + results["MIA"][league]["points"] + + results["NYM"][league]["points"] + + results["PHI"][league]["points"] + + results["WSN"][league]["points"] + ) + nlc_points = ( + results["CHC"][league]["points"] + + results["CIN"][league]["points"] + + results["MIL"][league]["points"] + + results["PIT"][league]["points"] + + results["STL"][league]["points"] + ) + nlw_points = ( + results["ARI"][league]["points"] + + results["COL"][league]["points"] + + results["LAD"][league]["points"] + + results["SDP"][league]["points"] + + results["SFG"][league]["points"] + ) embed.add_field( - name=f'AL East ({ale_points} pts)', + name=f"AL East ({ale_points} pts)", value=f'BAL: {results["BAL"][league]["w"]} - {results["BAL"][league]["l"]} ({results["BAL"][league]["rd"]} RD)\n' - f'BOS: {results["BOS"][league]["w"]} - {results["BOS"][league]["l"]} ({results["BOS"][league]["rd"]} RD)\n' - f'NYY: {results["NYY"][league]["w"]} - {results["NYY"][league]["l"]} ({results["NYY"][league]["rd"]} RD)\n' - f'TBR: {results["TBR"][league]["w"]} - {results["TBR"][league]["l"]} ({results["TBR"][league]["rd"]} RD)\n' - f'TOR: {results["TOR"][league]["w"]} - {results["TOR"][league]["l"]} ({results["TOR"][league]["rd"]} RD)\n' + f'BOS: {results["BOS"][league]["w"]} - {results["BOS"][league]["l"]} ({results["BOS"][league]["rd"]} RD)\n' + f'NYY: {results["NYY"][league]["w"]} - {results["NYY"][league]["l"]} ({results["NYY"][league]["rd"]} RD)\n' + f'TBR: {results["TBR"][league]["w"]} - {results["TBR"][league]["l"]} ({results["TBR"][league]["rd"]} RD)\n' + f'TOR: {results["TOR"][league]["w"]} - {results["TOR"][league]["l"]} ({results["TOR"][league]["rd"]} RD)\n', ) embed.add_field( - name=f'AL Central ({alc_points} pts)', + name=f"AL Central ({alc_points} pts)", value=f'CLE: {results["CLE"][league]["w"]} - {results["CLE"][league]["l"]} ({results["CLE"][league]["rd"]} RD)\n' - f'CHW: {results["CHW"][league]["w"]} - {results["CHW"][league]["l"]} ({results["CHW"][league]["rd"]} RD)\n' - f'DET: {results["DET"][league]["w"]} - {results["DET"][league]["l"]} ({results["DET"][league]["rd"]} RD)\n' - f'KCR: {results["KCR"][league]["w"]} - {results["KCR"][league]["l"]} ({results["KCR"][league]["rd"]} RD)\n' - f'MIN: {results["MIN"][league]["w"]} - {results["MIN"][league]["l"]} ({results["MIN"][league]["rd"]} RD)\n' + f'CHW: {results["CHW"][league]["w"]} - {results["CHW"][league]["l"]} ({results["CHW"][league]["rd"]} RD)\n' + f'DET: {results["DET"][league]["w"]} - {results["DET"][league]["l"]} ({results["DET"][league]["rd"]} RD)\n' + f'KCR: {results["KCR"][league]["w"]} - {results["KCR"][league]["l"]} ({results["KCR"][league]["rd"]} RD)\n' + f'MIN: {results["MIN"][league]["w"]} - {results["MIN"][league]["l"]} ({results["MIN"][league]["rd"]} RD)\n', ) embed.add_field( - name=f'AL West ({alw_points} pts)', + name=f"AL West ({alw_points} pts)", value=f'HOU: {results["HOU"][league]["w"]} - {results["HOU"][league]["l"]} ({results["HOU"][league]["rd"]} RD)\n' - f'LAA: {results["LAA"][league]["w"]} - {results["LAA"][league]["l"]} ({results["LAA"][league]["rd"]} RD)\n' - f'OAK: {results["OAK"][league]["w"]} - {results["OAK"][league]["l"]} ({results["OAK"][league]["rd"]} RD)\n' - f'SEA: {results["SEA"][league]["w"]} - {results["SEA"][league]["l"]} ({results["SEA"][league]["rd"]} RD)\n' - f'TEX: {results["TEX"][league]["w"]} - {results["TEX"][league]["l"]} ({results["TEX"][league]["rd"]} RD)\n' + f'LAA: {results["LAA"][league]["w"]} - {results["LAA"][league]["l"]} ({results["LAA"][league]["rd"]} RD)\n' + f'OAK: {results["OAK"][league]["w"]} - {results["OAK"][league]["l"]} ({results["OAK"][league]["rd"]} RD)\n' + f'SEA: {results["SEA"][league]["w"]} - {results["SEA"][league]["l"]} ({results["SEA"][league]["rd"]} RD)\n' + f'TEX: {results["TEX"][league]["w"]} - {results["TEX"][league]["l"]} ({results["TEX"][league]["rd"]} RD)\n', ) embed.add_field( - name=f'NL East ({nle_points} pts)', + name=f"NL East ({nle_points} pts)", value=f'ATL: {results["ATL"][league]["w"]} - {results["ATL"][league]["l"]} ({results["ATL"][league]["rd"]} RD)\n' - f'MIA: {results["MIA"][league]["w"]} - {results["MIA"][league]["l"]} ({results["MIA"][league]["rd"]} RD)\n' - f'NYM: {results["NYM"][league]["w"]} - {results["NYM"][league]["l"]} ({results["NYM"][league]["rd"]} RD)\n' - f'PHI: {results["PHI"][league]["w"]} - {results["PHI"][league]["l"]} ({results["PHI"][league]["rd"]} RD)\n' - f'WSN: {results["WSN"][league]["w"]} - {results["WSN"][league]["l"]} ({results["WSN"][league]["rd"]} RD)\n' + f'MIA: {results["MIA"][league]["w"]} - {results["MIA"][league]["l"]} ({results["MIA"][league]["rd"]} RD)\n' + f'NYM: {results["NYM"][league]["w"]} - {results["NYM"][league]["l"]} ({results["NYM"][league]["rd"]} RD)\n' + f'PHI: {results["PHI"][league]["w"]} - {results["PHI"][league]["l"]} ({results["PHI"][league]["rd"]} RD)\n' + f'WSN: {results["WSN"][league]["w"]} - {results["WSN"][league]["l"]} ({results["WSN"][league]["rd"]} RD)\n', ) embed.add_field( - name=f'NL Central ({nlc_points} pts)', + name=f"NL Central ({nlc_points} pts)", value=f'CHC: {results["CHC"][league]["w"]} - {results["CHC"][league]["l"]} ({results["CHC"][league]["rd"]} RD)\n' - f'CHW: {results["CIN"][league]["w"]} - {results["CIN"][league]["l"]} ({results["CIN"][league]["rd"]} RD)\n' - f'MIL: {results["MIL"][league]["w"]} - {results["MIL"][league]["l"]} ({results["MIL"][league]["rd"]} RD)\n' - f'PIT: {results["PIT"][league]["w"]} - {results["PIT"][league]["l"]} ({results["PIT"][league]["rd"]} RD)\n' - f'STL: {results["STL"][league]["w"]} - {results["STL"][league]["l"]} ({results["STL"][league]["rd"]} RD)\n' + f'CHW: {results["CIN"][league]["w"]} - {results["CIN"][league]["l"]} ({results["CIN"][league]["rd"]} RD)\n' + f'MIL: {results["MIL"][league]["w"]} - {results["MIL"][league]["l"]} ({results["MIL"][league]["rd"]} RD)\n' + f'PIT: {results["PIT"][league]["w"]} - {results["PIT"][league]["l"]} ({results["PIT"][league]["rd"]} RD)\n' + f'STL: {results["STL"][league]["w"]} - {results["STL"][league]["l"]} ({results["STL"][league]["rd"]} RD)\n', ) embed.add_field( - name=f'NL West ({nlw_points} pts)', + name=f"NL West ({nlw_points} pts)", value=f'ARI: {results["ARI"][league]["w"]} - {results["ARI"][league]["l"]} ({results["ARI"][league]["rd"]} RD)\n' - f'COL: {results["COL"][league]["w"]} - {results["COL"][league]["l"]} ({results["COL"][league]["rd"]} RD)\n' - f'LAD: {results["LAD"][league]["w"]} - {results["LAD"][league]["l"]} ({results["LAD"][league]["rd"]} RD)\n' - f'SDP: {results["SDP"][league]["w"]} - {results["SDP"][league]["l"]} ({results["SDP"][league]["rd"]} RD)\n' - f'SFG: {results["SFG"][league]["w"]} - {results["SFG"][league]["l"]} ({results["SFG"][league]["rd"]} RD)\n' + f'COL: {results["COL"][league]["w"]} - {results["COL"][league]["l"]} ({results["COL"][league]["rd"]} RD)\n' + f'LAD: {results["LAD"][league]["w"]} - {results["LAD"][league]["l"]} ({results["LAD"][league]["rd"]} RD)\n' + f'SDP: {results["SDP"][league]["w"]} - {results["SDP"][league]["l"]} ({results["SDP"][league]["rd"]} RD)\n' + f'SFG: {results["SFG"][league]["w"]} - {results["SFG"][league]["l"]} ({results["SFG"][league]["rd"]} RD)\n', ) return embed @@ -240,52 +420,52 @@ def get_record_embed_legacy(embed: discord.Embed, results: dict, league: str): def get_record_embed(team: dict, results: dict, league: str): embed = get_team_embed(league, team) embed.add_field( - name=f'AL East', + name=f"AL East", value=f'BAL: {results["BAL"][0]} - {results["BAL"][1]} ({results["BAL"][2]} RD)\n' - f'BOS: {results["BOS"][0]} - {results["BOS"][1]} ({results["BOS"][2]} RD)\n' - f'NYY: {results["NYY"][0]} - {results["NYY"][1]} ({results["NYY"][2]} RD)\n' - f'TBR: {results["TBR"][0]} - {results["TBR"][1]} ({results["TBR"][2]} RD)\n' - f'TOR: {results["TOR"][0]} - {results["TOR"][1]} ({results["TOR"][2]} RD)\n' + f'BOS: {results["BOS"][0]} - {results["BOS"][1]} ({results["BOS"][2]} RD)\n' + f'NYY: {results["NYY"][0]} - {results["NYY"][1]} ({results["NYY"][2]} RD)\n' + f'TBR: {results["TBR"][0]} - {results["TBR"][1]} ({results["TBR"][2]} RD)\n' + f'TOR: {results["TOR"][0]} - {results["TOR"][1]} ({results["TOR"][2]} RD)\n', ) embed.add_field( - name=f'AL Central', + name=f"AL Central", value=f'CLE: {results["CLE"][0]} - {results["CLE"][1]} ({results["CLE"][2]} RD)\n' - f'CHW: {results["CHW"][0]} - {results["CHW"][1]} ({results["CHW"][2]} RD)\n' - f'DET: {results["DET"][0]} - {results["DET"][1]} ({results["DET"][2]} RD)\n' - f'KCR: {results["KCR"][0]} - {results["KCR"][1]} ({results["KCR"][2]} RD)\n' - f'MIN: {results["MIN"][0]} - {results["MIN"][1]} ({results["MIN"][2]} RD)\n' + f'CHW: {results["CHW"][0]} - {results["CHW"][1]} ({results["CHW"][2]} RD)\n' + f'DET: {results["DET"][0]} - {results["DET"][1]} ({results["DET"][2]} RD)\n' + f'KCR: {results["KCR"][0]} - {results["KCR"][1]} ({results["KCR"][2]} RD)\n' + f'MIN: {results["MIN"][0]} - {results["MIN"][1]} ({results["MIN"][2]} RD)\n', ) embed.add_field( - name=f'AL West', + name=f"AL West", value=f'HOU: {results["HOU"][0]} - {results["HOU"][1]} ({results["HOU"][2]} RD)\n' - f'LAA: {results["LAA"][0]} - {results["LAA"][1]} ({results["LAA"][2]} RD)\n' - f'OAK: {results["OAK"][0]} - {results["OAK"][1]} ({results["OAK"][2]} RD)\n' - f'SEA: {results["SEA"][0]} - {results["SEA"][1]} ({results["SEA"][2]} RD)\n' - f'TEX: {results["TEX"][0]} - {results["TEX"][1]} ({results["TEX"][2]} RD)\n' + f'LAA: {results["LAA"][0]} - {results["LAA"][1]} ({results["LAA"][2]} RD)\n' + f'OAK: {results["OAK"][0]} - {results["OAK"][1]} ({results["OAK"][2]} RD)\n' + f'SEA: {results["SEA"][0]} - {results["SEA"][1]} ({results["SEA"][2]} RD)\n' + f'TEX: {results["TEX"][0]} - {results["TEX"][1]} ({results["TEX"][2]} RD)\n', ) embed.add_field( - name=f'NL East', + name=f"NL East", value=f'ATL: {results["ATL"][0]} - {results["ATL"][1]} ({results["ATL"][2]} RD)\n' - f'MIA: {results["MIA"][0]} - {results["MIA"][1]} ({results["MIA"][2]} RD)\n' - f'NYM: {results["NYM"][0]} - {results["NYM"][1]} ({results["NYM"][2]} RD)\n' - f'PHI: {results["PHI"][0]} - {results["PHI"][1]} ({results["PHI"][2]} RD)\n' - f'WSN: {results["WSN"][0]} - {results["WSN"][1]} ({results["WSN"][2]} RD)\n' + f'MIA: {results["MIA"][0]} - {results["MIA"][1]} ({results["MIA"][2]} RD)\n' + f'NYM: {results["NYM"][0]} - {results["NYM"][1]} ({results["NYM"][2]} RD)\n' + f'PHI: {results["PHI"][0]} - {results["PHI"][1]} ({results["PHI"][2]} RD)\n' + f'WSN: {results["WSN"][0]} - {results["WSN"][1]} ({results["WSN"][2]} RD)\n', ) embed.add_field( - name=f'NL Central', + name=f"NL Central", value=f'CHC: {results["CHC"][0]} - {results["CHC"][1]} ({results["CHC"][2]} RD)\n' - f'CIN: {results["CIN"][0]} - {results["CIN"][1]} ({results["CIN"][2]} RD)\n' - f'MIL: {results["MIL"][0]} - {results["MIL"][1]} ({results["MIL"][2]} RD)\n' - f'PIT: {results["PIT"][0]} - {results["PIT"][1]} ({results["PIT"][2]} RD)\n' - f'STL: {results["STL"][0]} - {results["STL"][1]} ({results["STL"][2]} RD)\n' + f'CIN: {results["CIN"][0]} - {results["CIN"][1]} ({results["CIN"][2]} RD)\n' + f'MIL: {results["MIL"][0]} - {results["MIL"][1]} ({results["MIL"][2]} RD)\n' + f'PIT: {results["PIT"][0]} - {results["PIT"][1]} ({results["PIT"][2]} RD)\n' + f'STL: {results["STL"][0]} - {results["STL"][1]} ({results["STL"][2]} RD)\n', ) embed.add_field( - name=f'NL West', + name=f"NL West", value=f'ARI: {results["ARI"][0]} - {results["ARI"][1]} ({results["ARI"][2]} RD)\n' - f'COL: {results["COL"][0]} - {results["COL"][1]} ({results["COL"][2]} RD)\n' - f'LAD: {results["LAD"][0]} - {results["LAD"][1]} ({results["LAD"][2]} RD)\n' - f'SDP: {results["SDP"][0]} - {results["SDP"][1]} ({results["SDP"][2]} RD)\n' - f'SFG: {results["SFG"][0]} - {results["SFG"][1]} ({results["SFG"][2]} RD)\n' + f'COL: {results["COL"][0]} - {results["COL"][1]} ({results["COL"][2]} RD)\n' + f'LAD: {results["LAD"][0]} - {results["LAD"][1]} ({results["LAD"][2]} RD)\n' + f'SDP: {results["SDP"][0]} - {results["SDP"][1]} ({results["SDP"][2]} RD)\n' + f'SFG: {results["SFG"][0]} - {results["SFG"][1]} ({results["SFG"][2]} RD)\n', ) return embed @@ -304,15 +484,17 @@ class Players(commands.Cog): @tasks.loop(hours=1) async def weekly_loop(self): - current = await db_get('current') + current = await db_get("current") now = datetime.datetime.now() - logger.debug(f'Datetime: {now} / weekday: {now.weekday()}') + logger.debug(f"Datetime: {now} / weekday: {now.weekday()}") # Begin Freeze # if now.weekday() == 0 and now.hour == 5: # Spring/Summer if now.weekday() == 0 and now.hour == 0: # Fall/Winter - current['week'] += 1 - await db_patch('current', object_id=current['id'], params=[('week', current['week'])]) + current["week"] += 1 + await db_patch( + "current", object_id=current["id"], params=[("week", current["week"])] + ) # End Freeze # elif now.weekday() == 5 and now.hour == 5 and current['freeze']: # Spring/Summer @@ -324,19 +506,28 @@ class Players(commands.Cog): await self.bot.wait_until_ready() async def cog_command_error(self, ctx, error): - await ctx.send(f'{error}') + await ctx.send(f"{error}") @tasks.loop(hours=18) async def build_player_list(self): - all_players = await db_get('players', params=[('flat', True), ('inc_dex', False)], timeout=25) - all_cardsets = await db_get('cardsets', params=[('flat', True)]) + all_players = await db_get( + "players", params=[("flat", True), ("inc_dex", False)], timeout=25 + ) + all_cardsets = await db_get("cardsets", params=[("flat", True)]) - [self.player_list.append(x['p_name'].lower()) for x in all_players['players'] if x['p_name'].lower() - not in self.player_list] - logger.info(f'There are now {len(self.player_list)} player names in the fuzzy search list.') + [ + self.player_list.append(x["p_name"].lower()) + for x in all_players["players"] + if x["p_name"].lower() not in self.player_list + ] + logger.info( + f"There are now {len(self.player_list)} player names in the fuzzy search list." + ) - self.cardset_list = [x['name'].lower() for x in all_cardsets['cardsets']] - logger.info(f'There are now {len(self.cardset_list)} cardsets in the fuzzy search list.') + self.cardset_list = [x["name"].lower() for x in all_cardsets["cardsets"]] + logger.info( + f"There are now {len(self.cardset_list)} cardsets in the fuzzy search list." + ) @build_player_list.before_loop async def before_player_list(self): @@ -413,109 +604,135 @@ class Players(commands.Cog): # db.close() # return return_embeds - @commands.command(name='build_list', help='Mod: Synchronize fuzzy player list') + @commands.command(name="build_list", help="Mod: Synchronize fuzzy player list") async def build_player_command(self, ctx): self.build_player_list.stop() self.build_player_list.start() - await ctx.send(f'Just kicked off the build...') + await ctx.send(f"Just kicked off the build...") await asyncio.sleep(10) - await ctx.send(f'There are now {len(self.player_list)} player names in the fuzzy search list.') + await ctx.send( + f"There are now {len(self.player_list)} player names in the fuzzy search list." + ) - @commands.command(name='player', help='For specific cardset, run /player', aliases=['show', 'card']) + @commands.command( + name="player", + help="For specific cardset, run /player", + aliases=["show", "card"], + ) @commands.has_any_role(PD_PLAYERS_ROLE_NAME) @commands.check(legal_channel) async def player_card_command(self, ctx, *, player_name: str): this_player = fuzzy_search(player_name, self.player_list) if not this_player: - await ctx.send(f'No clue who that is.') + await ctx.send(f"No clue who that is.") return - all_players = await db_get('players', params=[('name', this_player)]) + all_players = await db_get("players", params=[("name", this_player)]) all_cards = [ - {'player': x, 'team': {'lname': 'Paper Dynasty', 'logo': IMAGES['logo'], 'season': PD_SEASON}} - for x in all_players['players'] + { + "player": x, + "team": { + "lname": "Paper Dynasty", + "logo": IMAGES["logo"], + "season": PD_SEASON, + }, + } + for x in all_players["players"] ] - all_cards.sort(key=lambda x: x['player']['rarity']['value'], reverse=True) + all_cards.sort(key=lambda x: x["player"]["rarity"]["value"], reverse=True) all_embeds = [] for x in all_cards: all_embeds.extend(await get_card_embeds(x)) await ctx.send(content=None, embeds=all_embeds) - @app_commands.command(name='player', description='Display one or more of the player\'s cards') + @app_commands.command( + name="player", description="Display one or more of the player's cards" + ) @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) - @app_commands.autocomplete(player_name=player_autocomplete, cardset=cardset_autocomplete) + @app_commands.autocomplete( + player_name=player_autocomplete, cardset=cardset_autocomplete + ) async def player_slash_command( - self, interaction: discord.Interaction, player_name: str, - cardset: str = 'All'): + self, interaction: discord.Interaction, player_name: str, cardset: str = "All" + ): ephemeral = False - if interaction.channel.name in ['paper-dynasty-chat', 'pd-news-ticker']: + if interaction.channel.name in ["paper-dynasty-chat", "pd-news-ticker"]: ephemeral = True await interaction.response.defer(ephemeral=ephemeral) this_player = fuzzy_search(player_name, self.player_list) if not this_player: - await interaction.response.send_message(f'No clue who that is.') + await interaction.response.send_message(f"No clue who that is.") return - if cardset and cardset != 'All': + if cardset and cardset != "All": this_cardset = await cardset_search(cardset, self.cardset_list) if this_cardset: - all_params = [('name', this_player), ('cardset_id', this_cardset['id'])] + all_params = [("name", this_player), ("cardset_id", this_cardset["id"])] else: - await interaction.edit_original_response(content=f'I couldn\'t find {cardset} cardset.') + await interaction.edit_original_response( + content=f"I couldn't find {cardset} cardset." + ) return else: - all_params = [('name', this_player)] + all_params = [("name", this_player)] - all_players = await db_get('players', params=all_params) - if all_players['count'] == 0: - await interaction.edit_original_response(content='No players found') + all_players = await db_get("players", params=all_params) + if all_players["count"] == 0: + await interaction.edit_original_response(content="No players found") return - all_cards = [get_blank_team_card(x) for x in all_players['players']] - all_cards.sort(key=lambda x: x['player']['rarity']['value'], reverse=True) + all_cards = [get_blank_team_card(x) for x in all_players["players"]] + all_cards.sort(key=lambda x: x["player"]["rarity"]["value"], reverse=True) all_embeds = [] for x in all_cards: all_embeds.extend(await get_card_embeds(x, include_stats=True)) - logger.debug(f'embeds: {all_embeds}') + logger.debug(f"embeds: {all_embeds}") if len(all_embeds) > 1: - await interaction.edit_original_response(content=f'# {all_players["players"][0]["p_name"]}') + await interaction.edit_original_response( + content=f'# {all_players["players"][0]["p_name"]}' + ) await embed_pagination( all_embeds, interaction.channel, interaction.user, timeout=20, - start_page=0 + start_page=0, ) else: await interaction.edit_original_response(content=None, embed=all_embeds[0]) - @app_commands.command(name='update-player', description='Update a player\'s card to a specific MLB team') + @app_commands.command( + name="update-player", + description="Update a player's card to a specific MLB team", + ) @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) - async def update_player_team(self, interaction: discord.Interaction, player_id: int): + async def update_player_team( + self, interaction: discord.Interaction, player_id: int + ): owner_team = await get_team_by_owner(interaction.user.id) if not owner_team: await interaction.response.send_message( - 'Thank you for offering to help - if you sign up for a team with /newteam I can let you post updates.', - ephemeral=True + "Thank you for offering to help - if you sign up for a team with /newteam I can let you post updates.", + ephemeral=True, ) return - if interaction.channel.name in ['paper-dynasty-chat', 'pd-news-ticker']: + if interaction.channel.name in ["paper-dynasty-chat", "pd-news-ticker"]: await interaction.response.send_message( - f'Slide on down to #pd-bot-hole to run updates - thanks!', - ephemeral=True + f"Slide on down to #pd-bot-hole to run updates - thanks!", + ephemeral=True, ) await interaction.response.defer() - this_player = await db_get('players', object_id=player_id) + this_player = await db_get("players", object_id=player_id) if not this_player: - await interaction.response.send_message(f'No clue who that is.') + await interaction.response.send_message(f"No clue who that is.") return embed = await get_card_embeds(get_blank_team_card(this_player)) @@ -523,536 +740,660 @@ class Players(commands.Cog): view = helpers.Confirm(responders=[interaction.user]) question = await interaction.channel.send( - content='Is this the player you want to update?', - view=view + content="Is this the player you want to update?", view=view ) await view.wait() if not view.value: - await question.edit(content='Okay, we\'ll leave it be.', view=None) + await question.edit(content="Okay, we'll leave it be.", view=None) return else: await question.delete() - view = SelectView([ - helpers.SelectUpdatePlayerTeam('AL', this_player, owner_team, self.bot), - helpers.SelectUpdatePlayerTeam('NL', this_player, owner_team, self.bot) - ]) + view = SelectView( + [ + helpers.SelectUpdatePlayerTeam("AL", this_player, owner_team, self.bot), + helpers.SelectUpdatePlayerTeam("NL", this_player, owner_team, self.bot), + ] + ) await interaction.channel.send(content=None, view=view) - @app_commands.command(name='record', description='Display team record against AI teams') + @app_commands.command( + name="record", description="Display team record against AI teams" + ) @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) async def record_slash_command( - self, interaction: discord.Interaction, - league: Literal['All', 'Minor League', 'Major League', 'Flashback', 'Hall of Fame'], - team_abbrev: Optional[str] = None): + self, + interaction: discord.Interaction, + league: Literal[ + "All", "Minor League", "Major League", "Flashback", "Hall of Fame" + ], + team_abbrev: Optional[str] = None, + ): ephemeral = False - if interaction.channel.name in ['paper-dynasty-chat', 'pd-news-ticker']: + if interaction.channel.name in ["paper-dynasty-chat", "pd-news-ticker"]: ephemeral = True if team_abbrev: - t_query = await db_get('teams', params=[('abbrev', team_abbrev)]) + t_query = await db_get("teams", params=[("abbrev", team_abbrev)]) else: - t_query = await db_get('teams', params=[('gm_id', interaction.user.id)]) + t_query = await db_get("teams", params=[("gm_id", interaction.user.id)]) - if t_query['count'] == 0: + if t_query["count"] == 0: await interaction.response.send_message( - f'Hmm...I can\'t find the team you looking for.', ephemeral=ephemeral + f"Hmm...I can't find the team you looking for.", ephemeral=ephemeral ) return - team = t_query['teams'][0] - current = await db_get('current') + team = t_query["teams"][0] + current = await db_get("current") await interaction.response.send_message( f'I\'m tallying the {team["lname"]} results now...', ephemeral=ephemeral ) - st_query = await db_get(f'teams/{team["id"]}/season-record', object_id=current["season"]) + st_query = await db_get( + f'teams/{team["id"]}/season-record', object_id=current["season"] + ) - minor_embed = get_record_embed(team, st_query['minor-league'], 'Minor League') - major_embed = get_record_embed(team, st_query['major-league'], 'Major League') - flashback_embed = get_record_embed(team, st_query['flashback'], 'Flashback') - hof_embed = get_record_embed(team, st_query['hall-of-fame'], 'Hall of Fame') + minor_embed = get_record_embed(team, st_query["minor-league"], "Minor League") + major_embed = get_record_embed(team, st_query["major-league"], "Major League") + flashback_embed = get_record_embed(team, st_query["flashback"], "Flashback") + hof_embed = get_record_embed(team, st_query["hall-of-fame"], "Hall of Fame") - if league == 'All': + if league == "All": start_page = 0 - elif league == 'Minor League': + elif league == "Minor League": start_page = 0 - elif league == 'Major League': + elif league == "Major League": start_page = 1 - elif league == 'Flashback': + elif league == "Flashback": start_page = 2 else: start_page = 3 - await interaction.edit_original_response(content=f'Here are the {team["lname"]} campaign records') + await interaction.edit_original_response( + content=f'Here are the {team["lname"]} campaign records' + ) await embed_pagination( [minor_embed, major_embed, flashback_embed, hof_embed], interaction.channel, interaction.user, timeout=20, - start_page=start_page + start_page=start_page, ) - @app_commands.command(name='team', description='Show team overview and rosters') + @app_commands.command(name="team", description="Show team overview and rosters") @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) @app_legal_channel() - async def team_command(self, interaction: discord.Interaction, team_abbrev: Optional[str] = None): + async def team_command( + self, interaction: discord.Interaction, team_abbrev: Optional[str] = None + ): await interaction.response.defer() if team_abbrev: - t_query = await db_get('teams', params=[('abbrev', team_abbrev)]) + t_query = await db_get("teams", params=[("abbrev", team_abbrev)]) else: - t_query = await db_get('teams', params=[('gm_id', interaction.user.id)]) + t_query = await db_get("teams", params=[("gm_id", interaction.user.id)]) - if t_query['count'] == 0: + if t_query["count"] == 0: await interaction.edit_original_response( - content=f'Hmm...I can\'t find the team you looking for.' + content=f"Hmm...I can't find the team you looking for." ) return - team = t_query['teams'][0] + team = t_query["teams"][0] embed = await team_summary_embed(team, interaction) await interaction.edit_original_response(content=None, embed=embed) - group_lookup = app_commands.Group(name='lookup', description='Search for cards or players by ID') + group_lookup = app_commands.Group( + name="lookup", description="Search for cards or players by ID" + ) - @group_lookup.command(name='card-id', description='Look up individual card by ID') + @group_lookup.command(name="card-id", description="Look up individual card by ID") @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) async def card_lookup_command(self, interaction: discord.Interaction, card_id: int): await interaction.response.defer() - c_query = await db_get('cards', object_id=card_id) + c_query = await db_get("cards", object_id=card_id) if c_query: - c_string = f'Card ID {card_id} is a {helpers.player_desc(c_query["player"])}' - if c_query['team'] is not None: + c_string = ( + f'Card ID {card_id} is a {helpers.player_desc(c_query["player"])}' + ) + if c_query["team"] is not None: c_string += f' owned by the {c_query["team"]["sname"]}' if c_query["pack"] is not None: - c_string += f' pulled from a {c_query["pack"]["pack_type"]["name"]} pack.' + c_string += ( + f' pulled from a {c_query["pack"]["pack_type"]["name"]} pack.' + ) else: - c_query['team'] = c_query["pack"]["team"] - c_string += f' used by the {c_query["pack"]["team"]["sname"]} in a gauntlet' + c_query["team"] = c_query["pack"]["team"] + c_string += ( + f' used by the {c_query["pack"]["team"]["sname"]} in a gauntlet' + ) await interaction.edit_original_response( - content=c_string, - embeds=await get_card_embeds(c_query) + content=c_string, embeds=await get_card_embeds(c_query) ) return - await interaction.edit_original_response(content=f'There is no card with ID {card_id}') + await interaction.edit_original_response( + content=f"There is no card with ID {card_id}" + ) - @group_lookup.command(name='player-id', description='Look up an individual player by ID') + @group_lookup.command( + name="player-id", description="Look up an individual player by ID" + ) @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) - async def player_lookup_command(self, interaction: discord.Interaction, player_id: int): + async def player_lookup_command( + self, interaction: discord.Interaction, player_id: int + ): await interaction.response.defer() - p_query = await db_get('players', object_id=player_id) + p_query = await db_get("players", object_id=player_id) if p_query: p_card = get_blank_team_card(p_query) await interaction.edit_original_response( - content=None, - embeds=await get_card_embeds(p_card) + content=None, embeds=await get_card_embeds(p_card) ) return - await interaction.edit_original_response(content=f'There is no player with ID {player_id}.') + await interaction.edit_original_response( + content=f"There is no player with ID {player_id}." + ) - @commands.hybrid_command(name='branding-pd', help='Update your team branding') + @commands.hybrid_command(name="branding-pd", help="Update your team branding") @commands.has_any_role(PD_PLAYERS_ROLE_NAME) @commands.check(legal_channel) async def branding_command( - self, ctx, team_logo_url: str = None, color: str = None, short_name: str = None, full_name: str = None): + self, + ctx, + team_logo_url: str = None, + color: str = None, + short_name: str = None, + full_name: str = None, + ): owner_team = await get_team_by_owner(get_context_user(ctx).id) if not owner_team: - await ctx.send(f'Hmm...I don\'t see a team for you, yet. You can create one with `/newteam`!') + await ctx.send( + f"Hmm...I don't see a team for you, yet. You can create one with `/newteam`!" + ) return params = [] if team_logo_url is not None: - params.append(('logo', team_logo_url)) + params.append(("logo", team_logo_url)) if color is not None: - params.append(('color', color)) + params.append(("color", color)) if short_name is not None: - params.append(('sname', short_name)) + params.append(("sname", short_name)) if full_name is not None: - params.append(('lname', full_name)) + params.append(("lname", full_name)) if not params: - await ctx.send(f'You keep thinking on it - I can\'t make updates if you don\'t provide them.') + await ctx.send( + f"You keep thinking on it - I can't make updates if you don't provide them." + ) return - team = await db_patch('teams', object_id=owner_team['id'], params=params) + team = await db_patch("teams", object_id=owner_team["id"], params=params) embed = await team_summary_embed(team, ctx) await ctx.send(content=None, embed=embed) - @commands.hybrid_command(name='fuck', help='You know') + @commands.hybrid_command(name="fuck", help="You know") @commands.has_any_role(PD_PLAYERS_ROLE_NAME) @commands.check(legal_channel) async def fuck_command(self, ctx, gm: Member): - t_query = await db_get('teams', params=[('gm_id', gm.id)]) - if t_query['count'] == 0: - await ctx.send(f'Who?') + t_query = await db_get("teams", params=[("gm_id", gm.id)]) + if t_query["count"] == 0: + await ctx.send(f"Who?") return await ctx.send(f'{t_query["teams"][0]["sname"]} are a bunch of cuties!') - @commands.hybrid_command(name='random', help='Check out a random card') + @commands.hybrid_command(name="random", help="Check out a random card") @commands.has_any_role(PD_PLAYERS_ROLE_NAME) @commands.check(legal_channel) async def random_card_command(self, ctx: commands.Context): - p_query = await db_get('players/random', params=[('limit', 1)]) - this_player = p_query['players'][0] + p_query = await db_get("players/random", params=[("limit", 1)]) + this_player = p_query["players"][0] this_embed = await get_card_embeds( - {'player': this_player, 'team': {'lname': 'Paper Dynasty', 'logo': IMAGES['logo'], 'season': PD_SEASON}} + { + "player": this_player, + "team": { + "lname": "Paper Dynasty", + "logo": IMAGES["logo"], + "season": PD_SEASON, + }, + } ) await ctx.send(content=None, embeds=this_embed) - group_paperdex = app_commands.Group(name='paperdex', description='Check your collection counts') + group_paperdex = app_commands.Group( + name="paperdex", description="Check your collection counts" + ) - @group_paperdex.command(name='cardset', description='Check your collection of a specific cardset') + @group_paperdex.command( + name="cardset", description="Check your collection of a specific cardset" + ) @commands.has_any_role(PD_PLAYERS_ROLE_NAME) @commands.check(legal_channel) async def paperdex_cardset_slash(self, interaction: discord.Interaction): team = await get_team_by_owner(interaction.user.id) if not team: - await interaction.response.send_message(f'Do you even have a team? I don\'t know you.', ephemeral=True) + await interaction.response.send_message( + f"Do you even have a team? I don't know you.", ephemeral=True + ) return view = SelectView([SelectPaperdexCardset()], timeout=15) await interaction.response.send_message( - content='You have 15 seconds to select a cardset.', + content="You have 15 seconds to select a cardset.", view=view, - ephemeral=True + ephemeral=True, ) await view.wait() await interaction.delete_original_response() - @group_paperdex.command(name='team', description='Check your collection of a specific MLB franchise') + @group_paperdex.command( + name="team", description="Check your collection of a specific MLB franchise" + ) @commands.has_any_role(PD_PLAYERS_ROLE_NAME) @commands.check(legal_channel) async def paperdex_cardset_slash(self, interaction: discord.Interaction): team = await get_team_by_owner(interaction.user.id) if not team: - await interaction.response.send_message(f'Do you even have a team? I don\'t know you.', ephemeral=True) + await interaction.response.send_message( + f"Do you even have a team? I don't know you.", ephemeral=True + ) return - view = SelectView([SelectPaperdexTeam('AL'), SelectPaperdexTeam('NL')], timeout=30) + view = SelectView( + [SelectPaperdexTeam("AL"), SelectPaperdexTeam("NL")], timeout=30 + ) await interaction.response.send_message( - content='You have 30 seconds to select a team.', - view=view, - ephemeral=True + content="You have 30 seconds to select a team.", view=view, ephemeral=True ) await view.wait() await interaction.delete_original_response() - @commands.hybrid_command(name='ai-teams', help='Get list of AI teams and abbreviations') + @commands.hybrid_command( + name="ai-teams", help="Get list of AI teams and abbreviations" + ) @commands.has_any_role(PD_PLAYERS_ROLE_NAME) @commands.check(legal_channel) async def ai_teams_command(self, ctx: commands.Context): - embed = get_team_embed(f'Paper Dynasty AI Teams') - embed.description = 'Teams Available for Solo Play' + embed = get_team_embed(f"Paper Dynasty AI Teams") + embed.description = "Teams Available for Solo Play" embed.add_field( - name='AL East', - value=f'BAL - Baltimore Orioles\nBOS - Boston Red Sox\nNYY - New York Yankees\nTBR - Tampa Bay Rays\nTOR - ' - f'Toronto Blue Jays' + name="AL East", + value=f"BAL - Baltimore Orioles\nBOS - Boston Red Sox\nNYY - New York Yankees\nTBR - Tampa Bay Rays\nTOR - " + f"Toronto Blue Jays", ) embed.add_field( - name='AL Central', - value=f'CLE - Cleveland Guardians\nCHW - Chicago White Sox\nDET - Detroit Tigers\nKCR - Kansas City ' - f'Royals\nMIN - Minnesota Twins' + name="AL Central", + value=f"CLE - Cleveland Guardians\nCHW - Chicago White Sox\nDET - Detroit Tigers\nKCR - Kansas City " + f"Royals\nMIN - Minnesota Twins", ) embed.add_field( - name='NL West', - value=f'HOU - Houston Astros\nLAA - Los Angeles Angels\nOAK - Oakland Athletics\nSEA - Seattle Mariners' - f'\nTEX - Texas Rangers' + name="NL West", + value=f"HOU - Houston Astros\nLAA - Los Angeles Angels\nOAK - Oakland Athletics\nSEA - Seattle Mariners" + f"\nTEX - Texas Rangers", ) embed.add_field( - name='NL East', - value=f'ATL - Atlanta Braves\nMIA - Miami Marlins\nNYM - New York Mets\nPHI - Philadelphia Phillies\n' - f'WSN - Washington Nationals' + name="NL East", + value=f"ATL - Atlanta Braves\nMIA - Miami Marlins\nNYM - New York Mets\nPHI - Philadelphia Phillies\n" + f"WSN - Washington Nationals", ) embed.add_field( - name='NL Central', - value=f'CHC - Chicago Cubs\nCIN - Cincinnati Reds\nMIL - Milwaukee Brewers\nPIT - Pittsburgh Pirates\n' - f'STL - St Louis Cardinals' + name="NL Central", + value=f"CHC - Chicago Cubs\nCIN - Cincinnati Reds\nMIL - Milwaukee Brewers\nPIT - Pittsburgh Pirates\n" + f"STL - St Louis Cardinals", ) embed.add_field( - name='NL West', - value=f'ARI - Arizona Diamondbacks\nCOL - Colorado Rockies\nLAD - Los Angeles Dodgers\nSDP - San Diego ' - f'Padres\nSFG - San Francisco Giants' + name="NL West", + value=f"ARI - Arizona Diamondbacks\nCOL - Colorado Rockies\nLAD - Los Angeles Dodgers\nSDP - San Diego " + f"Padres\nSFG - San Francisco Giants", ) await ctx.send(content=None, embed=embed) - @commands.hybrid_command(name='standings', help='Check weekly or season-long standings') + @commands.hybrid_command( + name="standings", help="Check weekly or season-long standings" + ) @commands.has_any_role(PD_PLAYERS_ROLE_NAME) @commands.check(legal_channel) - async def standings_command(self, ctx: commands.Context, which: Literal['week', 'season']): - current = await db_get('current') - params = [('season', current['season']), ('ranked', True)] + async def standings_command( + self, ctx: commands.Context, which: Literal["week", "season"] + ): + current = await db_get("current") + params = [("season", current["season"]), ("ranked", True)] - if which == 'week': - params.append(('week', current['week'])) + if which == "week": + params.append(("week", current["week"])) - r_query = await db_get('results', params=params) - if not r_query['count']: - await ctx.send(f'There are no Ranked games on record this {"week" if which == "week" else "season"}.') + r_query = await db_get("results", params=params) + if not r_query["count"]: + await ctx.send( + f'There are no Ranked games on record this {"week" if which == "week" else "season"}.' + ) return all_records = {} - for line in r_query['results']: - home_win = True if line['home_score'] > line['away_score'] else False + for line in r_query["results"]: + home_win = True if line["home_score"] > line["away_score"] else False - if line['away_team']['id'] not in all_records: - all_records[line['away_team']['id']] = { - 'wins': 1 if not home_win else 0, - 'losses': 1 if home_win else 0, - 'points': 2 if not home_win else 1 + if line["away_team"]["id"] not in all_records: + all_records[line["away_team"]["id"]] = { + "wins": 1 if not home_win else 0, + "losses": 1 if home_win else 0, + "points": 2 if not home_win else 1, } else: - all_records[line['away_team']['id']]['wins'] += 1 if not home_win else 0 - all_records[line['away_team']['id']]['losses'] += 1 if home_win else 0 - all_records[line['away_team']['id']]['points'] += 2 if not home_win else 1 + all_records[line["away_team"]["id"]]["wins"] += 1 if not home_win else 0 + all_records[line["away_team"]["id"]]["losses"] += 1 if home_win else 0 + all_records[line["away_team"]["id"]]["points"] += ( + 2 if not home_win else 1 + ) - if line['home_team']['id'] not in all_records: - all_records[line['home_team']['id']] = { - 'wins': 1 if home_win else 0, - 'losses': 1 if not home_win else 0, - 'points': 2 if home_win else 1 + if line["home_team"]["id"] not in all_records: + all_records[line["home_team"]["id"]] = { + "wins": 1 if home_win else 0, + "losses": 1 if not home_win else 0, + "points": 2 if home_win else 1, } else: - all_records[line['home_team']['id']]['wins'] += 1 if home_win else 0 - all_records[line['home_team']['id']]['losses'] += 1 if not home_win else 0 - all_records[line['home_team']['id']]['points'] += 2 if home_win else 0 + all_records[line["home_team"]["id"]]["wins"] += 1 if home_win else 0 + all_records[line["home_team"]["id"]]["losses"] += ( + 1 if not home_win else 0 + ) + all_records[line["home_team"]["id"]]["points"] += 2 if home_win else 0 # logger.info(f'all_records:\n\n{all_records}') - sorted_records = sorted(all_records.items(), key=lambda k_v: k_v[1]['points'], reverse=True) + sorted_records = sorted( + all_records.items(), key=lambda k_v: k_v[1]["points"], reverse=True + ) # logger.info(f'sorted_records: {sorted_records}') # await ctx.send(f'sorted: {sorted_records}') embed = get_team_embed( title=f'{"Season" if which == "season" else "Week"} ' - f'{current["season"] if which == "season" else current["week"]} Standings' + f'{current["season"] if which == "season" else current["week"]} Standings' ) - chunk_string = '' + chunk_string = "" for index, record in enumerate(sorted_records): # logger.info(f'index: {index} / record: {record}') - team = await db_get('teams', object_id=record[0]) + team = await db_get("teams", object_id=record[0]) if team: - chunk_string += f'{record[1]["points"]} pt{"s" if record[1]["points"] != 1 else ""} ' \ - f'({record[1]["wins"]}-{record[1]["losses"]}) - {team["sname"]} [{team["ranking"]}]\n' + chunk_string += ( + f'{record[1]["points"]} pt{"s" if record[1]["points"] != 1 else ""} ' + f'({record[1]["wins"]}-{record[1]["losses"]}) - {team["sname"]} [{team["ranking"]}]\n' + ) else: - logger.error(f'Could not find team {record[0]} when running standings.') + logger.error(f"Could not find team {record[0]} when running standings.") if (index + 1) == len(sorted_records): embed.add_field( - name=f'Group {math.ceil((index + 1) / 20)} / ' - f'{math.ceil(len(sorted_records) / 20)}', - value=chunk_string + name=f"Group {math.ceil((index + 1) / 20)} / " + f"{math.ceil(len(sorted_records) / 20)}", + value=chunk_string, ) elif (index + 1) % 20 == 0: embed.add_field( - name=f'Group {math.ceil((index + 1) / 20)} / ' - f'{math.floor(len(sorted_records) / 20)}', - value=chunk_string + name=f"Group {math.ceil((index + 1) / 20)} / " + f"{math.floor(len(sorted_records) / 20)}", + value=chunk_string, ) await ctx.send(content=None, embed=embed) - @commands.hybrid_command(name='pullroster', help='Pull saved rosters from your team Sheet', - aliases=['roster', 'rosters', 'pullrosters']) + @commands.hybrid_command( + name="pullroster", + help="Pull saved rosters from your team Sheet", + aliases=["roster", "rosters", "pullrosters"], + ) @app_commands.describe( - specific_roster_num='Enter 1, 2, or 3 to only pull one roster; leave blank to pull all 3', + specific_roster_num="Enter 1, 2, or 3 to only pull one roster; leave blank to pull all 3", ) @commands.has_any_role(PD_PLAYERS_ROLE_NAME) @commands.check(legal_channel) - async def pull_roster_command(self, ctx: commands.Context, specific_roster_num: Optional[int] = None): + async def pull_roster_command( + self, ctx: commands.Context, specific_roster_num: Optional[int] = None + ): team = await get_team_by_owner(get_context_user(ctx).id) if not team: - await ctx.send(f'Do you even have a team? I don\'t know you.') + await ctx.send(f"Do you even have a team? I don't know you.") return # Pull data from Sheets async with ctx.typing(): roster_data = get_rosters(team, self.bot) - logger.debug(f'roster_data: {roster_data}') + logger.debug(f"roster_data: {roster_data}") # Post roster team/card ids and throw error if db says no for index, roster in enumerate(roster_data): - logger.debug(f'index: {index} / roster: {roster}') + logger.debug(f"index: {index} / roster: {roster}") if (not specific_roster_num or specific_roster_num == index + 1) and roster: this_roster = await db_post( - 'rosters', + "rosters", payload={ - 'team_id': team['id'], 'name': roster['name'], - 'roster_num': roster['roster_num'], 'card_ids': roster['cards'] - } + "team_id": team["id"], + "name": roster["name"], + "roster_num": roster["roster_num"], + "card_ids": roster["cards"], + }, ) await ctx.send(random_conf_gif()) - group_gauntlet = app_commands.Group(name='gauntlets', description='Check your progress or start a new Gauntlet') + group_gauntlet = app_commands.Group( + name="gauntlets", description="Check your progress or start a new Gauntlet" + ) - @group_gauntlet.command(name='status', description='View status of current Gauntlet run') + @group_gauntlet.command( + name="status", description="View status of current Gauntlet run" + ) @app_commands.describe( - team_abbrev='To check the status of a team\'s active run, enter their abbreviation' + team_abbrev="To check the status of a team's active run, enter their abbreviation" ) @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) async def gauntlet_run_command( - self, interaction: discord.Interaction, event_name: ACTIVE_EVENT_LITERAL, # type: ignore - team_abbrev: str = None): + self, + interaction: discord.Interaction, + event_name: ACTIVE_EVENT_LITERAL, # type: ignore + team_abbrev: str = None, + ): await interaction.response.defer() - e_query = await db_get('events', params=[("name", event_name), ("active", True)]) - if e_query['count'] == 0: - await interaction.edit_original_response(content=f'Hmm...looks like that event is inactive.') + e_query = await db_get( + "events", params=[("name", event_name), ("active", True)] + ) + if e_query["count"] == 0: + await interaction.edit_original_response( + content=f"Hmm...looks like that event is inactive." + ) return else: - this_event = e_query['events'][0] + this_event = e_query["events"][0] this_run, this_team = None, None if team_abbrev: - if 'Gauntlet-' not in team_abbrev: - team_abbrev = f'Gauntlet-{team_abbrev}' - t_query = await db_get('teams', params=[('abbrev', team_abbrev)]) - if t_query['count'] != 0: - this_team = t_query['teams'][0] - r_query = await db_get('gauntletruns', params=[ - ('team_id', this_team['id']), ('is_active', True), ('gauntlet_id', this_event['id']) - ]) + if "Gauntlet-" not in team_abbrev: + team_abbrev = f"Gauntlet-{team_abbrev}" + t_query = await db_get("teams", params=[("abbrev", team_abbrev)]) + if t_query["count"] != 0: + this_team = t_query["teams"][0] + r_query = await db_get( + "gauntletruns", + params=[ + ("team_id", this_team["id"]), + ("is_active", True), + ("gauntlet_id", this_event["id"]), + ], + ) - if r_query['count'] != 0: - this_run = r_query['runs'][0] + if r_query["count"] != 0: + this_run = r_query["runs"][0] else: await interaction.channel.send( content=f'I do not see an active run for the {this_team["lname"]}.' ) else: await interaction.channel.send( - content=f'I do not see an active run for {team_abbrev.upper()}.' + content=f"I do not see an active run for {team_abbrev.upper()}." ) await interaction.edit_original_response( content=None, - embed=await gauntlets.get_embed(this_run, this_event, this_team) + embed=await gauntlets.get_embed(this_run, this_event, this_team), ) - @group_gauntlet.command(name='start', description='Start a new Gauntlet run') + @group_gauntlet.command(name="start", description="Start a new Gauntlet run") @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) - async def gauntlet_start_command( - self, interaction: discord.Interaction): - if 'hello' not in interaction.channel.name: + async def gauntlet_start_command(self, interaction: discord.Interaction): + if "hello" not in interaction.channel.name: await interaction.response.send_message( - content='The draft will probably take you about 15 minutes. Why don\'t you head to your private ' - 'channel to run the draft?', - ephemeral=True + content="The draft will probably take you about 15 minutes. Why don't you head to your private " + "channel to run the draft?", + ephemeral=True, ) return - logger.info(f'Starting a gauntlet run for user {interaction.user.name}') + logger.info(f"Starting a gauntlet run for user {interaction.user.name}") await interaction.response.defer() with Session(engine) as session: - main_team = await get_team_or_none(session, gm_id=interaction.user.id, main_team=True) - draft_team = await get_team_or_none(session, gm_id=interaction.user.id, gauntlet_team=True) + main_team = await get_team_or_none( + session, gm_id=interaction.user.id, main_team=True + ) + draft_team = await get_team_or_none( + session, gm_id=interaction.user.id, gauntlet_team=True + ) - e_query = await db_get('events', params=[("active", True)]) - if e_query['count'] == 0: - await interaction.edit_original_response(content='Hmm...I don\'t see any active events.') + e_query = await db_get("events", params=[("active", True)]) + if e_query["count"] == 0: + await interaction.edit_original_response( + content="Hmm...I don't see any active events." + ) return - elif e_query['count'] == 1: - this_event = e_query['events'][0] + elif e_query["count"] == 1: + this_event = e_query["events"][0] else: event_choice = await ask_with_buttons( interaction, - button_options=[x['name'] for x in e_query['events']], - question='Which event would you like to take on?', + button_options=[x["name"] for x in e_query["events"]], + question="Which event would you like to take on?", # edit_original_interaction=True, timeout=3, - delete_question=False + delete_question=False, ) - this_event = [event for event in e_query['events'] if event['name'] == event_choice][0] + this_event = [ + event + for event in e_query["events"] + if event["name"] == event_choice + ][0] # await interaction.channel.send( # content=f'You chose the {event_choice} event!' # ) - logger.info(f'this_event: {this_event}') + logger.info(f"this_event: {this_event}") first_flag = draft_team is None if draft_team is not None: r_query = await db_get( - 'gauntletruns', - params=[('team_id', draft_team.id), ('gauntlet_id', this_event['id']), ('is_active', True)] + "gauntletruns", + params=[ + ("team_id", draft_team.id), + ("gauntlet_id", this_event["id"]), + ("is_active", True), + ], ) - if r_query['count'] != 0: + if r_query["count"] != 0: await interaction.edit_original_response( content=f'Looks like you already have a {r_query["runs"][0]["gauntlet"]["name"]} run active! ' - f'You can check it out with the `/gauntlets status` command.' + f"You can check it out with the `/gauntlets status` command." ) return try: - draft_embed = await gauntlets.run_draft(interaction, main_team, this_event, draft_team) - except ZeroDivisionError as e: + draft_embed = await gauntlets.run_draft( + interaction, main_team, this_event, draft_team + ) + except ZeroDivisionError: + logger.info(f'User declined {this_event["name"]} draft - cancelling') return except Exception as e: - logger.error(f'Failed to run {this_event["name"]} draft for the {main_team.sname}: {e}') + logger.error( + f'Failed to run {this_event["name"]} draft for the {main_team.sname}: {e}' + ) await gauntlets.wipe_team(draft_team, interaction) 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 ' - f'for now. I let {get_cal_user(interaction).mention} know what happened so he better ' - f'fix it quick.' + 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"fix it quick." ) return if first_flag: await interaction.channel.send( - f'Good luck, champ in the making! To start playing, follow these steps:\n\n' - f'1) Make a copy of the Team Sheet Template found in `/help-pd links`\n' - f'2) Run `/newsheet` to link it to your Gauntlet team\n' + f"Good luck, champ in the making! To start playing, follow these steps:\n\n" + f"1) Make a copy of the Team Sheet Template found in `/help-pd links`\n" + f"2) Run `/newsheet` to link it to your Gauntlet team\n" f'3) Go play your first game with `/new-game gauntlet {this_event["name"]}`' ) else: await interaction.channel.send( - f'Good luck, champ in the making! In your team sheet, sync your cards with **Paper Dynasty** -> ' - f'**Data Imports** -> **My Cards** then you can set your lineup here and you\'ll be ready to go!\n\n' - f'{get_roster_sheet(draft_team)}' + f"Good luck, champ in the making! In your team sheet, sync your cards with **Paper Dynasty** -> " + f"**Data Imports** -> **My Cards** then you can set your lineup here and you'll be ready to go!\n\n" + f"{get_roster_sheet(draft_team)}" ) await helpers.send_to_channel( bot=self.bot, - channel_name='pd-news-ticker', + channel_name="pd-news-ticker", content=f'The {main_team.lname} have entered the {this_event["name"]} Gauntlet!', - embed=draft_embed + embed=draft_embed, ) - @group_gauntlet.command(name='reset', description='Wipe your current team so you can re-draft') + @group_gauntlet.command( + name="reset", description="Wipe your current team so you can re-draft" + ) @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) async def gauntlet_reset_command( - self, interaction: discord.Interaction, event_name: ACTIVE_EVENT_LITERAL): # type: ignore + self, interaction: discord.Interaction, event_name: ACTIVE_EVENT_LITERAL + ): # type: ignore await interaction.response.defer() main_team = await get_team_by_owner(interaction.user.id) draft_team = await get_team_by_abbrev(f'Gauntlet-{main_team["abbrev"]}') if draft_team is None: await interaction.edit_original_response( - content='Hmm, I can\'t find a gauntlet team for you. Have you signed up already?') + content="Hmm, I can't find a gauntlet team for you. Have you signed up already?" + ) return - e_query = await db_get('events', params=[("name", event_name), ("active", True)]) - if e_query['count'] == 0: - await interaction.edit_original_response(content='Hmm...looks like that event is inactive.') + e_query = await db_get( + "events", params=[("name", event_name), ("active", True)] + ) + if e_query["count"] == 0: + await interaction.edit_original_response( + content="Hmm...looks like that event is inactive." + ) return else: - this_event = e_query['events'][0] + this_event = e_query["events"][0] - r_query = await db_get('gauntletruns', params=[ - ('team_id', draft_team['id']), ('is_active', True), ('gauntlet_id', this_event['id']) - ]) + r_query = await db_get( + "gauntletruns", + params=[ + ("team_id", draft_team["id"]), + ("is_active", True), + ("gauntlet_id", this_event["id"]), + ], + ) - if r_query['count'] != 0: - this_run = r_query['runs'][0] + if r_query["count"] != 0: + this_run = r_query["runs"][0] else: await interaction.edit_original_response( content=f'I do not see an active run for the {draft_team["lname"]}.' @@ -1060,27 +1401,23 @@ class Players(commands.Cog): return view = helpers.Confirm(responders=[interaction.user], timeout=60) - conf_string = f'Are you sure you want to wipe your active run?' - await interaction.edit_original_response( - content=conf_string, - view=view - ) + conf_string = f"Are you sure you want to wipe your active run?" + await interaction.edit_original_response(content=conf_string, view=view) await view.wait() if view.value: await gauntlets.end_run(this_run, this_event, draft_team, force_end=True) await interaction.edit_original_response( - content=f'Your {event_name} run has been reset. Run `/gauntlets start {event_name}` to redraft!', - view=None + content=f"Your {event_name} run has been reset. Run `/gauntlets start {event_name}` to redraft!", + view=None, ) else: await interaction.edit_original_response( - content=f'~~{conf_string}~~\n\nNo worries, I will leave it active.', - view=None + content=f"~~{conf_string}~~\n\nNo worries, I will leave it active.", + view=None, ) - # @commands.command(name='standings', aliases=['leaders', 'points', 'weekly'], help='Weekly standings') # async def standings_command(self, ctx, *week_or_season): # if not await legal_channel(ctx): @@ -1104,17 +1441,25 @@ class Players(commands.Cog): # for embed in all_embeds: # await ctx.send(content=None, embed=embed) - @commands.command(name='in', help='Get Paper Dynasty Players role') + @commands.command(name="in", help="Get Paper Dynasty Players role") async def give_role(self, ctx, *args): - await ctx.author.add_roles(discord.utils.get(ctx.guild.roles, name='Paper Dynasty Players')) - await ctx.send('I got u, boo. ;)\n\nNow that you\'ve got the PD role, you can run all of the Paper Dynasty ' - 'bot commands. For help, check out `/help-pd`') + await ctx.author.add_roles( + discord.utils.get(ctx.guild.roles, name="Paper Dynasty Players") + ) + await ctx.send( + "I got u, boo. ;)\n\nNow that you've got the PD role, you can run all of the Paper Dynasty " + "bot commands. For help, check out `/help-pd`" + ) - @commands.command(name='out', help='Remove Paper Dynasty Players role') - @commands.has_any_role('Paper Dynasty Players') + @commands.command(name="out", help="Remove Paper Dynasty Players role") + @commands.has_any_role("Paper Dynasty Players") async def take_role(self, ctx, *args): - await ctx.author.remove_roles(discord.utils.get(ctx.guild.roles, name='Paper Dynasty Players')) - await ctx.send('Oh no! I\'m so sad to see you go! What are we going to do without you?') + await ctx.author.remove_roles( + discord.utils.get(ctx.guild.roles, name="Paper Dynasty Players") + ) + await ctx.send( + "Oh no! I'm so sad to see you go! What are we going to do without you?" + ) # @commands.command(name='teams', help='List all teams') # @commands.has_any_role('Paper Dynasty Players') @@ -1617,7 +1962,7 @@ class Players(commands.Cog): # all_embeds[x].add_field(name='Abbrev - Name - GM', value=team_strings[x], inline=False) # await ctx.send(content=None, embed=all_embeds[x]) - @commands.command(name='c', aliases=['chaos', 'choas'], help='c, chaos, or choas') + @commands.command(name="c", aliases=["chaos", "choas"], help="c, chaos, or choas") async def chaos_roll(self, ctx): """ Have the pitcher check for chaos with a runner on base. @@ -1627,35 +1972,41 @@ class Players(commands.Cog): flag = None if d_twenty == 1: - flag = 'wild pitch' + flag = "wild pitch" elif d_twenty == 2: if random.randint(1, 2) == 1: - flag = 'balk' + flag = "balk" else: - flag = 'passed ball' + flag = "passed ball" if not flag: - roll_message = f'Chaos roll for {ctx.author.name}\n```md\nNo Chaos```' + roll_message = f"Chaos roll for {ctx.author.name}\n```md\nNo Chaos```" else: - roll_message = f'Chaos roll for {ctx.author.name}\n```md\nCheck {flag}```\n'\ - f'{flag.title()} roll```md\n# {d_twenty_two}\nDetails: [1d20 ({d_twenty_two})]```' + roll_message = ( + f"Chaos roll for {ctx.author.name}\n```md\nCheck {flag}```\n" + f"{flag.title()} roll```md\n# {d_twenty_two}\nDetails: [1d20 ({d_twenty_two})]```" + ) await ctx.send(roll_message) - @commands.command(name='sba', hidden=True) + @commands.command(name="sba", hidden=True) async def sba_command(self, ctx, *, player_name): async def get_one_player(id_or_name): - req_url = f'http://database/api/v1/players/{id_or_name}' + req_url = f"http://database/api/v1/players/{id_or_name}" - resp = requests.get(req_url, timeout=3) - if resp.status_code == 200: - return resp.json() - else: - logger.warning(resp.text) - raise ValueError(f'DB: {resp.text}') + async with aiohttp.ClientSession() as session: + async with session.get( + req_url, timeout=aiohttp.ClientTimeout(total=3) + ) as resp: + if resp.status == 200: + return await resp.json() + else: + text = await resp.text() + logger.warning(text) + raise ValueError(f"DB: {text}") this_player = await get_one_player(player_name) - logger.debug(f'this_player: {this_player}') + logger.debug(f"this_player: {this_player}") # @app_commands.command(name='matchup', description='Simulate a matchup between a pitcher and batter') # @app_commands.describe( diff --git a/cogs/players_new/gauntlet.py b/cogs/players_new/gauntlet.py index 1889c83..4f42274 100644 --- a/cogs/players_new/gauntlet.py +++ b/cogs/players_new/gauntlet.py @@ -12,65 +12,89 @@ import datetime from sqlmodel import Session from api_calls import db_get, db_post, db_patch, db_delete, get_team_by_abbrev from helpers import ( - ACTIVE_EVENT_LITERAL, PD_PLAYERS_ROLE_NAME, get_team_embed, get_team_by_owner, - legal_channel, Confirm, send_to_channel + ACTIVE_EVENT_LITERAL, + PD_PLAYERS_ROLE_NAME, + get_team_embed, + get_team_by_owner, + legal_channel, + Confirm, + send_to_channel, ) from helpers.utils import get_roster_sheet, get_cal_user from utilities.buttons import ask_with_buttons from in_game.gameplay_models import engine from in_game.gameplay_queries import get_team_or_none -logger = logging.getLogger('discord_app') +logger = logging.getLogger("discord_app") # Try to import gauntlets module, provide fallback if not available try: import gauntlets + GAUNTLETS_AVAILABLE = True except ImportError: - logger.warning("Gauntlets module not available - gauntlet commands will have limited functionality") + logger.warning( + "Gauntlets module not available - gauntlet commands will have limited functionality" + ) GAUNTLETS_AVAILABLE = False gauntlets = None class Gauntlet(commands.Cog): """Gauntlet game mode functionality for Paper Dynasty.""" - + def __init__(self, bot): self.bot = bot - group_gauntlet = app_commands.Group(name='gauntlets', description='Check your progress or start a new Gauntlet') + group_gauntlet = app_commands.Group( + name="gauntlets", description="Check your progress or start a new Gauntlet" + ) - @group_gauntlet.command(name='status', description='View status of current Gauntlet run') + @group_gauntlet.command( + name="status", description="View status of current Gauntlet run" + ) @app_commands.describe( - team_abbrev='To check the status of a team\'s active run, enter their abbreviation' + team_abbrev="To check the status of a team's active run, enter their abbreviation" ) @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) async def gauntlet_run_command( - self, interaction: discord.Interaction, event_name: ACTIVE_EVENT_LITERAL, # type: ignore - team_abbrev: Optional[str] = None): + self, + interaction: discord.Interaction, + event_name: ACTIVE_EVENT_LITERAL, # type: ignore + team_abbrev: Optional[str] = None, + ): """View status of current gauntlet run - corrected to match original business logic.""" await interaction.response.defer() - e_query = await db_get('events', params=[("name", event_name), ("active", True)]) - if not e_query or e_query.get('count', 0) == 0: - await interaction.edit_original_response(content=f'Hmm...looks like that event is inactive.') + e_query = await db_get( + "events", params=[("name", event_name), ("active", True)] + ) + if not e_query or e_query.get("count", 0) == 0: + await interaction.edit_original_response( + content=f"Hmm...looks like that event is inactive." + ) return else: - this_event = e_query['events'][0] + this_event = e_query["events"][0] this_run, this_team = None, None if team_abbrev: - if 'Gauntlet-' not in team_abbrev: - team_abbrev = f'Gauntlet-{team_abbrev}' - t_query = await db_get('teams', params=[('abbrev', team_abbrev)]) - if t_query and t_query.get('count', 0) != 0: - this_team = t_query['teams'][0] - r_query = await db_get('gauntletruns', params=[ - ('team_id', this_team['id']), ('is_active', True), ('gauntlet_id', this_event['id']) - ]) + if "Gauntlet-" not in team_abbrev: + team_abbrev = f"Gauntlet-{team_abbrev}" + t_query = await db_get("teams", params=[("abbrev", team_abbrev)]) + if t_query and t_query.get("count", 0) != 0: + this_team = t_query["teams"][0] + r_query = await db_get( + "gauntletruns", + params=[ + ("team_id", this_team["id"]), + ("is_active", True), + ("gauntlet_id", this_event["id"]), + ], + ) - if r_query and r_query.get('count', 0) != 0: - this_run = r_query['runs'][0] + if r_query and r_query.get("count", 0) != 0: + this_run = r_query["runs"][0] else: await interaction.edit_original_response( content=f'I do not see an active run for the {this_team["lname"]}.' @@ -78,7 +102,7 @@ class Gauntlet(commands.Cog): return else: await interaction.edit_original_response( - content=f'I do not see an active run for {team_abbrev.upper()}.' + content=f"I do not see an active run for {team_abbrev.upper()}." ) return @@ -86,127 +110,160 @@ class Gauntlet(commands.Cog): if GAUNTLETS_AVAILABLE and gauntlets: await interaction.edit_original_response( content=None, - embed=await gauntlets.get_embed(this_run, this_event, this_team) # type: ignore + embed=await gauntlets.get_embed(this_run, this_event, this_team), # type: ignore ) else: await interaction.edit_original_response( - content='Gauntlet status unavailable - gauntlets module not loaded.' + content="Gauntlet status unavailable - gauntlets module not loaded." ) - @group_gauntlet.command(name='start', description='Start a new Gauntlet run') + @group_gauntlet.command(name="start", description="Start a new Gauntlet run") @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) async def gauntlet_start_command(self, interaction: discord.Interaction): """Start a new gauntlet run.""" - + # Channel restriction - must be in a 'hello' channel (private channel) - if interaction.channel and hasattr(interaction.channel, 'name') and 'hello' not in str(interaction.channel.name): + if ( + interaction.channel + and hasattr(interaction.channel, "name") + and "hello" not in str(interaction.channel.name) + ): await interaction.response.send_message( - content='The draft will probably take you about 15 minutes. Why don\'t you head to your private ' - 'channel to run the draft?', - ephemeral=True + content="The draft will probably take you about 15 minutes. Why don't you head to your private " + "channel to run the draft?", + ephemeral=True, ) return - logger.info(f'Starting a gauntlet run for user {interaction.user.name}') + logger.info(f"Starting a gauntlet run for user {interaction.user.name}") await interaction.response.defer() with Session(engine) as session: - main_team = await get_team_or_none(session, gm_id=interaction.user.id, main_team=True) - draft_team = await get_team_or_none(session, gm_id=interaction.user.id, gauntlet_team=True) + main_team = await get_team_or_none( + session, gm_id=interaction.user.id, main_team=True + ) + draft_team = await get_team_or_none( + session, gm_id=interaction.user.id, gauntlet_team=True + ) # Get active events - e_query = await db_get('events', params=[("active", True)]) - if not e_query or e_query.get('count', 0) == 0: - await interaction.edit_original_response(content='Hmm...I don\'t see any active events.') + e_query = await db_get("events", params=[("active", True)]) + if not e_query or e_query.get("count", 0) == 0: + await interaction.edit_original_response( + content="Hmm...I don't see any active events." + ) return - elif e_query.get('count', 0) == 1: - this_event = e_query['events'][0] + elif e_query.get("count", 0) == 1: + this_event = e_query["events"][0] else: event_choice = await ask_with_buttons( interaction, - button_options=[x['name'] for x in e_query['events']], - question='Which event would you like to take on?', + button_options=[x["name"] for x in e_query["events"]], + question="Which event would you like to take on?", timeout=3, - delete_question=False + delete_question=False, ) - this_event = [event for event in e_query['events'] if event['name'] == event_choice][0] - - logger.info(f'this_event: {this_event}') + this_event = [ + event + for event in e_query["events"] + if event["name"] == event_choice + ][0] + + logger.info(f"this_event: {this_event}") first_flag = draft_team is None if draft_team is not None: r_query = await db_get( - 'gauntletruns', - params=[('team_id', draft_team.id), ('gauntlet_id', this_event['id']), ('is_active', True)] + "gauntletruns", + params=[ + ("team_id", draft_team.id), + ("gauntlet_id", this_event["id"]), + ("is_active", True), + ], ) - if r_query and r_query.get('count', 0) != 0: + if r_query and r_query.get("count", 0) != 0: await interaction.edit_original_response( content=f'Looks like you already have a {r_query["runs"][0]["gauntlet"]["name"]} run active! ' - f'You can check it out with the `/gauntlets status` command.' + f"You can check it out with the `/gauntlets status` command." ) return try: - draft_embed = await gauntlets.run_draft(interaction, main_team, this_event, draft_team) # type: ignore - except ZeroDivisionError as e: + draft_embed = await gauntlets.run_draft(interaction, main_team, this_event, draft_team) # type: ignore + except ZeroDivisionError: + logger.info(f'User declined {this_event["name"]} draft - cancelling') return except Exception as e: - logger.error(f'Failed to run {this_event["name"]} draft for the {main_team.sname if main_team else "unknown"}: {e}') - await gauntlets.wipe_team(draft_team, interaction) # type: ignore + logger.error( + f'Failed to run {this_event["name"]} draft for the {main_team.sname if main_team else "unknown"}: {e}' + ) + await gauntlets.wipe_team(draft_team, interaction) # type: ignore await interaction.followup.send( - 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'fix it quick.' + 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"fix it quick." ) return if first_flag: await interaction.followup.send( - f'Good luck, champ in the making! To start playing, follow these steps:\n\n' - f'1) Make a copy of the Team Sheet Template found in `/help-pd links`\n' - f'2) Run `/newsheet` to link it to your Gauntlet team\n' + f"Good luck, champ in the making! To start playing, follow these steps:\n\n" + f"1) Make a copy of the Team Sheet Template found in `/help-pd links`\n" + f"2) Run `/newsheet` to link it to your Gauntlet team\n" f'3) Go play your first game with `/new-game gauntlet {this_event["name"]}`' ) else: await interaction.followup.send( - f'Good luck, champ in the making! In your team sheet, sync your cards with **Paper Dynasty** -> ' - f'**Data Imports** -> **My Cards** then you can set your lineup here and you\'ll be ready to go!\n\n' - f'{get_roster_sheet(draft_team)}' + f"Good luck, champ in the making! In your team sheet, sync your cards with **Paper Dynasty** -> " + f"**Data Imports** -> **My Cards** then you can set your lineup here and you'll be ready to go!\n\n" + f"{get_roster_sheet(draft_team)}" ) await send_to_channel( bot=self.bot, - channel_name='pd-news-ticker', + channel_name="pd-news-ticker", content=f'The {main_team.lname if main_team else "Unknown Team"} have entered the {this_event["name"]} Gauntlet!', - embed=draft_embed + embed=draft_embed, ) - @group_gauntlet.command(name='reset', description='Wipe your current team so you can re-draft') + @group_gauntlet.command( + name="reset", description="Wipe your current team so you can re-draft" + ) @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) - async def gauntlet_reset_command(self, interaction: discord.Interaction, event_name: ACTIVE_EVENT_LITERAL): # type: ignore + async def gauntlet_reset_command(self, interaction: discord.Interaction, event_name: ACTIVE_EVENT_LITERAL): # type: ignore """Reset current gauntlet run.""" await interaction.response.defer() main_team = await get_team_by_owner(interaction.user.id) draft_team = await get_team_by_abbrev(f'Gauntlet-{main_team["abbrev"]}') if draft_team is None: await interaction.edit_original_response( - content='Hmm, I can\'t find a gauntlet team for you. Have you signed up already?') + content="Hmm, I can't find a gauntlet team for you. Have you signed up already?" + ) return - e_query = await db_get('events', params=[("name", event_name), ("active", True)]) - if e_query['count'] == 0: - await interaction.edit_original_response(content='Hmm...looks like that event is inactive.') + e_query = await db_get( + "events", params=[("name", event_name), ("active", True)] + ) + if e_query["count"] == 0: + await interaction.edit_original_response( + content="Hmm...looks like that event is inactive." + ) return else: - this_event = e_query['events'][0] + this_event = e_query["events"][0] - r_query = await db_get('gauntletruns', params=[ - ('team_id', draft_team['id']), ('is_active', True), ('gauntlet_id', this_event['id']) - ]) + r_query = await db_get( + "gauntletruns", + params=[ + ("team_id", draft_team["id"]), + ("is_active", True), + ("gauntlet_id", this_event["id"]), + ], + ) - if r_query and r_query.get('count', 0) != 0: - this_run = r_query['runs'][0] + if r_query and r_query.get("count", 0) != 0: + this_run = r_query["runs"][0] else: await interaction.edit_original_response( content=f'I do not see an active run for the {draft_team["lname"]}.' @@ -214,27 +271,24 @@ class Gauntlet(commands.Cog): return view = Confirm(responders=[interaction.user], timeout=60) - conf_string = f'Are you sure you want to wipe your active run?' - await interaction.edit_original_response( - content=conf_string, - view=view - ) + conf_string = f"Are you sure you want to wipe your active run?" + await interaction.edit_original_response(content=conf_string, view=view) await view.wait() if view.value: - await gauntlets.end_run(this_run, this_event, draft_team, force_end=True) # type: ignore + await gauntlets.end_run(this_run, this_event, draft_team, force_end=True) # type: ignore await interaction.edit_original_response( - content=f'Your {event_name} run has been reset. Run `/gauntlets start` to redraft!', - view=None + content=f"Your {event_name} run has been reset. Run `/gauntlets start` to redraft!", + view=None, ) else: await interaction.edit_original_response( - content=f'~~{conf_string}~~\n\nNo worries, I will leave it active.', - view=None + content=f"~~{conf_string}~~\n\nNo worries, I will leave it active.", + view=None, ) async def setup(bot): """Setup function for the Gauntlet cog.""" - await bot.add_cog(Gauntlet(bot)) \ No newline at end of file + await bot.add_cog(Gauntlet(bot))