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
19
breadtube_bot/unidecode.py
Normal file
19
breadtube_bot/unidecode.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import re
|
||||
|
||||
from breadtube_bot.unidecode_data import UNIDECODE_DICT
|
||||
|
||||
|
||||
DISCORD_PATTERN = re.compile(r'[^a-zA-Z0-9\-_]')
|
||||
|
||||
|
||||
def unidecode(text: str) -> str:
|
||||
result: list[str] = []
|
||||
for char in text:
|
||||
codepoint: int = ord(char)
|
||||
if codepoint < 0x80: # noqa: PLR2004
|
||||
result.append(DISCORD_PATTERN.sub('_', char).lower())
|
||||
elif codepoint >> 8 in UNIDECODE_DICT:
|
||||
result.append(UNIDECODE_DICT[codepoint >> 8][codepoint % 256])
|
||||
else:
|
||||
result.append('_')
|
||||
return ''.join(result)
|
||||
Loading…
Add table
Add a link
Reference in a new issue