From f05e1eb9c2473b34767ee05dbac3d92f976c9397 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Sun, 28 Mar 2021 15:16:31 -0400 Subject: [PATCH] added a ton of flags to the draft; added oblreset --- database.py | 9 +++++++ the_draft.py | 24 +++++++++---------- the_prestige.py | 64 ++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 77 insertions(+), 20 deletions(-) diff --git a/database.py b/database.py index 69afb31..5a63ff8 100644 --- a/database.py +++ b/database.py @@ -457,6 +457,15 @@ def set_obl_rival(base_team, rival): conn.commit() conn.close() +def clear_obl(): + conn = create_connection() + if conn is not None: + c=conn.cursor() + + c.execute("DELETE FROM one_big_league") + conn.commit() + conn.close() + def list_to_newline_string(list): string = "" for element in list: diff --git a/the_draft.py b/the_draft.py index cfb4cbc..15504c9 100644 --- a/the_draft.py +++ b/the_draft.py @@ -5,10 +5,6 @@ import uuid import onomancer -DRAFT_SIZE = 20 -REFRESH_DRAFT_SIZE = 4 # fewer players remaining than this and the list refreshes -DRAFT_ROUNDS = 13 - Participant = namedtuple('Participant', ['handle', 'team']) BOOKMARK = Participant(handle="bookmark", team=None) # keep track of start/end of draft round @@ -20,15 +16,19 @@ class Draft: """ @classmethod - def make_draft(cls): - draft = cls() + def make_draft(cls, teamsize, draftsize, minsize, pitchers): + draft = cls(teamsize, draftsize, minsize, pitchers) return draft - def __init__(self): + def __init__(self, teamsize, draftsize, minsize, pitchers): + self.DRAFT_SIZE = draftsize + self.REFRESH_DRAFT_SIZE = minsize # fewer players remaining than this and the list refreshes + self.DRAFT_ROUNDS = teamsize + self.pitchers = pitchers self._id = str(uuid.uuid4())[:6] self._participants = [] self._active_participant = BOOKMARK # draft mutex - self._players = onomancer.get_names(limit=DRAFT_SIZE) + self._players = onomancer.get_names(limit=self.DRAFT_SIZE) self._round = 0 @property @@ -68,7 +68,7 @@ class Draft: self.advance_draft() def refresh_players(self): - self._players = onomancer.get_names(limit=DRAFT_SIZE) + self._players = onomancer.get_names(limit=self.DRAFT_SIZE) def advance_draft(self): """ @@ -104,12 +104,12 @@ class Draft: raise ValueError(f'Player `{player_name}` not in draft list') del self._players[player['name']] - if len(self._players) <= REFRESH_DRAFT_SIZE: + if len(self._players) <= self.REFRESH_DRAFT_SIZE: self.refresh_players() - if self._round < DRAFT_ROUNDS: + if self._round <= self.DRAFT_ROUNDS - self.pitchers: self._active_participant.team.add_lineup(games.player(json.dumps(player))) - elif self._round == DRAFT_ROUNDS: + else: self._active_participant.team.add_pitcher(games.player(json.dumps(player))) self.advance_draft() diff --git a/the_prestige.py b/the_prestige.py index c7cdfd6..af8c16d 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -2,7 +2,7 @@ import discord, json, math, os, roman, games, asyncio, random, main_controller, import database as db import onomancer as ono from league_storage import league_exists, season_save, season_restart -from the_draft import Draft, DRAFT_ROUNDS +from the_draft import Draft from flask import Flask from uuid import uuid4 import weather @@ -639,7 +639,34 @@ class StartDraftCommand(Command): """ async def execute(self, msg, command, flags): - draft = Draft.make_draft() + teamsize = 13 + draftsize = 20 + minsize = 4 + pitchers = 3 + + for flag in flags: + try: + if flag[0] == "t": + teamsize = int(flag[1]) + elif flag[0] == "d": + draftsize = int(flag[1]) + elif flag[0] == "r": #refreshsize, default 4 + minsize = int(flag[1]) + elif flag[0] == "p": + pitchers = int(flag[1]) + else: + raise CommandError(f"We don't recognize that {flag[0]} flag.") + except ValueError: + raise CommandError(f"Your {flag[0]} flag isn't a valid integer, boss.") + + if teamsize-pitchers > 20 or pitchers > 8: + raise CommandError("You can't fit that many players on a team, chief. Slow your roll.") + if teamsize < 3 or pitchers < 1 or draftsize < 10 or minsize < 2: + raise CommandError("One of those numbers is too low. Draft size has to be at least 10, the rest should be obvious.") + if drafsize > 40: + raise CommandError("40 players is the max. We're not too confident about pushing for more.") + + draft = Draft.make_draft(teamsize, draftsize, minsize, pitchers) mentions = {f'<@!{m.id}>' for m in msg.mentions} content = msg.content.split('\n')[1:] # drop command out of message if not content or len(content) % 3: @@ -668,23 +695,30 @@ class StartDraftCommand(Command): draft.start_draft() footer = f"The draft class of {random.randint(2007, 2075)}" - while draft.round <= DRAFT_ROUNDS: - message_prefix = f'Round {draft.round}/{DRAFT_ROUNDS}:' - if draft.round == DRAFT_ROUNDS: + while draft.round <= draft.DRAFT_ROUNDS: + message_prefix = f'Round {draft.round}/{draft.DRAFT_ROUNDS}:' + if draft.round == draft.DRAFT_ROUNDS: body = random.choice([ f"Now just choose a pitcher and we can finish off this paperwork for you, {draft.active_drafter}", f"Pick a pitcher, {draft.active_drafter}, and we can all go home happy. 'Cept your players. They'll have to play baseball.", f"Almost done, {draft.active_drafter}. Pick your pitcher.", ]) message = f"⚾️ {message_prefix} {body}" - else: + elif draft.round <= draft.DRAFT_ROUNDS - draft.pitchers: body = random.choice([ - f"Choose a batter, {draft.active_drafter}", + f"Choose a batter, {draft.active_drafter}.", f"{draft.active_drafter}, your turn. Pick one.", - f"Pick one to fill your next lineup slot, {draft.active_drafter}", + f"Pick one to fill your next lineup slot, {draft.active_drafter}.", f"Alright, {draft.active_drafter}, choose a batter.", ]) message = f"🏏 {message_prefix} {body}" + else: + body = random.choice([ + f"Warning: Pitcher Zone. Enter if you dare, {draft.active_drafter}.", + f"Time to pitch a picker, {draft.active_drafter}.\nWait, that doesn't sound right.", + f"Choose a yeeter, {draft.active_drafter}.\nDid we use that word right?", + f"Choose a pitcher, {draft.active_drafter}."]) + message = f"⚾️ {message_prefix} {body}" await msg.channel.send( message, embed=build_draft_embed(draft.get_draftees(), footer=footer), @@ -1404,6 +1438,19 @@ class OBLConqueredCommand(Command): except asyncio.TimeoutError: return +class OBLResetCommand(Command): + name = "oblreset" + template = "m;oblreset" + description = "NUKES THE OBL BOARD. BE CAREFUL." + + def isauthorized(self, user): + return user.id in config()["owners"] + + async def execute(self, msg, command, flags): + if self.isauthorized(msg.author): + db.clear_obl() + await msg.channel.send("💣") + class TeamsInfoCommand(Command): name = "teamcount" template = "m;teamcount" @@ -1441,6 +1488,7 @@ commands = [ OBLSetRivalCommand(), OBLConqueredCommand(), OBLLeaderboardCommand(), + OBLResetCommand(), LeagueClaimCommand(), LeagueAddOwnersCommand(), StartLeagueCommand(),