def _build_message(saved_links_response: {}): if not saved_links_response: return 'You have not saved links' msg = '<strong>Saved links:</strong> \n' for saved_link in saved_links_response: link = saved_link.get('link') genres = Link.get_genres(link) msg += f'- {emojis.get_music_emoji(link.get("link_type"))} <a href="{link.get("url")}">{Link.get_name(link)}</a> ' \ f'({", ".join(genres) if genres else ""}). ' \ f'Saved at: {datetime.datetime.fromisoformat(saved_link.get("saved_at")).strftime(OUTPUT_DATE_FORMAT)}\n' return msg
def _build_message(last_week_links): msg = '<strong>Music from the last week:</strong> \n' for user, sent_links in last_week_links.items(): msg += '- {} <strong>{}:</strong>\n'.format(emojis.EMOJI_USER, user) for sent_link in sent_links: link = sent_link.get('link') genres = Link.get_genres(link) msg += ' {} <a href="{}">{}</a> {}\n'.format( emojis.get_music_emoji(link.get('link_type')), link.get('url'), Link.get_name(link), '({})'.format(', '.join(genres)) if genres else '' ) msg += '\n' return msg
def _build_message(all_time_links): msg = '<strong>Music from the beginning of time:</strong> \n' for user, sent_links in all_time_links.items(): msg += '- {} <strong>{}:</strong>\n'.format(emojis.EMOJI_USER, user) for sent_link in sent_links: link = sent_link.get('link') genres = Link.get_genres(link) msg += ' {} <a href="{}">{}</a> {}\n'.format( emojis.get_music_emoji(link.get('link_type')), f'[{datetime.datetime.fromisoformat(sent_link.get("sent_at")).strftime(OUTPUT_DATE_FORMAT)}]', link.get('url'), Link.get_name(link), '({})'.format(', '.join(genres)) if genres else '' ) msg += '\n' return msg
def _build_message(self, sent_link: OrderedDict): from bot.commands import NowPlayingCommand msg = '<strong>Saved: </strong>' link = sent_link.get('link') genres = ', '.join(Link.get_genres(link)) if link.get('link_type') == LinkType.ARTIST.value: msg += '{} <strong>{}</strong>\n'.format( emojis.EMOJI_ARTIST, link.get('artist').get('name')) elif link.get('link_type') == LinkType.ALBUM.value: msg += '{} <strong>{}</strong> - <strong>{}</strong>\n'.format( emojis.EMOJI_ALBUM, link.get('album').get('artists')[0].get('name'), link.get('album').get('name')) elif link.get('link_type') == LinkType.TRACK.value: msg += '{} {} by <strong>{}</strong>\n'.format( emojis.EMOJI_TRACK, link.get('track').get('name'), link.get('track').get('artists')[0].get('name'), ) # Only show the link if the processed url comes from a /np command if isinstance(self.command, NowPlayingCommand): msg += f'{link.get("url")} \n' msg += '<strong>Genres:</strong> {}'.format( genres if genres else 'N/A') save_link_button_keyboard_markup = SaveLinkButton.get_keyboard_markup( link.get('id')) preview_track = sent_link.get('spotify_preview_track', None) if preview_track and preview_track.get('preview_url'): performer = preview_track.get('artists')[0].get('name', 'unknown') title = preview_track.get('name', 'unknown') self.reply(update=self.update, context=self.context, message=msg, reply_type=ReplyType.AUDIO, audio=preview_track.get('preview_url'), title=title, performer=performer, reply_markup=save_link_button_keyboard_markup) else: self.reply(self.update, self.context, msg, reply_markup=save_link_button_keyboard_markup)
def _build_message(all_time_links): msg = '<strong>Music sent in all your chats from the beginning of time:</strong> \n' for sent_link in all_time_links: link = sent_link.get('link') genres = Link.get_genres(link) msg += ' {} {} <a href="{}">{}</a> {}\n'.format( emojis.get_music_emoji(link.get('type')), '[{}@{}]'.format( datetime.datetime.fromisoformat(sent_link.get('sent_at')).strftime(OUTPUT_DATE_FORMAT), sent_link.get('chat').get('name') ), link.get('url'), Link.get_name(link), '({})'.format(', '.join(genres)) if genres else '' ) msg += '\n' return msg