Special characters handling
* Fix README for python version * Add discord-friendly unidecode function for channel names (avoiding special characted) * Check if "items" is present before accessing in channel id request response
This commit is contained in:
parent
8d76596ebf
commit
d015927861
10 changed files with 315 additions and 13 deletions
|
|
@ -7,8 +7,8 @@ import logging
|
|||
import operator
|
||||
from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import tomllib
|
||||
from typing import Any
|
||||
import traceback
|
||||
|
||||
|
|
@ -37,6 +37,10 @@ class Bot:
|
|||
|
||||
@staticmethod
|
||||
def _get_code_version() -> str:
|
||||
assert sys.version_info.major == 3, f'Only Python version 3 is supported : current is {sys.version_info.major}' # noqa: PLR2004
|
||||
if sys.version_info.minor < 11: # noqa: PLR2004
|
||||
return '0.1.0'
|
||||
import tomllib # noqa: PLC0415
|
||||
pyproject_path = Path(__file__).parents[1] / 'pyproject.toml'
|
||||
if not pyproject_path.exists():
|
||||
raise RuntimeError('Cannot current bot version')
|
||||
|
|
@ -154,9 +158,13 @@ class Bot:
|
|||
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}')
|
||||
try:
|
||||
channel_id = self.yt_manager.request_channel_id(
|
||||
channel_name, request_timeout=self.config.request_timeout)
|
||||
answers.append(
|
||||
f'{channel_name}{self.config.youtube_channel_id_answer_seperator}{channel_id}')
|
||||
except RuntimeError as error:
|
||||
answers.append(f'{channel_name}{self.config.youtube_channel_id_answer_seperator}{error}')
|
||||
bot_message = self.discord_manager.create_message(self.bot_channel, {
|
||||
'content': '\n'.join(answers),
|
||||
'message_reference': MessageReference(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue