Fix discord channel name sanitization

This commit is contained in:
BreadTube 2026-05-25 00:11:13 +09:00
commit a30ed6c85c

View file

@ -24,7 +24,6 @@ from .youtube_subscription import (
class Bot: class Bot:
DEFAULT_MESSAGE_LIST_LIMIT: int = 50 DEFAULT_MESSAGE_LIST_LIMIT: int = 50
DISCORD_NAME_REGEX: str = r'([^a-z])'
INIT_MESSAGE: str = ('Bot initialized.\nThis is the current configuration used.\n' INIT_MESSAGE: str = ('Bot initialized.\nThis is the current configuration used.\n'
'You can upload a new one to update the configuration.') 'You can upload a new one to update the configuration.')
MAX_DOWNLOAD_SIZE: int = 50_000 MAX_DOWNLOAD_SIZE: int = 50_000
@ -356,9 +355,8 @@ class Bot:
def _get_subscription_channel(self, subscription: SubscriptionInfo, channel_dict: dict[str, TextChannel], def _get_subscription_channel(self, subscription: SubscriptionInfo, channel_dict: dict[str, TextChannel],
category_ranges: list[tuple[int, int, ChannelCategory]]) -> TextChannel: category_ranges: list[tuple[int, int, ChannelCategory]]) -> TextChannel:
discord_name = re.sub(self.DISCORD_NAME_REGEX, '-', subscription.name.lower()) category_value = ord(subscription.name[0])
category_value = ord(discord_name[0]) sub_channel: TextChannel | None = channel_dict.get(subscription.name)
sub_channel: TextChannel | None = channel_dict.get(discord_name)
if sub_channel is None: if sub_channel is None:
selected_category: ChannelCategory | None = None selected_category: ChannelCategory | None = None
for start_range, stop_range, category in category_ranges: for start_range, stop_range, category in category_ranges:
@ -369,7 +367,7 @@ class Bot:
selected_category = category_ranges[-1][2] selected_category = category_ranges[-1][2]
sub_channel = self.discord_manager.create_text_channel( sub_channel = self.discord_manager.create_text_channel(
self.guild_id, { self.guild_id, {
'name': discord_name, 'name': subscription.name,
'parent_id': selected_category.id, 'parent_id': selected_category.id,
'permission_overwrites': [ 'permission_overwrites': [
Overwrite(self.everyone_role.id, OverwriteType.ROLE, allow=Permissions.NONE, Overwrite(self.everyone_role.id, OverwriteType.ROLE, allow=Permissions.NONE,