fix(timers): Handle corner cases.
Handle cases where discord objects are deleted while timer is running.
This commit is contained in:
@@ -38,6 +38,7 @@ class TimerOptions(SettingGroup):
|
|||||||
|
|
||||||
_model = TimerData.Timer
|
_model = TimerData.Timer
|
||||||
_column = TimerData.Timer.channelid.name
|
_column = TimerData.Timer.channelid.name
|
||||||
|
_allow_object = False
|
||||||
|
|
||||||
@TimerConfig.register_model_setting
|
@TimerConfig.register_model_setting
|
||||||
class NotificationChannel(ModelData, ChannelSetting):
|
class NotificationChannel(ModelData, ChannelSetting):
|
||||||
@@ -51,6 +52,7 @@ class TimerOptions(SettingGroup):
|
|||||||
|
|
||||||
_model = TimerData.Timer
|
_model = TimerData.Timer
|
||||||
_column = TimerData.Timer.notification_channelid.name
|
_column = TimerData.Timer.notification_channelid.name
|
||||||
|
_allow_object = False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def _check_value(cls, parent_id: int, value: Optional[discord.abc.GuildChannel], **kwargs):
|
async def _check_value(cls, parent_id: int, value: Optional[discord.abc.GuildChannel], **kwargs):
|
||||||
@@ -120,6 +122,7 @@ class TimerOptions(SettingGroup):
|
|||||||
|
|
||||||
_model = TimerData.Timer
|
_model = TimerData.Timer
|
||||||
_column = TimerData.Timer.manager_roleid.name
|
_column = TimerData.Timer.manager_roleid.name
|
||||||
|
_allow_object = False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _format_data(cls, parent_id, data, timer=None, **kwargs):
|
def _format_data(cls, parent_id, data, timer=None, **kwargs):
|
||||||
|
|||||||
@@ -406,7 +406,7 @@ class Timer:
|
|||||||
"Remember to press {tick} to register your presence every stage.",
|
"Remember to press {tick} to register your presence every stage.",
|
||||||
len(needs_kick)
|
len(needs_kick)
|
||||||
), locale=self.locale.value).format(
|
), locale=self.locale.value).format(
|
||||||
channel=self.channel.mention,
|
channel=f"<#{self.data.channelid}>",
|
||||||
mentions=', '.join(member.mention for member in needs_kick),
|
mentions=', '.join(member.mention for member in needs_kick),
|
||||||
tick=self.bot.config.emojis.tick
|
tick=self.bot.config.emojis.tick
|
||||||
)
|
)
|
||||||
@@ -439,7 +439,7 @@ class Timer:
|
|||||||
if not stage:
|
if not stage:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self.channel.permissions_for(self.guild.me).speak:
|
if not self.channel or not self.channel.permissions_for(self.guild.me).speak:
|
||||||
return
|
return
|
||||||
|
|
||||||
async with self.lguild.voice_lock:
|
async with self.lguild.voice_lock:
|
||||||
@@ -501,7 +501,7 @@ class Timer:
|
|||||||
"{channel} is now on **BREAK**! Take a rest, **FOCUS** starts {timestamp}"
|
"{channel} is now on **BREAK**! Take a rest, **FOCUS** starts {timestamp}"
|
||||||
)
|
)
|
||||||
stageline = t(lazy_stageline).format(
|
stageline = t(lazy_stageline).format(
|
||||||
channel=self.channel.mention,
|
channel=f"<#{self.data.channelid}>",
|
||||||
timestamp=f"<t:{int(stage.end.timestamp())}:R>"
|
timestamp=f"<t:{int(stage.end.timestamp())}:R>"
|
||||||
)
|
)
|
||||||
return stageline
|
return stageline
|
||||||
@@ -550,12 +550,12 @@ class Timer:
|
|||||||
content = t(_p(
|
content = t(_p(
|
||||||
'timer|status|stopped:auto',
|
'timer|status|stopped:auto',
|
||||||
"Timer stopped! Join {channel} to start the timer."
|
"Timer stopped! Join {channel} to start the timer."
|
||||||
)).format(channel=self.channel.mention)
|
)).format(channel=f"<#{self.data.channelid}>")
|
||||||
else:
|
else:
|
||||||
content = t(_p(
|
content = t(_p(
|
||||||
'timer|status|stopped:manual',
|
'timer|status|stopped:manual',
|
||||||
"Timer stopped! Press `Start` to restart the timer."
|
"Timer stopped! Press `Start` to restart the timer."
|
||||||
)).format(channel=self.channel.mention)
|
)).format(channel=f"<#{self.data.channelid}>")
|
||||||
|
|
||||||
card = await get_timer_card(self.bot, self, stage)
|
card = await get_timer_card(self.bot, self, stage)
|
||||||
await card.render()
|
await card.render()
|
||||||
|
|||||||
Reference in New Issue
Block a user