fix: cannot subscribe to a team that is not playing

This commit is contained in:
insert 2025-06-09 14:43:45 -04:00
parent eb9ce9be11
commit d5c2597593
Signed by: insert
GPG key ID: A70775C389ACF105
2 changed files with 17 additions and 11 deletions

View file

@ -97,16 +97,22 @@ class liveupdate(commands.Cog):
await interaction.response.send_message("Invalid Team!", ephemeral=True) await interaction.response.send_message("Invalid Team!", ephemeral=True)
await interaction.response.defer() await interaction.response.defer()
teamid = self.bot.teams_dict[team] teamid = self.bot.teams_dict[team]
game = requests.get(f"https://mmolb.com/api/game-by-team/{teamid}").json() try:
gameid = game["game_id"] game = requests.get(f"https://mmolb.com/api/game-by-team/{teamid}").json()
data = requests.get(f"https://mmolb.com/api/game/{gameid}").json() gameid = game["game_id"]
await interaction.edit_original_message(content=f"{data["AwayTeamName"]} {data["AwayTeamEmoji"]} **{data["EventLog"][-1]["away_score"]}** vs {data["HomeTeamName"]} {data["HomeTeamEmoji"]} **{data["EventLog"][-1]["home_score"]}**") data = requests.get(f"https://mmolb.com/api/game/{gameid}").json()
message = await interaction.original_message() await interaction.edit_original_message(content=f"{data["AwayTeamName"]} {data["AwayTeamEmoji"]} **{data["EventLog"][-1]["away_score"]}** vs {data["HomeTeamName"]} {data["HomeTeamEmoji"]} **{data["EventLog"][-1]["home_score"]}**")
if data["State"] != "Complete": message = await interaction.original_message()
await self.bot.db.execute(f""" if data["State"] != "Complete":
INSERT INTO liveupdate VALUES await self.bot.db.execute(f"""
({interaction.guild_id}, {interaction.user.id}, {interaction.channel_id}, {message.id}, "{gameid}", {len(data["EventLog"])}) INSERT INTO liveupdate VALUES
""") ({interaction.guild_id}, {interaction.user.id}, {interaction.channel_id}, {message.id}, "{gameid}", {len(data["EventLog"])})
""")
except Exception as e:
await interaction.edit_original_message(content="This channel is now subscribed to updates")
warning = self.bot.get_channel(1365478368555827270)
await warning.send(e)
print(e)
await self.bot.db.execute(f""" await self.bot.db.execute(f"""
INSERT INTO teamsubscriptions VALUES INSERT INTO teamsubscriptions VALUES
({interaction.guild_id}, {interaction.channel_id}, "{teamid}") ({interaction.guild_id}, {interaction.channel_id}, "{teamid}")

View file

@ -310,7 +310,7 @@ 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()
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)