From 1eddcb686c1d061c08f8e8992ed4f53b750ff116 Mon Sep 17 00:00:00 2001 From: BreadTube Date: Fri, 9 Jan 2026 20:37:43 +0900 Subject: [PATCH] Fix type in request_channel_id url --- breadtube_bot/bot.py | 37 +++++++++++++++++--------------- breadtube_bot/youtube_manager.py | 2 +- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/breadtube_bot/bot.py b/breadtube_bot/bot.py index 253b474..5bb0d88 100644 --- a/breadtube_bot/bot.py +++ b/breadtube_bot/bot.py @@ -148,23 +148,26 @@ class Bot: for message in messages: if message.author.id != self.bot_user.id and message.content.startswith(self.YT_CHANNEL_NAME_URL): - self.logger.debug('Parsing message for youtube channel name conversion: %s', message) - answers: list[str] = [] - for line in message.content.splitlines(): - if line.startswith(self.YT_CHANNEL_NAME_URL): - channel_name = line.rstrip()[len(self.YT_CHANNEL_NAME_URL):] - channel_id = self.yt_manager.request_channel_id( - channel_name, request_timeout=self.config.request_timeout) - answers.append(f'{channel_name} -> {channel_id}') - bot_message = self.discord_manager.create_message(self.bot_channel, { - 'content': '\n'.join(answers), - 'message_reference': MessageReference( - type=MessageReferenceType.DEFAULT, - message_id=message.id, - channel_id=self.bot_channel.id, - guild_id=None, - fail_if_not_exists=None)}, request_timeout=self.config.request_timeout) - delayed_delete[bot_message.id] = bot_message + try: + self.logger.debug('Parsing message for youtube channel name conversion: %s', message) + answers: list[str] = [] + for line in message.content.splitlines(): + if line.startswith(self.YT_CHANNEL_NAME_URL): + channel_name = line.rstrip()[len(self.YT_CHANNEL_NAME_URL):] + channel_id = self.yt_manager.request_channel_id( + channel_name, request_timeout=self.config.request_timeout) + answers.append(f'{channel_name} -> {channel_id}') + bot_message = self.discord_manager.create_message(self.bot_channel, { + 'content': '\n'.join(answers), + 'message_reference': MessageReference( + type=MessageReferenceType.DEFAULT, + message_id=message.id, + channel_id=self.bot_channel.id, + guild_id=None, + fail_if_not_exists=None)}, request_timeout=self.config.request_timeout) + delayed_delete[bot_message.id] = bot_message + except Exception as error: + self.logger.error('Unexpected error while searching channel id from name: %s', error) delayed_delete[message.id] = message continue diff --git a/breadtube_bot/youtube_manager.py b/breadtube_bot/youtube_manager.py index 6fd9259..c02d87f 100644 --- a/breadtube_bot/youtube_manager.py +++ b/breadtube_bot/youtube_manager.py @@ -73,7 +73,7 @@ class YoutubeManager: def request_channel_id(self, channel_name: str, request_timeout: float) -> str: url = ('https://www.googleapis.com/youtube/v3/channels?part=snippet' - f'&forHandle%40={channel_name}&key={self._api_key}') + f'&forHandle=%40{channel_name}&key={self._api_key}') self._logger.debug('YoutubeManager: request channel id for channel %s', channel_name) _, info = self._request(url=url, request_timeout=request_timeout) return info['items'][0]['id']