From a6283c9bc6c0318d25948c75c0174a02bbe4fd93 Mon Sep 17 00:00:00 2001 From: Conatum Date: Mon, 24 Jan 2022 08:20:22 +0200 Subject: [PATCH] (timer): Harden channel name updates. Truncate too-long names. Ignore update if we don't have permission. --- bot/modules/study/timers/Timer.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bot/modules/study/timers/Timer.py b/bot/modules/study/timers/Timer.py index 88a15f4f..df603aaa 100644 --- a/bot/modules/study/timers/Timer.py +++ b/bot/modules/study/timers/Timer.py @@ -131,7 +131,7 @@ class Timer: """ stage = self.current_stage name_format = self.data.channel_name or "{remaining} {stage} -- {name}" - return name_format.replace( + name = name_format.replace( '{remaining}', "{}m".format( 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) ) ) + return name[:100] async def notify_change_stage(self, old_stage, new_stage): # Update channel name @@ -245,9 +246,15 @@ class Timer: if self._voice_update_task: self._voice_update_task.cancel() + if not self.channel: + return + if self.channel.name == self.channel_name: return + if not self.channel.permissions_for(self.channel.guild.me).manage_channels: + return + if self._last_voice_update: to_wait = ((self._last_voice_update + timedelta(minutes=5)) - utc_now()).total_seconds() if to_wait > 0: