fix(statistics): Guard against interaction expiry.
This commit is contained in:
@@ -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,7 +67,8 @@ 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()
|
||||||
await self._original.delete_original_response()
|
if self._original and not self._original.is_expired():
|
||||||
|
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())
|
||||||
await self._original.edit_original_response(**args.edit_args, view=self)
|
if self._original and not self._original.is_expired():
|
||||||
|
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):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user