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)