feat: game history

This commit is contained in:
insert 2025-04-27 18:30:36 -04:00
parent 4ccc90fda8
commit 6870f7ccd3
Signed by: insert
GPG key ID: A70775C389ACF105
3 changed files with 68 additions and 3 deletions

1
bot.py
View file

@ -37,6 +37,7 @@ async def on_ready():
bot.db = db bot.db = db
bot.cur = cur bot.cur = cur
bot.load_extension('cogs.liveupdate') bot.load_extension('cogs.liveupdate')
bot.load_extension('cogs.error')
bot.load_extension('cogs.team') bot.load_extension('cogs.team')
bot.add_all_application_commands() bot.add_all_application_commands()
await bot.sync_all_application_commands() await bot.sync_all_application_commands()

View file

@ -241,10 +241,10 @@ class liveupdate(commands.Cog):
DELETE from liveupdate WHERE messageid = {messageid} DELETE from liveupdate WHERE messageid = {messageid}
""") """)
await self.bot.db.commit() 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): async def checkspotlightsubscriptions(self):
try: try:
await self.bot.wait_until_ready() await self.bot.wait_until_ready()
@ -281,7 +281,7 @@ class liveupdate(commands.Cog):
return return
@tasks.loop(seconds=35.0) @tasks.loop(seconds=120.0)
async def checkteamsubscriptions(self): async def checkteamsubscriptions(self):
try: try:
print("refreshing team subscriptions") print("refreshing team subscriptions")

View file

@ -6,6 +6,7 @@ import requests
import re import re
import asyncio import asyncio
import nextcord import nextcord
import itertools
from nextcord.ext import commands, application_checks from nextcord.ext import commands, application_checks
from nextcord import TextInputStyle, IntegrationType from nextcord import TextInputStyle, IntegrationType
@ -193,6 +194,32 @@ class TeamView(nextcord.ui.View):
for i in splistats: for i in splistats:
await interaction.followup.send(f"```ansi\n{i}```",ephemeral=True) 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): class team(commands.Cog):
def __init__(self, bot: commands.Bot): 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) embed.add_field(name="Championships", value=f"{data["Championships"]}", inline=True)
await interaction.edit_original_message(embed=embed,view=TeamView()) 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( @nextcord.slash_command(
name="teamstats", name="teamstats",