done except draft

This commit is contained in:
Sakimori 2023-03-31 14:28:04 -04:00
parent 99fd5b00a3
commit 7fbd793cf5

View file

@ -1548,135 +1548,142 @@ class OBLLeaderboardCommand(Command):
name = "oblstandings" name = "oblstandings"
template = "m;oblstandings" template = "m;oblstandings"
description = "Displays the 15 teams with the most OBL points in this meta-season." description = "Displays the 15 teams with the most OBL points in this meta-season."
async def execute(self, msg, command, flags):
leaders_list = db.obl_leaderboards()[:15]
leaders = []
rank = 1
for team, points in leaders_list:
leaders.append({"name" : team, "points" : points})
rank += 1
embed = discord.Embed(color=discord.Color.red(), title="The One Big League") @client.tree.command()
for index in range(0, len(leaders)): async def oblstandings(interaction):
embed.add_field(name=f"{index+1}. {leaders[index]['name']}", value=f"{leaders[index]['points']} points" , inline = False) leaders_list = db.obl_leaderboards()[:15]
await msg.channel.send(embed=embed) leaders = []
rank = 1
for team, points in leaders_list:
leaders.append({"name" : team, "points" : points})
rank += 1
embed = discord.Embed(color=discord.Color.red(), title="The One Big League")
for index in range(0, len(leaders)):
embed.add_field(name=f"{index+1}. {leaders[index]['name']}", value=f"{leaders[index]['points']} points" , inline = False)
await interaction.response.send_message(embed=embed)
class OBLTeamCommand(Command): class OBLTeamCommand(Command):
name = "oblteam" name = "oblteam"
template = "m;oblteam [team name]" template = "m;oblteam [team name]"
description = "Displays a team's rank, current OBL points, and current opponent selection." description = "Displays a team's rank, current OBL points, and current opponent selection."
async def execute(self, msg, command, flags): @client.tree.command()
team = get_team_fuzzy_search(command.strip()) @app_commands.rename(team_name="team")
if team is None: async def oblteam(interaction, team_name):
raise CommandError("Sorry boss, we can't find that team.") """Displays a team's rank, current OBL points, and current opponent selection."""
team = get_team_fuzzy_search(team_name)
if team is None:
raise CommandError("Sorry boss, we can't find that team.")
rival_team = None rival_team = None
points, beaten_teams_list, opponents_string, rank, rival_name = db.get_obl_stats(team, full=True) points, beaten_teams_list, opponents_string, rank, rival_name = db.get_obl_stats(team, full=True)
opponents_list = db.newline_string_to_list(opponents_string) opponents_list = db.newline_string_to_list(opponents_string)
for index in range(0, len(opponents_list)): for index in range(0, len(opponents_list)):
oppteam = get_team_fuzzy_search(opponents_list[index]) oppteam = get_team_fuzzy_search(opponents_list[index])
opplist = db.get_obl_stats(oppteam)[1] opplist = db.get_obl_stats(oppteam)[1]
if team.name in opplist: if team.name in opplist:
opponents_list[index] = opponents_list[index] + " 🤼" opponents_list[index] = opponents_list[index] + " 🤼"
if rival_name == opponents_list[index]: if rival_name == opponents_list[index]:
opponents_list[index] = opponents_list[index] + " 😈" opponents_list[index] = opponents_list[index] + " 😈"
if rival_name is not None: if rival_name is not None:
rival_team = games.get_team(rival_name) rival_team = games.get_team(rival_name)
opponents_string = db.list_to_newline_string(opponents_list) opponents_string = db.list_to_newline_string(opponents_list)
embed = discord.Embed(color=discord.Color.red(), title=f"{team.name} in the One Big League")
embed.add_field(name="OBL Points", value=points)
embed.add_field(name="Rank", value=rank)
embed.add_field(name="Bounty Board", value=opponents_string, inline=False)
if rival_team is not None:
r_points, r_beaten_teams_list, r_opponents_string, r_rank, r_rival_name = db.get_obl_stats(rival_team, full=True)
embed.add_field(name="Rival", value=f"**{rival_team.name}**: Rank {r_rank}\n{rival_team.slogan}\nPoints: {r_points}")
if r_rival_name == team.name:
embed.set_footer(text="🔥")
else:
embed.set_footer(text="Set a rival with m;oblrival!")
await interaction.response.send_message(embed=embed)
embed = discord.Embed(color=discord.Color.red(), title=f"{team.name} in the One Big League")
embed.add_field(name="OBL Points", value=points)
embed.add_field(name="Rank", value=rank)
embed.add_field(name="Bounty Board", value=opponents_string, inline=False)
if rival_team is not None:
r_points, r_beaten_teams_list, r_opponents_string, r_rank, r_rival_name = db.get_obl_stats(rival_team, full=True)
embed.add_field(name="Rival", value=f"**{rival_team.name}**: Rank {r_rank}\n{rival_team.slogan}\nPoints: {r_points}")
if r_rival_name == team.name:
embed.set_footer(text="🔥")
else:
embed.set_footer(text="Set a rival with m;oblrival!")
await msg.channel.send(embed=embed)
class OBLSetRivalCommand(Command): class OBLSetRivalCommand(Command):
name = "oblrival" name = "oblrival"
template = "m;oblrival\n[your team name]\n[rival team name]" template = "m;oblrival\n[your team name]\n[rival team name]"
description = "Sets your team's OBL rival. Can be changed at any time. Requires ownership." description = "Sets your team's OBL rival. Can be changed at any time. Requires ownership."
async def execute(self, msg, command, flags): @client.tree.command()
try: @app_commands.rename(owned_team_name="yourteam", rival_team_name="newrivalteam")
team_i = get_team_fuzzy_search(command.split("\n")[1].strip()) async def oblsetrival(interaction, owned_team_name: str, rival_team_name: str):
team_r = get_team_fuzzy_search(command.split("\n")[2].strip()) """Sets your team's OBL rival. Can be changed at any time."""
except IndexError: team_i = get_team_fuzzy_search(owned_team_name)
raise CommandError("You didn't give us enough lines. Command on the top, your team in the middle, and your rival at the bottom.") team_r = get_team_fuzzy_search(rival_team_name)
team, owner_id = games.get_team_and_owner(team_i.name) team, owner_id = games.get_team_and_owner(team_i.name)
if team is None or team_r is None: if team is None or team_r is None:
raise CommandError("Can't find one of those teams, boss. Typo?") raise CommandError("Can't find one of those teams, boss. Typo?")
elif owner_id != msg.author.id and msg.author.id not in config()["owners"]: elif owner_id != interaction.user.id and interaction.user.id not in config()["owners"]:
raise CommandError("You're not authorized to mess with this team. Sorry, boss.") raise CommandError("You're not authorized to mess with this team. Sorry, boss.")
try: try:
db.set_obl_rival(team, team_r) db.set_obl_rival(team, team_r)
await msg.channel.send("One pair of mortal enemies, coming right up. Unless you're more of the 'enemies to lovers' type. We can manage that too, don't worry.") await interaction.response.send_message("One pair of mortal enemies, coming right up. Unless you're more of the 'enemies to lovers' type. We can manage that too, don't worry.")
except: except:
raise CommandError("Hm. We don't think that team has tried to do anything in the One Big League yet, so you'll have to wait for consent. Get them to check their bounty board.") raise CommandError("Hm. We don't think that team has tried to do anything in the One Big League yet, so you'll have to wait for consent. Get them to check their bounty board.")
class OBLConqueredCommand(Command): class OBLConqueredCommand(Command):
name = "oblwins" name = "oblwins"
template = "m;oblwins [team name]" template = "m;oblwins [team name]"
description = "Displays all teams that a given team has won points off of." description = "Displays all teams that a given team has won points off of."
async def execute(self, msg, command, flags): @client.tree.command()
team = get_team_fuzzy_search(command.strip()) @app_commands.rename(team_name="team")
if team is None: async def oblconquestlist(interaction, team_name:str):
raise CommandError("Sorry boss, we can't find that team.") team = get_team_fuzzy_search(team_name)
if team is None:
raise CommandError("Sorry boss, we can't find that team.")
points, teams, oppTeams, rank, rivalName = db.get_obl_stats(team, full=True) points, teams, oppTeams, rank, rivalName = db.get_obl_stats(team, full=True)
pages = [] pages = []
page_max = math.ceil(len(teams)/25) page_max = math.ceil(len(teams)/25)
title_text = f"Rank {rank}: {team.name}" title_text = f"Rank {rank}: {team.name}"
for page in range(0,page_max): for page in range(0,page_max):
embed = discord.Embed(color=discord.Color.red(), title=title_text) embed = discord.Embed(color=discord.Color.red(), title=title_text)
embed.set_footer(text = f"{points} OBL Points") embed.set_footer(text = f"{points} OBL Points")
for i in range(0,25): for i in range(0,25):
try: try:
thisteam = games.get_team(teams[i+25*page]) thisteam = games.get_team(teams[i+25*page])
if thisteam.slogan.strip() != "": if thisteam.slogan.strip() != "":
embed.add_field(name=thisteam.name, value=thisteam.slogan) embed.add_field(name=thisteam.name, value=thisteam.slogan)
else: else:
embed.add_field(name=thisteam.name, value="404: Slogan not found") embed.add_field(name=thisteam.name, value="404: Slogan not found")
except: except:
break break
pages.append(embed) pages.append(embed)
teams_list = await msg.channel.send(embed=pages[0]) teams_list = await interaction.channel.send(embed=pages[0])
current_page = 0 current_page = 0
if page_max > 1: if page_max > 1:
await teams_list.add_reaction("") await teams_list.add_reaction("")
await teams_list.add_reaction("") await teams_list.add_reaction("")
def react_check(react, user): def react_check(payload):
return user == msg.author and react.message == teams_list return payload.user_id == interaction.user.id and payload.message_id == teams_list.id
while True: while True:
try: try:
react, user = await client.wait_for('reaction_add', timeout=60.0, check=react_check) payload = await client.wait_for('raw_reaction_add', timeout=60.0, check=react_check)
if react.emoji == "" and current_page > 0: if payload.emoji.name == "" and current_page > 0:
current_page -= 1 current_page -= 1
await react.remove(user) elif payload.emoji.name == "" and current_page < (page_max-1):
elif react.emoji == "" and current_page < (page_max-1): current_page += 1
current_page += 1 await teams_list.edit(embed=pages[current_page])
await react.remove(user) except asyncio.TimeoutError:
await teams_list.edit(embed=pages[current_page]) return
except asyncio.TimeoutError:
return
class OBLResetCommand(Command): class OBLResetCommand(Command):
name = "oblreset" name = "oblreset"
template = "m;oblreset" template = "m;oblreset [bot mention]"
description = "NUKES THE OBL BOARD. BE CAREFUL." description = "NUKES THE OBL BOARD. BE CAREFUL."
def isauthorized(self, user): def isauthorized(self, user):
@ -1689,7 +1696,7 @@ class OBLResetCommand(Command):
class TeamsInfoCommand(Command): class TeamsInfoCommand(Command):
name = "teamcount" name = "teamcount"
template = "m;teamcount" template = "m;teamcount [bot mention]"
description = "Prints a readout of how many teams exist in the sim." description = "Prints a readout of how many teams exist in the sim."
async def execute(self, msg, command, flags): async def execute(self, msg, command, flags):
@ -1699,7 +1706,7 @@ class TeamsInfoCommand(Command):
commands = [ commands = [
IntroduceCommand(), #not needed IntroduceCommand(), #not needed
CountActiveGamesCommand(), #owner only CountActiveGamesCommand(), #owner only
TeamsInfoCommand(), TeamsInfoCommand(), #workaround
AssignOwnerCommand(), #owner only AssignOwnerCommand(), #owner only
ShowPlayerCommand(), #done ShowPlayerCommand(), #done
SaveTeamCommand(), #done SaveTeamCommand(), #done
@ -1718,12 +1725,12 @@ commands = [
StartGameCommand(), #done StartGameCommand(), #done
StartRandomGameCommand(), #done StartRandomGameCommand(), #done
StartTournamentCommand(), #workaround StartTournamentCommand(), #workaround
OBLExplainCommand(), OBLExplainCommand(), #done
OBLTeamCommand(), OBLTeamCommand(), #done
OBLSetRivalCommand(), OBLSetRivalCommand(), #done
OBLConqueredCommand(), OBLConqueredCommand(), #done
OBLLeaderboardCommand(), OBLLeaderboardCommand(), #done
OBLResetCommand(), OBLResetCommand(), #not needed
LeagueClaimCommand(), #done LeagueClaimCommand(), #done
LeagueAddOwnersCommand(), #done LeagueAddOwnersCommand(), #done
LeagueSetPlayerModifiersCommand(), #was a test command, never fully tested LeagueSetPlayerModifiersCommand(), #was a test command, never fully tested