finished league management commands, started OBL

This commit is contained in:
Sakimori 2023-03-31 14:07:01 -04:00
parent a7a9e37842
commit 99fd5b00a3

View file

@ -1133,6 +1133,7 @@ class LeagueDivisionDisplayCommand(Command):
@client.tree.command()
@app_commands.rename(league_name="leaguename", division_name="division")
async def divisionstandings(interaction, league_name: str, division_name: str):
"""Displays the current standings for the given division in the given league."""
if league_exists(league_name):
league = leagues.load_league_file(league_name)
division = None
@ -1154,11 +1155,14 @@ class LeagueWildcardCommand(Command):
template = "m;leaguewildcard [league name]"
description = "Displays the current wildcard race for the given league, if the league has wildcard slots."
async def execute(self, msg, command, flags):
if league_exists(command.strip()):
league = leagues.load_league_file(command.strip())
@client.tree.command()
@app_commands.rename(league_name="leaguename")
async def wildcard(interaction, league_name: str):
"""Displays the current wildcard race for the given league, if the league has wildcard slots."""
if league_exists(league_name):
league = leagues.load_league_file(league_name)
if league.constraints["wild_cards"] > 0:
await msg.channel.send(embed=league.wildcard_embed())
await interaction.response.send_message(embed=league.wildcard_embed())
else:
raise CommandError("That league doesn't have wildcards, boss.")
else:
@ -1169,13 +1173,16 @@ class LeaguePauseCommand(Command):
template = "m;pauseleague [league name]"
description = "Tells a currently running league to stop running after the current series."
async def execute(self, msg, command, flags):
league_name = command.strip()
@client.tree.command()
@app_commands.rename(league_name="leaguename")
async def leaguepause(interaction, league_name: str):
"""Tells a currently running league to stop running after the current series."""
for active_league in active_leagues:
if active_league.name == league_name:
if (active_league.owner is not None and msg.author.id in active_league.owner) or msg.author.id in config()["owners"]:
if (active_league.owner is not None and interaction.user.id in active_league.owner) or interaction.user.id in config()["owners"]:
active_league.autoplay = 0
await msg.channel.send(f"Loud and clear, chief. {league_name} will stop after this series is over.")
await interaction.response.send_message(f"Loud and clear, chief. {league_name} will stop after this series is over.")
return
else:
raise CommandError("You don't have permission to manage that league.")
@ -1186,14 +1193,17 @@ class LeagueClaimCommand(Command):
template = "m;claimleague [league name]"
description = "Claims an unclaimed league. Do this as soon as possible after creating the league, or it will remain unclaimed."
async def execute(self, msg, command, flags):
league_name = command.strip()
@client.tree.command()
@app_commands.rename(league_name="leaguename")
async def claimleague(interaction, league_name: str):
"""Claims an unclaimed league. Do this as soon as possible after creating the league, or it will remain unclaimed."""
if league_exists(league_name):
league = leagues.load_league_file(league_name)
if league.owner is None:
league.owner = [msg.author.id]
league.owner = [interaction.user.id]
leagues.save_league(league)
await msg.channel.send(f"The {league.name} commissioner is doing a great job. That's you, by the way.")
await interaction.response.send_message(f"The {league.name} commissioner is doing a great job. That's you, by the way.")
return
else:
raise CommandError("That league has already been claimed!")
@ -1205,16 +1215,18 @@ class LeagueAddOwnersCommand(Command):
template = "m;addleagueowner [league name]\n[user mentions]"
description = "Adds additional owners to a league."
async def execute(self, msg, command, flags):
league_name = command.split("\n")[0].strip()
@client.tree.command()
@app_commands.rename(league_name="leaguename", newowner="newownermention")
async def addleagueowner(interaction, league_name: str, newowner: str):
"""Adds an owner to a league."""
if league_exists(league_name):
league = leagues.load_league_file(league_name)
if (league.owner is not None and msg.author.id in league.owner) or (league.owner is not None and msg.author.id in config()["owners"]):
for user in msg.mentions:
if user.id not in league.owner:
league.owner.append(user.id)
if (league.owner is not None and interaction.user.id in league.owner) or (league.owner is not None and interaction.user.id in config()["owners"]):
if int(newowner[2:-1]) not in league.owner:
league.owner.append(int(newowner[2:-1]))
leagues.save_league(league)
await msg.channel.send(f"The new {league.name} front office is now up and running.")
await interaction.response.send(f"The new {league.name} front office is now up and running.")
return
else:
raise CommandError(f"That league isn't yours, boss.")
@ -1226,8 +1238,10 @@ class LeagueScheduleCommand(Command):
template = "m;leagueschedule [league name]"
description = "Sends an embed with the given league's schedule for the next 4 series."
async def execute(self, msg, command, flags):
league_name = command.split("\n")[0].strip()
@client.tree.command()
@app_commands.rename(league_name="leaguename")
async def leagueschedule(interaction, league_name:str):
"""Show a league's 4-series schedule."""
if league_exists(league_name):
league = leagues.load_league_file(league_name)
current_series = league.day_to_series_num(league.day)
@ -1270,7 +1284,7 @@ class LeagueScheduleCommand(Command):
schedule_text = ""
sched_embed.add_field(name=embed_title, value=schedule_text, inline = False)
await msg.channel.send(embed=sched_embed)
await interaction.response.send_message(embed=sched_embed)
else:
raise CommandError("That league's already finished with this season, boss.")
else:
@ -1281,9 +1295,11 @@ class LeagueTeamScheduleCommand(Command):
template = "m;teamschedule [league name]\n[team name]"
description = "Sends an embed with the given team's schedule in the given league for the next 7 series."
async def execute(self, msg, command, flags):
league_name = command.split("\n")[0].strip()
team_name = command.split("\n")[1].strip()
@client.tree.command()
@app_commands.rename(league_name="leaguename", team_name="teamname")
async def teamschedule(interaction, league_name: str, team_name: str):
"""Shows a team's 7-series schedule in a specific league."""
team = get_team_fuzzy_search(team_name)
if league_exists(league_name):
league = leagues.load_league_file(league_name)
@ -1299,7 +1315,6 @@ class LeagueTeamScheduleCommand(Command):
if str(current_series+day) in league.schedule.keys():
schedule_text = ""
for game in league.schedule[str(current_series+day)]:
if team.name in game:
emojis = ""
@ -1309,7 +1324,7 @@ class LeagueTeamScheduleCommand(Command):
if schedule_text == "":
schedule_text += "Resting"
sched_embed.add_field(name=f"Days {((current_series+day-1)*league.series_length) + 1} - {(current_series+day)*(league.series_length)}", value=schedule_text, inline = False)
await msg.channel.send(embed=sched_embed)
await interaction.response.send_message(embed=sched_embed)
else:
raise CommandError("That league's already finished with this season, boss.")
else:
@ -1320,17 +1335,19 @@ class LeagueRegenerateScheduleCommand(Command):
template = "m;leagueseasonreset [league name]"
description = "Completely scraps the given league's current season, resetting everything to day 1 of the current season. Requires ownership."
async def execute(self, msg, command, flags):
league_name = command.split("\n")[0].strip()
@client.tree.command()
@app_commands.rename(league_name="leaguename")
async def leaguereset(interaction, league_name: str):
"""Completely scraps the given league's current season, resetting everything to day 1 of the current season. Requires ownership."""
if league_exists(league_name):
league = leagues.load_league_file(league_name)
if (league.owner is not None and msg.author.id in league.owner) or (league.owner is not None and msg.author.id in config()["owners"]):
await msg.channel.send("You got it, boss. Give us two seconds and a bucket of white-out.")
if (league.owner is not None and interaction.user.id in league.owner) or (league.owner is not None and interaction.user.id in config()["owners"]):
await interaction.response.send_message("You got it, boss. Give us two seconds and a bucket of white-out.")
season_restart(league)
league.season -= 1
league.season_reset()
await asyncio.sleep(1)
await msg.channel.send("Done and dusted. Go ahead and start the league again whenever you want.")
await interaction.channel.send("Done and dusted. Go ahead and start the league again whenever you want.")
return
else:
raise CommandError("That league isn't yours, boss.")
@ -1339,14 +1356,14 @@ class LeagueRegenerateScheduleCommand(Command):
class LeagueForceStopCommand(Command):
name = "leagueforcestop"
template = "m;leagueforcestop [league name]"
template = "m;leagueforcestop [league name] [bot mention]"
description = "Halts a league and removes it from the list of currently running leagues. To be used in the case of crashed loops."
def isauthorized(self, user):
return user.id in config()["owners"]
async def execute(self, msg, command, flags):
league_name = command.split("\n")[0].strip()
league_name = command.split("\n")[0].split(" ")[0].strip()
for index in range(0,len(active_leagues)):
if active_leagues[index].name == league_name:
active_leagues.pop(index)
@ -1359,17 +1376,20 @@ class LeagueReplaceTeamCommand(Command):
template = "m;leaguereplaceteam [league name]\n[team to remove]\n[team to add]"
description = "Adds a team to a league, removing the old one in the process. Can only be executed by a league owner, and only before the start of a new season."
async def execute(self, msg, command, flags):
league_name = command.split("\n")[0].strip()
@client.tree.command()
@app_commands.rename(league_name="leaguename")
async def leaguereplaceteam(interaction, league_name: str, removeteam: str, addteam: str):
"""Removes a team from a league, replacing it with another."""
if league_exists(league_name):
league = leagues.load_league_file(league_name)
if league.day != 1:
await msg.channel.send("That league hasn't finished its current season yet, chief. Either reset it, or be patient.")
await interaction.response.send("That league hasn't finished its current season yet, chief. Either reset it, or be patient.")
return
if (league.owner is not None and msg.author.id in league.owner) or (league.owner is not None and msg.author.id in config()["owners"]):
if (league.owner is not None and interaction.user.id in league.owner) or (league.owner is not None and interaction.user.id in config()["owners"]):
try:
team_del = get_team_fuzzy_search(command.split("\n")[1].strip())
team_add = get_team_fuzzy_search(command.split("\n")[2].strip())
team_del = get_team_fuzzy_search(removeteam)
team_add = get_team_fuzzy_search(addteam)
except IndexError:
raise CommandError("Three lines, boss. Make sure you give us the team to remove, then the team to add.")
if team_add.name == team_del.name:
@ -1393,8 +1413,8 @@ class LeagueReplaceTeamCommand(Command):
league.schedule = {}
league.generate_schedule()
leagues.save_league_as_new(league)
await msg.channel.send(embed=league.standings_embed())
await msg.channel.send("Paperwork signed, stamped, copied, and faxed up to the goddess. Xie's pretty quick with this stuff.")
await interaction.response.send_message(embed=league.standings_embed())
await interaction.channel.send("Paperwork signed, stamped, copied, and faxed up to the goddess. Xie's pretty quick with this stuff.")
else:
raise CommandError("That league isn't yours, chief.")
else:
@ -1407,15 +1427,21 @@ class LeagueSwapTeamCommand(Command):
async def execute(self, msg, command, flags):
league_name = command.split("\n")[0].strip()
@client.tree.command()
@app_commands.rename(league_name="leaguename")
async def leagueswapteam(interaction, league_name: str, teama: str, teamb: str):
"""Swaps two teams' divisional assignments."""
if league_exists(league_name):
league = leagues.load_league_file(league_name)
if league.day != 1:
await msg.channel.send("That league hasn't finished its current season yet, chief. Either reset it, or be patient.")
await interaction.response.send_message("That league hasn't finished its current season yet, chief. Either reset it, or be patient.")
return
if (league.owner is not None and msg.author.id in league.owner) or (league.owner is not None and msg.author.id in config()["owners"]):
if (league.owner is not None and interaction.user.id in league.owner) or (league.owner is not None and interaction.user.id in config()["owners"]):
try:
team_a = get_team_fuzzy_search(command.split("\n")[1].strip())
team_b = get_team_fuzzy_search(command.split("\n")[2].strip())
team_a = get_team_fuzzy_search(teama)
team_b = get_team_fuzzy_search(teamb)
except IndexError:
raise CommandError("Three lines, boss. Make sure you give us the team to remove, then the team to add.")
if team_a.name == team_b.name:
@ -1442,14 +1468,13 @@ class LeagueSwapTeamCommand(Command):
league.schedule = {}
league.generate_schedule()
leagues.save_league_as_new(league)
await msg.channel.send(embed=league.standings_embed())
await msg.channel.send("Paperwork signed, stamped, copied, and faxed up to the goddess. Xie's pretty quick with this stuff.")
await interaction.response.send_message(embed=league.standings_embed())
await interaction.channel.send("Paperwork signed, stamped, copied, and faxed up to the goddess. Xie's pretty quick with this stuff.")
else:
raise CommandError("That league isn't yours, chief.")
else:
raise CommandError("We can't find that league.")
class LeagueRenameCommand(Command):
name = "leaguerename"
template = "m;leaguerename [league name]\n[old conference/division name]\n[new conference/division name]"
@ -1510,10 +1535,13 @@ class OBLExplainCommand(Command):
template = "m;oblhelp"
description = "Explains the One Big League!"
async def execute(self, msg, command, flags):
await msg.channel.send("""The One Big League, or OBL, is an asynchronous league that includes every team in the simsim's database. To participate, just use the m;oblteam command with your team of choice. **No signup is required!** This will give you a list of five opponents; playing against one of them and winning nets you a point, and will refresh the list with five new opponents. **Losing results in no penalty!** Each meta-season will last for a few weeks, after which the leaderboards are reset to start the race again!
Look out for the people wrestling emoji, which indicates the potential for a :people_wrestling:Wrassle Match:people_wrestling:, where both teams are on each others' lists and both have the opportunity to score a point. Team rankings and points can also be viewed in the m;oblteam command, and the overall OBL leaderboard can be checked with the m;oblstandings command. Best of luck!!
@client.tree.command()
async def oblhelp(interaction):
"""Explains the One Big League!"""
await interaction.response.send_message("""The One Big League, or OBL, is an asynchronous league that includes every team in sim16's database. To participate, just use the oblteam command with your team of choice. **No signup is required!** This will give you a list of five opponents; playing against one of them and winning nets you a point, and will refresh the list with five new opponents. **Losing results in no penalty!** Each meta-season will last for ~~a few weeks~~ *shrugs*, after which the leaderboards are reset to start the race again!
Look out for the people wrestling emoji, which indicates the potential for a 🤼Wrassle Match🤼, where both teams are on each others' lists and both have the opportunity to score a point. Team rankings and points can also be viewed in the oblteam command, and the overall OBL leaderboard can be checked with the oblstandings command. Best of luck!!
""")
class OBLLeaderboardCommand(Command):
@ -1696,23 +1724,23 @@ commands = [
OBLConqueredCommand(),
OBLLeaderboardCommand(),
OBLResetCommand(),
LeagueClaimCommand(),
LeagueAddOwnersCommand(),
LeagueClaimCommand(), #done
LeagueAddOwnersCommand(), #done
LeagueSetPlayerModifiersCommand(), #was a test command, never fully tested
StartLeagueCommand(), #done
LeagueSubscribeCommand(), #done
LeaguePauseCommand(),
LeaguePauseCommand(), #done
LeagueDisplayCommand(), #done
LeagueLeadersCommand(), #done
LeagueDivisionDisplayCommand(), #done
LeagueWildcardCommand(),
LeagueScheduleCommand(),
LeagueTeamScheduleCommand(),
LeagueRegenerateScheduleCommand(),
LeagueSwapTeamCommand(),
LeagueReplaceTeamCommand(),
LeagueRenameCommand(),
LeagueForceStopCommand(),
LeagueWildcardCommand(), #done
LeagueScheduleCommand(), #done
LeagueTeamScheduleCommand(), #done
LeagueRegenerateScheduleCommand(), #done
LeagueSwapTeamCommand(), #done
LeagueReplaceTeamCommand(), #done
LeagueRenameCommand(), #postponing
LeagueForceStopCommand(), #not needed
CreditCommand(), #done
RomanCommand(), #not needed
HelpCommand(),