fix(statistics): Guard against interaction expiry.

This commit is contained in:
2023-10-06 10:11:52 +03:00
parent eaa44ab43c
commit c4a9f9abf3
2 changed files with 11 additions and 3 deletions

View File

@@ -41,7 +41,7 @@ class StatsUI(LeoUI):
""" """
ID of guild to render stats for, or None if global. ID of guild to render stats for, or None if global.
""" """
return self.guild.id if not self._showing_global else None return self.guild.id if self.guild and not self._showing_global else None
@property @property
def userid(self) -> int: def userid(self) -> int:
@@ -67,6 +67,7 @@ class StatsUI(LeoUI):
Delete the output message and close the UI. Delete the output message and close the UI.
""" """
await press.response.defer() await press.response.defer()
if self._original and not self._original.is_expired():
await self._original.delete_original_response() await self._original.delete_original_response()
self._original = None self._original = None
await self.close() await self.close()
@@ -93,7 +94,10 @@ class StatsUI(LeoUI):
args = await self.make_message() args = await self.make_message()
if thinking is not None and not thinking.is_expired() and thinking.response.is_done(): if thinking is not None and not thinking.is_expired() and thinking.response.is_done():
asyncio.create_task(thinking.delete_original_response()) asyncio.create_task(thinking.delete_original_response())
if self._original and not self._original.is_expired():
await self._original.edit_original_response(**args.edit_args, view=self) await self._original.edit_original_response(**args.edit_args, view=self)
else:
await self.close()
async def refresh(self, thinking: Optional[discord.Interaction] = None): async def refresh(self, thinking: Optional[discord.Interaction] = None):
""" """

View File

@@ -41,6 +41,7 @@ class StatType(IntEnum):
class LeaderboardUI(StatsUI): class LeaderboardUI(StatsUI):
page_size = 10 page_size = 10
guildid: int
def __init__(self, bot, user, guild, **kwargs): def __init__(self, bot, user, guild, **kwargs):
super().__init__(bot, user, guild, **kwargs) super().__init__(bot, user, guild, **kwargs)
@@ -199,6 +200,9 @@ class LeaderboardUI(StatsUI):
mode = CardMode.TEXT mode = CardMode.TEXT
elif self.stat_type is StatType.ANKI: elif self.stat_type is StatType.ANKI:
mode = CardMode.ANKI mode = CardMode.ANKI
else:
raise ValueError
card = await get_leaderboard_card( card = await get_leaderboard_card(
self.bot, self.userid, self.guildid, self.bot, self.userid, self.guildid,
mode, mode,