Keep track of channel deletion

This commit is contained in:
BreadTube 2026-05-27 01:15:15 +09:00
commit 1340e8d49a

View file

@ -141,6 +141,8 @@ class Bot:
self.logger.debug('Deleting duplicated text channels')
channel_names: list[str] = [c.name for c in self.guild_text_channels if c.name is not None]
unique_names: set[str] = set(channel_names)
deleted_channels: set[TextChannel] = set()
try:
for name in unique_names:
occurence = 0
for channel in self.guild_text_channels:
@ -150,6 +152,9 @@ class Bot:
self.logger.debug('Deleting duplicate channel: %d -> %s', channel.id, name)
self.discord_manager.delete_text_channel(
channel.id, request_timeout=self.config.request_timeout)
deleted_channels.add(channel)
finally:
self.guild_text_channels = [c for c in self.guild_text_channels if c not in deleted_channels]
def _get_all_channel_messages(self, channel: TextChannel) -> list[Message]:
messages_id_delete_task: set[int] = set()
@ -223,10 +228,15 @@ class Bot:
def _clean_category(self, category: ChannelCategory):
self.logger.info('Cleaning category "%s" (%d)', category.name, category.id)
for channel in self.guild_categories:
deleted_channels: set[TextChannel] = set()
try:
for channel in self.guild_text_channels:
if channel.parent_id == category.id:
self.logger.debug('Cleaning category -> deleting channel "%s"', channel.name)
self.discord_manager.delete_text_channel(channel.id, request_timeout=self.config.request_timeout)
deleted_channels.add(channel)
finally:
self.guild_text_channels = [c for c in self.guild_text_channels if c not in deleted_channels]
def _parse_command(self, message: Message) -> bool:
match BotCommand(message.content[:100].split(' ')[0]) if message.content else BotCommand.UNKNOWN: