async def get_printed_input( config: Config, msg: str, *, images: bool, ) -> Optional[Tuple[str, str]]: msg_match = MSG_RE.match(msg) if msg_match: info = parse_badge_info(msg_match['info']) if info['color']: r, g, b = _parse_color(info['color']) else: r, g, b = _gen_color(info['display-name']) color_start = f'\033[1m\033[38;2;{r};{g};{b}m' msg_s = msg_match['msg'] is_action = msg_s.startswith('\x01ACTION ') if is_action: msg_s = msg_s[8:-1] badges_s = badges_plain_text(info['badges']) if images: badges = parse_badges(info['badges']) await download_all_badges( badges, channel=config.channel, oauth_token=config.oauth_token_token, client_id=config.client_id, ) badges_s_images = badges_images(badges) else: badges_s_images = badges_s if images: emote_info = parse_emote_info(info['emotes']) await download_all_emotes(emote_info) msg_s_images = replace_emotes(msg_s, emote_info) else: msg_s_images = msg_s if is_action: fmt = (f'{dt_str()}' f'{{badges}}' f'{color_start}\033[3m * {info["display-name"]}\033[22m ' f'{{msg}}\033[m') elif info.get('msg-id') == 'highlighted-message': fmt = (f'{dt_str()}' f'{{badges}}' f'<{color_start}{info["display-name"]}\033[m> ' f'\033[48;2;117;094;188m{{msg}}\033[m') elif 'custom-reward-id' in info: fmt = (f'{dt_str()}' f'{{badges}}' f'<{color_start}{info["display-name"]}\033[m> ' f'\033[48;2;029;091;130m{{msg}}\033[m') else: fmt = (f'{dt_str()}' f'{{badges}}' f'<{color_start}{info["display-name"]}\033[m> ' f'{{msg}}') to_print = fmt.format(badges=badges_s_images, msg=msg_s_images) to_log = fmt.format(badges=badges_s, msg=msg_s) return to_print, to_log return None
def test_parse_emote_info(s, expected): assert parse_emote_info(s) == expected