added a ton of flags to the draft; added oblreset

This commit is contained in:
Sakimori 2021-03-28 15:16:31 -04:00
parent e7f1c83f9d
commit f05e1eb9c2
3 changed files with 77 additions and 20 deletions

View file

@ -457,6 +457,15 @@ def set_obl_rival(base_team, rival):
conn.commit() conn.commit()
conn.close() 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): def list_to_newline_string(list):
string = "" string = ""
for element in list: for element in list:

View file

@ -5,10 +5,6 @@ import uuid
import onomancer 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']) Participant = namedtuple('Participant', ['handle', 'team'])
BOOKMARK = Participant(handle="bookmark", team=None) # keep track of start/end of draft round BOOKMARK = Participant(handle="bookmark", team=None) # keep track of start/end of draft round
@ -20,15 +16,19 @@ class Draft:
""" """
@classmethod @classmethod
def make_draft(cls): def make_draft(cls, teamsize, draftsize, minsize, pitchers):
draft = cls() draft = cls(teamsize, draftsize, minsize, pitchers)
return draft 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._id = str(uuid.uuid4())[:6]
self._participants = [] self._participants = []
self._active_participant = BOOKMARK # draft mutex 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 self._round = 0
@property @property
@ -68,7 +68,7 @@ class Draft:
self.advance_draft() self.advance_draft()
def refresh_players(self): 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): def advance_draft(self):
""" """
@ -104,12 +104,12 @@ class Draft:
raise ValueError(f'Player `{player_name}` not in draft list') raise ValueError(f'Player `{player_name}` not in draft list')
del self._players[player['name']] del self._players[player['name']]
if len(self._players) <= REFRESH_DRAFT_SIZE: if len(self._players) <= self.REFRESH_DRAFT_SIZE:
self.refresh_players() 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))) 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._active_participant.team.add_pitcher(games.player(json.dumps(player)))
self.advance_draft() self.advance_draft()

View file

@ -2,7 +2,7 @@ import discord, json, math, os, roman, games, asyncio, random, main_controller,
import database as db import database as db
import onomancer as ono import onomancer as ono
from league_storage import league_exists, season_save, season_restart 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 flask import Flask
from uuid import uuid4 from uuid import uuid4
import weather import weather
@ -639,7 +639,34 @@ class StartDraftCommand(Command):
""" """
async def execute(self, msg, command, flags): 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} mentions = {f'<@!{m.id}>' for m in msg.mentions}
content = msg.content.split('\n')[1:] # drop command out of message content = msg.content.split('\n')[1:] # drop command out of message
if not content or len(content) % 3: if not content or len(content) % 3:
@ -668,23 +695,30 @@ class StartDraftCommand(Command):
draft.start_draft() draft.start_draft()
footer = f"The draft class of {random.randint(2007, 2075)}" footer = f"The draft class of {random.randint(2007, 2075)}"
while draft.round <= DRAFT_ROUNDS: while draft.round <= draft.DRAFT_ROUNDS:
message_prefix = f'Round {draft.round}/{DRAFT_ROUNDS}:' message_prefix = f'Round {draft.round}/{draft.DRAFT_ROUNDS}:'
if draft.round == DRAFT_ROUNDS: if draft.round == draft.DRAFT_ROUNDS:
body = random.choice([ body = random.choice([
f"Now just choose a pitcher and we can finish off this paperwork for you, {draft.active_drafter}", 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"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.", f"Almost done, {draft.active_drafter}. Pick your pitcher.",
]) ])
message = f"⚾️ {message_prefix} {body}" message = f"⚾️ {message_prefix} {body}"
else: elif draft.round <= draft.DRAFT_ROUNDS - draft.pitchers:
body = random.choice([ 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"{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.", f"Alright, {draft.active_drafter}, choose a batter.",
]) ])
message = f"🏏 {message_prefix} {body}" 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( await msg.channel.send(
message, message,
embed=build_draft_embed(draft.get_draftees(), footer=footer), embed=build_draft_embed(draft.get_draftees(), footer=footer),
@ -1404,6 +1438,19 @@ class OBLConqueredCommand(Command):
except asyncio.TimeoutError: except asyncio.TimeoutError:
return 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): class TeamsInfoCommand(Command):
name = "teamcount" name = "teamcount"
template = "m;teamcount" template = "m;teamcount"
@ -1441,6 +1488,7 @@ commands = [
OBLSetRivalCommand(), OBLSetRivalCommand(),
OBLConqueredCommand(), OBLConqueredCommand(),
OBLLeaderboardCommand(), OBLLeaderboardCommand(),
OBLResetCommand(),
LeagueClaimCommand(), LeagueClaimCommand(),
LeagueAddOwnersCommand(), LeagueAddOwnersCommand(),
StartLeagueCommand(), StartLeagueCommand(),