mirror of
https://github.com/insertapp/mmolbbot.git
synced 2025-08-01 18:53:33 +00:00
feat: team feed command
This commit is contained in:
parent
9e52347be3
commit
edaccdc684
1 changed files with 63 additions and 3 deletions
66
cogs/team.py
66
cogs/team.py
|
@ -7,6 +7,7 @@ import re
|
|||
import asyncio
|
||||
import nextcord
|
||||
import itertools
|
||||
import aiohttp
|
||||
from nextcord.ext import commands, application_checks, tasks
|
||||
from nextcord import TextInputStyle, IntegrationType
|
||||
|
||||
|
@ -211,7 +212,7 @@ class TeamView(nextcord.ui.View):
|
|||
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()
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
ogmsg = interaction.message.embeds
|
||||
embed = ogmsg[0]
|
||||
teamid = embed.footer.text
|
||||
|
@ -233,6 +234,25 @@ class TeamView(nextcord.ui.View):
|
|||
embed.add_field(name=f"vs. {tempdata["Location"]} {tempdata["Name"]} {tempdata["Emoji"]} ({ourscore} - {otherscore})", value=f"[watch](<https://mmolb.com/watch/{index['game_id']}>)", inline=False)
|
||||
await interaction.followup.send(embed=embed,ephemeral=True)
|
||||
|
||||
@nextcord.ui.button(
|
||||
label="Feed", style=nextcord.ButtonStyle.green, custom_id="team:feed"
|
||||
)
|
||||
async def feedbutton(self, button: nextcord.ui.Button, interaction: nextcord.Interaction):
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
ogmsg = interaction.message.embeds
|
||||
embed = ogmsg[0]
|
||||
teamid = embed.footer.text
|
||||
async with aiohttp.ClientSession() as session:
|
||||
data = await session.get(f"https://mmolb.com/api/team/{teamid}")
|
||||
data = await data.json()
|
||||
color = tuple(int(data["Color"][i:i+2], 16) for i in (0, 2, 4))
|
||||
embed = nextcord.Embed(title=f"Last ten feed events for the {data["Location"]} {data["Name"]} {data["Emoji"]}", colour = nextcord.Color.from_rgb(color[0], color[1], color[2]))
|
||||
embed.set_footer(text=teamid)
|
||||
data = data['Feed']
|
||||
for index in itertools.islice(data, (len(data)-10 if len(data)-10 > 0 else 0) , len(data)):
|
||||
embed.add_field(name=f"{index['emoji']} Day {index['day']} Season {index['season']}", value=index['text'], inline=False)
|
||||
await interaction.followup.send(embed=embed,ephemeral=True)
|
||||
|
||||
class team(commands.Cog):
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
|
@ -319,7 +339,7 @@ class team(commands.Cog):
|
|||
await interaction.response.defer()
|
||||
teamid = teams_dict[team]
|
||||
data = requests.get(f"https://mmolb.com/api/team/{teamid}").json()
|
||||
history = requests.get(f"https://freecashe.ws/api/games?team={teamid}&season=2").json()["items"]
|
||||
history = requests.get(f"https://freecashe.ws/api/games?team={teamid}&season=3").json()["items"]
|
||||
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)
|
||||
|
@ -387,7 +407,47 @@ class team(commands.Cog):
|
|||
thanksdiscord = closestteam[:20]
|
||||
await interaction.response.send_autocomplete(thanksdiscord)
|
||||
|
||||
|
||||
@nextcord.slash_command(
|
||||
name="feed",
|
||||
description="Get the latest entry from the team's feed",
|
||||
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 teamfeed(self, interaction: nextcord.Interaction, team: str):
|
||||
if team not in teams_dict:
|
||||
await interaction.response.send_message("Invalid Team!", ephemeral=True)
|
||||
return
|
||||
await interaction.response.defer()
|
||||
teamid = teams_dict[team]
|
||||
async with aiohttp.ClientSession() as session:
|
||||
data = await session.get(f"https://mmolb.com/api/team/{teamid}")
|
||||
data = await data.json()
|
||||
color = tuple(int(data["Color"][i:i+2], 16) for i in (0, 2, 4))
|
||||
embed = nextcord.Embed(title=f"Last ten feed events for the {data["Location"]} {data["Name"]} {data["Emoji"]}", colour = nextcord.Color.from_rgb(color[0], color[1], color[2]))
|
||||
embed.set_footer(text=teamid)
|
||||
data = data['Feed']
|
||||
for index in itertools.islice(data, (len(data)-10 if len(data)-10 > 0 else 0) , len(data)):
|
||||
embed.add_field(name=f"{index['emoji']} Day {index['day']} Season {index['season']}", value=index['text'], inline=False)
|
||||
await interaction.edit_original_message(embed=embed)
|
||||
|
||||
@teamfeed.on_autocomplete("team")
|
||||
async def feedac(self, interaction: nextcord.Interaction, team: str):
|
||||
if not team:
|
||||
print("we're here")
|
||||
thanksdiscord = teams_list[:20]
|
||||
await interaction.response.send_autocomplete(thanksdiscord)
|
||||
return
|
||||
closestteam = [name for name in teams_list if name.lower().startswith(team.lower())]
|
||||
thanksdiscord = closestteam[:20]
|
||||
await interaction.response.send_autocomplete(thanksdiscord)
|
||||
|
||||
@tasks.loop(hours=1)
|
||||
async def updateallteams(self):
|
||||
|
|
Loading…
Reference in a new issue