(timer): Harden channel name updates.
Truncate too-long names. Ignore update if we don't have permission.
This commit is contained in:
@@ -131,7 +131,7 @@ class Timer:
|
|||||||
"""
|
"""
|
||||||
stage = self.current_stage
|
stage = self.current_stage
|
||||||
name_format = self.data.channel_name or "{remaining} {stage} -- {name}"
|
name_format = self.data.channel_name or "{remaining} {stage} -- {name}"
|
||||||
return name_format.replace(
|
name = name_format.replace(
|
||||||
'{remaining}', "{}m".format(
|
'{remaining}', "{}m".format(
|
||||||
int(5 * math.ceil((stage.end - utc_now()).total_seconds() / 300)),
|
int(5 * math.ceil((stage.end - utc_now()).total_seconds() / 300)),
|
||||||
)
|
)
|
||||||
@@ -147,6 +147,7 @@ class Timer:
|
|||||||
int(self.focus_length // 60), int(self.break_length // 60)
|
int(self.focus_length // 60), int(self.break_length // 60)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
return name[:100]
|
||||||
|
|
||||||
async def notify_change_stage(self, old_stage, new_stage):
|
async def notify_change_stage(self, old_stage, new_stage):
|
||||||
# Update channel name
|
# Update channel name
|
||||||
@@ -245,9 +246,15 @@ class Timer:
|
|||||||
if self._voice_update_task:
|
if self._voice_update_task:
|
||||||
self._voice_update_task.cancel()
|
self._voice_update_task.cancel()
|
||||||
|
|
||||||
|
if not self.channel:
|
||||||
|
return
|
||||||
|
|
||||||
if self.channel.name == self.channel_name:
|
if self.channel.name == self.channel_name:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.channel.permissions_for(self.channel.guild.me).manage_channels:
|
||||||
|
return
|
||||||
|
|
||||||
if self._last_voice_update:
|
if self._last_voice_update:
|
||||||
to_wait = ((self._last_voice_update + timedelta(minutes=5)) - utc_now()).total_seconds()
|
to_wait = ((self._last_voice_update + timedelta(minutes=5)) - utc_now()).total_seconds()
|
||||||
if to_wait > 0:
|
if to_wait > 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user