async def show_user_info(message: types.Message): user: User = await register(message) return await message.answer(md.text( md.text('Information about ' + message.from_user.first_name + ' ' + str(message.from_user.last_name)), md.text('🔸', md.hbold('Your ID:'), md.hcode(message.from_user.id)), md.text('🔸', md.hbold('First name:'), md.hcode(message.from_user.first_name)), md.text('🔸', md.hbold('Second name:'), md.hcode(message.from_user.last_name or 'Unknown')), md.text('🔸', md.hbold('Username:'******'Unknown')), md.text('🔸', md.hbold('Phone number:'), md.hcode(user.phone_number)) if user else "", sep='\n', ), reply_markup=types.ReplyKeyboardRemove())
def format_post(post_id: str, post: dict) -> (str, types.InlineKeyboardMarkup): text = md.text( md.hbold(post['title']), md.quote_html(post['body']) ) markup = types.InlineKeyboardMarkup() markup.add(types.InlineKeyboardButton('Geri', callback_data=posts_cb.new(id='-', action='list'))) return text, markup
async def show_menu(message: types.Message, user: User): await message.answer(text=md.text( md.text('Information about ' + message.from_user.first_name + ' ' + str(message.from_user.last_name)), md.text('🔸', md.hbold('Your ID:'), md.hcode(user.user_id)), md.text('🔸', md.hbold('First name:'), md.hcode(user.first_name)), md.text('🔸', md.hbold('Second name:'), md.hcode(user.last_name or 'Unknown')), md.text('🔸', md.hbold('Username:'******'Unknown')), md.text('🔸', md.hbold('Phone number:'), md.hcode(user.phone_number)), sep='\n', ), reply_markup=types.ReplyKeyboardRemove()) text, keyboard = await fuser.send_menu_msg(message) return await message.answer(text=text, reply_markup=keyboard)
async def notify_superusers(chats: Union[List[int], List[str], int, str]): # Generate chats chats = [ { "chat_id": chat_id, "mention": md.hlink(title=f"ID:{chat_id}", url=f"tg://user?id={chat_id}"), } for chat_id in chats ] # Run broadcaster await TextBroadcaster( chats=chats, text=md.hbold("$mention, The bot is running!"), ).run()
def format_post(post_id: str, post: dict) -> (str, types.InlineKeyboardMarkup): text = md.text( md.hbold(post['title']), md.quote_html(post['body']), '', # just new empty line f"Votes: {post['votes']}", sep='\n', ) markup = types.InlineKeyboardMarkup() markup.row( types.InlineKeyboardButton('👍', callback_data=posts_cb.new(id=post_id, action='like')), types.InlineKeyboardButton('👎', callback_data=posts_cb.new(id=post_id, action='dislike')), ) markup.add(types.InlineKeyboardButton('<< Back', callback_data=posts_cb.new(id='-', action='list'))) return text, markup
async def links(msg: types.Message, state: FSMContext, locale): urls = extractor.find_urls(msg.text) # Return if message not contain urls if not urls: if msg.chat.type == types.chat.ChatType.PRIVATE: await msg.answer( _('No links to music services were found in the message\\.')) return if not msg.chat.type == types.chat.ChatType.PRIVATE and not is_supported_link( urls[0]): return # Send bot `typing...` await bot.send_chat_action(chat_id=msg.chat.id, action=types.ChatActions.TYPING) # Get user data from state user_data = await state.get_data() # Set layout if it not defined early if user_data.get(LINKS_LAYOUT_NAME) is None: async with state.proxy() as data: data[LINKS_LAYOUT_NAME] = LinksLayout.COMBINED.value for url in urls: new_url = url shazam = Shazam(url) if shazam.is_shazam_url(): new_url = await shazam.find_links() message: List[str] = [] try: linksdata = await odesli.links(url=new_url) except Exception as e: print(e) await msg.answer( _('Unfortunately, we have no data for this link 😥\.')) return entity = linksdata.entitiesByUniqueId[linksdata.entityUniqueId] def links_by_platform(platform: Platform) -> Optional[str]: return getattr(linksdata.linksByPlatform.get(platform), 'url', None) message.append( md.hlink( f"{entity.artistName} - {entity.title}\n", get_streaming_hell_link(id=entity.id, type=entity.type, platform=entity.platforms[0]))) # Compose message text for `SEPARATE` layout if user_data.get(LINKS_LAYOUT_NAME) == LinksLayout.SEPARATE.value: listen_links: list[str] = [] buy_links: list[str] = [] for key, value in platforms.items(): if links_by_platform(key) and value['isStore'] is False: listen_links.append( md.hlink(value['name'], links_by_platform(key))) elif links_by_platform(key) and value['isStore'] is True: buy_links.append( md.hlink(value['name'], links_by_platform(key))) if listen_links: message.append(md.hbold(_('🎧 Listen'))) message.extend(listen_links) message.append( md.hlink( 'VK', get_vk_search_link( f"{entity.artistName} - {entity.title}"))) if buy_links: message.append(md.hbold(_('\n🛍 Buy'))) message.extend(buy_links) # Compose message text for `COMBINED` layout if user_data.get(LINKS_LAYOUT_NAME) == LinksLayout.COMBINED.value: for key, value in platforms.items(): if links_by_platform(key): message.append( md.hlink(value['name'], links_by_platform(key))) message.append( md.hlink( 'VK', get_vk_search_link( f"{entity.artistName} - {entity.title}"))) # Compose message text for `MINIMAL` layout if user_data.get(LINKS_LAYOUT_NAME) == LinksLayout.MINIMAL.value: for key, value in platforms.items(): if links_by_platform(key): message.append( md.hlink(value['name'], links_by_platform(key))) message.append(md.text(' | ')) message.append( md.hlink( 'VK', get_vk_search_link( f"{entity.artistName} - {entity.title}"))) caption = md.text(*message, sep='\n') if user_data.get(LINKS_LAYOUT_NAME) == LinksLayout.MINIMAL.value: caption = md.text(*message, sep='') # Delete user message that contains streaming link bot_member = await bot.get_chat_member(chat_id=msg.chat.id, user_id=bot.id) if msg.chat.type == types.ChatType.PRIVATE: await bot.delete_message(chat_id=msg.chat.id, message_id=msg.message_id) elif bot_member.can_delete_messages: await bot.delete_message(chat_id=msg.chat.id, message_id=msg.message_id) # Send found streaming links await msg.answer_photo(photo=entity.thumbnailUrl, caption=caption, parse_mode=types.ParseMode.HTML)