diff options
| author | 2020-04-06 17:32:57 +0200 | |
|---|---|---|
| committer | 2020-04-06 17:32:57 +0200 | |
| commit | ae49def47a2f956b93c814993b8f380b5182c6b7 (patch) | |
| tree | 157dd171df0898d5438e46c5ed1dd76d2569e98a | |
| parent | Add channel status emoji to help channels (diff) | |
Change bottom sorting strategy to using a large int
The current approach of trying to find the maximum channel position, adding one, and using that as the position integer for channels does not seem to work reliably. An approach that seems to work in the testing environment is using a very large integer for the position attribute of the channel: It wil be sorted at the bottom and Discord will automatically scale the integer down to `max + 1`.
This also means the `get_position` utility function is no longer needed; it has been removed.
| -rw-r--r-- | bot/cogs/help_channels.py | 23 |
1 files changed, 2 insertions, 21 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index 4fddba627..60580695c 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -221,25 +221,6 @@ class HelpChannels(Scheduler, commands.Cog): return channel @staticmethod - def get_position(channel: discord.TextChannel, destination: discord.CategoryChannel) -> int: - """Return the position to sort the `channel` at the bottom if moved to `destination`.""" - log.trace(f"Getting bottom position for #{channel} ({channel.id}).") - - if not destination.channels: - # If the destination category is empty, use the first position - position = 1 - else: - # Else use the maximum position int + 1 - position = max(c.position for c in destination.channels) + 1 - - log.trace( - f"Position of #{channel} ({channel.id}) in {destination.name} will be {position} " - f"(was {channel.position})." - ) - - return position - - @staticmethod def get_clean_channel_name(channel: discord.TextChannel) -> str: """Return a clean channel name without status emojis prefix.""" try: @@ -454,7 +435,7 @@ class HelpChannels(Scheduler, commands.Cog): category=self.dormant_category, sync_permissions=True, topic=DORMANT_TOPIC, - position=self.get_position(channel, self.dormant_category), + position=10000, ) log.trace(f"Position of #{channel} ({channel.id}) is actually {channel.position}.") @@ -475,7 +456,7 @@ class HelpChannels(Scheduler, commands.Cog): category=self.in_use_category, sync_permissions=True, topic=IN_USE_TOPIC, - position=self.get_position(channel, self.in_use_category), + position=10000, ) timeout = constants.HelpChannels.idle_minutes * 60 |