mirror of
https://github.com/insertapp/mmolbbot.git
synced 2025-07-01 14:27:03 +00:00
feat: get league ranking information
This commit is contained in:
parent
f7b7867d50
commit
0ad64bc326
3 changed files with 53 additions and 3 deletions
|
@ -23,6 +23,7 @@ class error(commands.Cog):
|
||||||
random.shuffle(errormsg)
|
random.shuffle(errormsg)
|
||||||
strerror = "".join(error)
|
strerror = "".join(error)
|
||||||
print(strerror, file=sys.stderr)
|
print(strerror, file=sys.stderr)
|
||||||
|
await self.bot.application_info()
|
||||||
message = f"{errormsg[0]}\n```py\n{strerror[-1800:]}\n```\n Contact <@{self.bot.owner_id}> if the error persists"
|
message = f"{errormsg[0]}\n```py\n{strerror[-1800:]}\n```\n Contact <@{self.bot.owner_id}> if the error persists"
|
||||||
try:
|
try:
|
||||||
await interaction.response.send_message(message, ephemeral=True)
|
await interaction.response.send_message(message, ephemeral=True)
|
||||||
|
|
|
@ -8,6 +8,7 @@ import nextcord
|
||||||
import aiosqlite as sqlite3
|
import aiosqlite as sqlite3
|
||||||
from nextcord.ext import commands, application_checks, tasks
|
from nextcord.ext import commands, application_checks, tasks
|
||||||
from nextcord import TextInputStyle, IntegrationType
|
from nextcord import TextInputStyle, IntegrationType
|
||||||
|
import itertools
|
||||||
|
|
||||||
leagues_dict = {}
|
leagues_dict = {}
|
||||||
leagues_list = []
|
leagues_list = []
|
||||||
|
@ -37,5 +38,46 @@ class league(commands.Cog):
|
||||||
self.bot.leagues_list = leagues_list
|
self.bot.leagues_list = leagues_list
|
||||||
self.bot.leagues_dict = leagues_dict
|
self.bot.leagues_dict = leagues_dict
|
||||||
|
|
||||||
|
|
||||||
|
@nextcord.slash_command(
|
||||||
|
name="ranking",
|
||||||
|
description="Get a leaguess overall rankings",
|
||||||
|
integration_types=[
|
||||||
|
IntegrationType.user_install,
|
||||||
|
IntegrationType.guild_install,
|
||||||
|
],
|
||||||
|
contexts=[
|
||||||
|
nextcord.InteractionContextType.guild,
|
||||||
|
nextcord.InteractionContextType.bot_dm,
|
||||||
|
nextcord.InteractionContextType.private_channel,
|
||||||
|
],
|
||||||
|
force_global=True,
|
||||||
|
)
|
||||||
|
async def leaguesranking(self, interaction: nextcord.Interaction, league: str):
|
||||||
|
if league not in leagues_dict:
|
||||||
|
await interaction.response.send_message("Invalid league!", ephemeral=True)
|
||||||
|
return
|
||||||
|
await interaction.response.defer()
|
||||||
|
leagueid = leagues_dict[league]
|
||||||
|
basedata = requests.get(f"https://mmolb.com/api/league/{leagueid}").json()
|
||||||
|
rankdata = requests.get(f"https://mmolb.com/api/league-top-teams/{leagueid}").json()
|
||||||
|
color = tuple(int(basedata["Color"][i:i+2], 16) for i in (0, 2, 4))
|
||||||
|
embed = nextcord.Embed(title=f"Top teams for the {basedata["Name"]} League {basedata["Emoji"]}", colour = nextcord.Color.from_rgb(color[0], color[1], color[2]))
|
||||||
|
rankdata = rankdata["teams"]
|
||||||
|
for i in itertools.islice(rankdata, 0, 10):
|
||||||
|
embed.add_field(name=f"{i["Location"]} {i["Name"]} {i["Emoji"]} ", value=f"[{i["Record"]["Regular Season"]["Wins"]}-{i["Record"]["Regular Season"]["Losses"]} ({i["Record"]["Regular Season"]["RunDifferential"]})](<https://mmolb.com/team/{i["_id"]}>)",inline=False)
|
||||||
|
embed.set_footer(text=leagueid)
|
||||||
|
await interaction.edit_original_message(embed=embed)
|
||||||
|
|
||||||
|
@leaguesranking.on_autocomplete("league")
|
||||||
|
async def leaguesrankingac(self, interaction: nextcord.Interaction, league: str):
|
||||||
|
if not league:
|
||||||
|
thanksdiscord = leagues_list[:20]
|
||||||
|
await interaction.response.send_autocomplete(thanksdiscord)
|
||||||
|
return
|
||||||
|
closestteam = [name for name in leagues_list if name.lower().startswith(league.lower())]
|
||||||
|
thanksdiscord = closestteam[:20]
|
||||||
|
await interaction.response.send_autocomplete(thanksdiscord)
|
||||||
|
|
||||||
def setup(bot: commands.Bot):
|
def setup(bot: commands.Bot):
|
||||||
bot.add_cog(league(bot))
|
bot.add_cog(league(bot))
|
13
cogs/team.py
13
cogs/team.py
|
@ -216,7 +216,7 @@ class TeamView(nextcord.ui.View):
|
||||||
embed = ogmsg[0]
|
embed = ogmsg[0]
|
||||||
teamid = embed.footer.text
|
teamid = embed.footer.text
|
||||||
data = requests.get(f"https://mmolb.com/api/team/{teamid}").json()
|
data = requests.get(f"https://mmolb.com/api/team/{teamid}").json()
|
||||||
history = requests.get(f"https://freecashe.ws/api/games?team={teamid}&season=0").json()["items"]
|
history = requests.get(f"https://freecashe.ws/api/games?team={teamid}&season=1").json()["items"]
|
||||||
color = tuple(int(data["Color"][i:i+2], 16) for i in (0, 2, 4))
|
color = tuple(int(data["Color"][i:i+2], 16) for i in (0, 2, 4))
|
||||||
embed = nextcord.Embed(title=f"Last ten games for the {data["Location"]} {data["Name"]} {data["Emoji"]}", colour = nextcord.Color.from_rgb(color[0], color[1], color[2]))
|
embed = nextcord.Embed(title=f"Last ten games for the {data["Location"]} {data["Name"]} {data["Emoji"]}", colour = nextcord.Color.from_rgb(color[0], color[1], color[2]))
|
||||||
embed.set_footer(text=teamid)
|
embed.set_footer(text=teamid)
|
||||||
|
@ -267,12 +267,19 @@ class team(commands.Cog):
|
||||||
await interaction.response.defer()
|
await interaction.response.defer()
|
||||||
teamid = teams_dict[team]
|
teamid = teams_dict[team]
|
||||||
data = requests.get(f"https://mmolb.com/api/team/{teamid}").json()
|
data = requests.get(f"https://mmolb.com/api/team/{teamid}").json()
|
||||||
|
rankdata = requests.get(f"https://mmolb.com/api/league-top-teams/{data["League"]}").json()["teams"]
|
||||||
|
ranking = 0
|
||||||
|
for i in rankdata:
|
||||||
|
ranking += 1
|
||||||
|
if i["_id"] == teamid:
|
||||||
|
break
|
||||||
color = tuple(int(data["Color"][i:i+2], 16) for i in (0, 2, 4))
|
color = tuple(int(data["Color"][i:i+2], 16) for i in (0, 2, 4))
|
||||||
embed = nextcord.Embed(title=f"{data["Location"]} {data["Name"]} {data["Emoji"]}", description=f"{data["Motto"]}", colour = nextcord.Color.from_rgb(color[0], color[1], color[2]))
|
embed = nextcord.Embed(title=f"{data["Location"]} {data["Name"]} {data["Emoji"]}", description=f"{data["Motto"]}", colour = nextcord.Color.from_rgb(color[0], color[1], color[2]))
|
||||||
embed.add_field(name="League", value=f"{dict((v,k) for k,v in self.bot.leagues_dict.items())[data["League"]]}", inline=True)
|
embed.add_field(name="League", value=f"{dict((v,k) for k,v in self.bot.leagues_dict.items())[data["League"]]}", inline=True)
|
||||||
embed.add_field(name="Wins", value=f"{data["Record"]["Regular Season"]["Wins"]}", inline=True)
|
embed.add_field(name="Wins", value=f"{data["Record"]["Regular Season"]["Wins"]}", inline=True)
|
||||||
embed.add_field(name="Losses", value=f"{data["Record"]["Regular Season"]["Losses"]}", inline=True)
|
embed.add_field(name="Losses", value=f"{data["Record"]["Regular Season"]["Losses"]}", inline=True)
|
||||||
embed.add_field(name="Run Differential", value=f"{data["Record"]["Regular Season"]["RunDifferential"]}", inline=True)
|
embed.add_field(name="Run Differential", value=f"{data["Record"]["Regular Season"]["RunDifferential"]}", inline=True)
|
||||||
|
embed.add_field(name="Rank", value=f"{ranking}", inline=True)
|
||||||
embed.add_field(name="Augments", value=f"{data["Augments"]}", inline=True)
|
embed.add_field(name="Augments", value=f"{data["Augments"]}", inline=True)
|
||||||
embed.add_field(name="Championships", value=f"{data["Championships"]}", inline=True)
|
embed.add_field(name="Championships", value=f"{data["Championships"]}", inline=True)
|
||||||
embed.set_footer(text=teamid)
|
embed.set_footer(text=teamid)
|
||||||
|
@ -342,8 +349,8 @@ class team(commands.Cog):
|
||||||
|
|
||||||
|
|
||||||
@nextcord.slash_command(
|
@nextcord.slash_command(
|
||||||
name="teamstats",
|
name="players",
|
||||||
description="Get a teams stats",
|
description="Get a team's player statistics",
|
||||||
integration_types=[
|
integration_types=[
|
||||||
IntegrationType.user_install,
|
IntegrationType.user_install,
|
||||||
IntegrationType.guild_install,
|
IntegrationType.guild_install,
|
||||||
|
|
Loading…
Reference in a new issue