mirror of
https://github.com/insertapp/mmolbbot.git
synced 2025-07-01 14:27:03 +00:00
feat: game history
This commit is contained in:
parent
4ccc90fda8
commit
6870f7ccd3
3 changed files with 68 additions and 3 deletions
1
bot.py
1
bot.py
|
@ -37,6 +37,7 @@ async def on_ready():
|
|||
bot.db = db
|
||||
bot.cur = cur
|
||||
bot.load_extension('cogs.liveupdate')
|
||||
bot.load_extension('cogs.error')
|
||||
bot.load_extension('cogs.team')
|
||||
bot.add_all_application_commands()
|
||||
await bot.sync_all_application_commands()
|
||||
|
|
|
@ -241,10 +241,10 @@ class liveupdate(commands.Cog):
|
|||
DELETE from liveupdate WHERE messageid = {messageid}
|
||||
""")
|
||||
await self.bot.db.commit()
|
||||
await message.edit(f"An error ocdbed in this live update\n{e}")
|
||||
await message.edit(f"An error occoured in this live update\n{e}")
|
||||
|
||||
|
||||
@tasks.loop(seconds=30.0)
|
||||
@tasks.loop(seconds=120.0)
|
||||
async def checkspotlightsubscriptions(self):
|
||||
try:
|
||||
await self.bot.wait_until_ready()
|
||||
|
@ -281,7 +281,7 @@ class liveupdate(commands.Cog):
|
|||
return
|
||||
|
||||
|
||||
@tasks.loop(seconds=35.0)
|
||||
@tasks.loop(seconds=120.0)
|
||||
async def checkteamsubscriptions(self):
|
||||
try:
|
||||
print("refreshing team subscriptions")
|
||||
|
|
64
cogs/team.py
64
cogs/team.py
|
@ -6,6 +6,7 @@ import requests
|
|||
import re
|
||||
import asyncio
|
||||
import nextcord
|
||||
import itertools
|
||||
from nextcord.ext import commands, application_checks
|
||||
from nextcord import TextInputStyle, IntegrationType
|
||||
|
||||
|
@ -193,6 +194,32 @@ class TeamView(nextcord.ui.View):
|
|||
for i in splistats:
|
||||
await interaction.followup.send(f"```ansi\n{i}```",ephemeral=True)
|
||||
|
||||
@nextcord.ui.button(
|
||||
label="Game History", style=nextcord.ButtonStyle.green, custom_id="team:gamehistory"
|
||||
)
|
||||
async def gamehistorybutton(self, button: nextcord.ui.Button, interaction: nextcord.Interaction):
|
||||
await interaction.response.defer()
|
||||
ogmsg = interaction.message.embeds
|
||||
embed = ogmsg[0]
|
||||
teamid = embed.footer.text
|
||||
data = requests.get(f"https://mmolb.com/api/team/{teamid}").json()
|
||||
history = requests.get(f"https://lunanova.space/mmolb/api/gamesbyteam/{teamid}").json()
|
||||
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.set_footer(text=teamid)
|
||||
for index in itertools.islice(history, (len(history)-10 if len(history)-10 > 0 else 0) , len(history)):
|
||||
if history[index]["away_team_id"] != teamid:
|
||||
awayteamid = history[index]["away_team_id"]
|
||||
otherscore = history[index]["away_score"]
|
||||
ourscore = history[index]["home_score"]
|
||||
else:
|
||||
awayteamid = history[index]["home_team_id"]
|
||||
otherscore = history[index]["home_score"]
|
||||
ourscore = history[index]["away_score"]
|
||||
tempdata = requests.get(f"https://mmolb.com/api/team/{awayteamid}").json()
|
||||
embed.add_field(name=f"vs. {tempdata["Location"]} {tempdata["Name"]} {tempdata["Emoji"]} ({ourscore} - {otherscore})", value=f"[watch](<https://mmolb.com/watch/{index}>)", inline=False)
|
||||
await interaction.followup.send(embed=embed,ephemeral=True)
|
||||
|
||||
class team(commands.Cog):
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
|
@ -277,6 +304,43 @@ class team(commands.Cog):
|
|||
embed.add_field(name="Championships", value=f"{data["Championships"]}", inline=True)
|
||||
await interaction.edit_original_message(embed=embed,view=TeamView())
|
||||
|
||||
@nextcord.slash_command(
|
||||
name="gamehistory",
|
||||
description="Get the last 10 games played by a team",
|
||||
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 gamehistory(self, interaction: nextcord.Interaction, teamid: str = nextcord.SlashOption(
|
||||
name = "team",
|
||||
description = "The team"
|
||||
)):
|
||||
await interaction.response.defer()
|
||||
data = requests.get(f"https://mmolb.com/api/team/{teamid}").json()
|
||||
history = requests.get(f"https://lunanova.space/mmolb/api/gamesbyteam/{teamid}").json()
|
||||
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.set_footer(text=teamid)
|
||||
for index in itertools.islice(history, (len(history)-10 if len(history)-10 > 0 else 0) , len(history)):
|
||||
if history[index]["away_team_id"] != teamid:
|
||||
awayteamid = history[index]["away_team_id"]
|
||||
otherscore = history[index]["away_score"]
|
||||
ourscore = history[index]["home_score"]
|
||||
else:
|
||||
awayteamid = history[index]["home_team_id"]
|
||||
otherscore = history[index]["home_score"]
|
||||
ourscore = history[index]["away_score"]
|
||||
tempdata = requests.get(f"https://mmolb.com/api/team/{awayteamid}").json()
|
||||
embed.add_field(name=f"vs. {tempdata["Location"]} {tempdata["Name"]} {tempdata["Emoji"]} ({ourscore} - {otherscore})", value=f"[watch](<https://mmolb.com/watch/{index}>)", inline=False)
|
||||
await interaction.edit_original_message(embed=embed)
|
||||
|
||||
|
||||
@nextcord.slash_command(
|
||||
name="teamstats",
|
||||
|
|
Loading…
Reference in a new issue