def format_emoji(text: str, server: discord.Server):
""" Creates a list supporting both emoji and custom emotes. """
char_and_emotes = []
# Loop through each character and compare with custom emotes.
# Add characters to list, along with emote byte-strings
text_iter = iter(enumerate(text))
has_custom = False
for i, c in text_iter:
match = emote_regex.match(text[i:])
if match:
char_and_emotes.append(await get_emote(match.group("id"), server))
has_custom = True
# Skip ahead in the iterator
for _ in range(len(match.group(0)) - 1):
next(text_iter)
else:
char_and_emotes.append(c)
parsed_emoji = list(parse_emoji(char_and_emotes))
# When the size of all emoji next to each other is greater than the max width,
# divide the size to properly fit the max_width at all times
size = default_size
if has_custom:
size = emote_size
else:
if size * len(parsed_emoji) > max_width:
scale = 1 / ((size * len(parsed_emoji) - 1) // max_width + 1)
size *= scale
# Return the list of emoji, and set the respective size (should be managed manually if needed)
return [e if isinstance(e, Image.Image) else get_emoji(e, size=size) for e in parsed_emoji], has_custom
评论列表
文章目录