def export(update, context): run_async = context.dispatcher.run_async user = User.validate_user(update.effective_user) message = update.callback_query.message podcasts = Podcast.objects(subscribers__in=[user]) if not podcasts: run_async(message.reply_text, '还没有订阅播客,请先订阅后导出~') return subscribed_podcasts = Podcast.subscribe_by(user) run_async(message.reply_document, filename=f"castpod-{date.today()}.xml", document=generate_opml(user, subscribed_podcasts))
def manage(update, context): run_async = context.dispatcher.run_async user = User.validate_user(update.effective_user) page = ManagePage(Podcast.subscribe_by(user, 'name')) msg = run_async( update.effective_message.reply_text, text=page.text, reply_markup=ReplyKeyboardMarkup( page.keyboard(), resize_keyboard=True, one_time_keyboard=True, selective=True) ).result() delete_manage_starter(context) save_manage_starter(context.chat_data, msg)
def star(update, context): run_async = context.dispatcher.run_async user = User.validate_user(update.effective_user) page = ManagePage(Podcast.star_by(user, 'name'), text='已启动收藏面板') msg = run_async( update.message.reply_text, text=page.text, reply_markup=ReplyKeyboardMarkup( page.keyboard(null_text='还没有收藏播客~', jump_to=DOC_MARK), resize_keyboard=True, one_time_keyboard=True, selective=True) ).result() delete_manage_starter(context) save_manage_starter(context.chat_data, msg)
def export_before_logout(update, context): run_async = context.dispatcher.run_async user = User.validate_user(update.effective_user) message = update.callback_query.message podcasts = Podcast.objects(subscribers__in=[user]) if not podcasts: run_async(message.reply_text, '还没有订阅播客,请先订阅后导出~') return subscribed_podcasts = Podcast.subscribe_by(user) run_async(message.reply_document, filename=f"castpod-{date.today()}.xml", document=generate_opml(user, subscribed_podcasts), reply_markup=InlineKeyboardMarkup.from_column([ InlineKeyboardButton("继续注销账号", callback_data="confirm_delete_account"), InlineKeyboardButton("返回帮助界面", callback_data="back_to_help") ])) message.delete()
def delete_account(update, context): run_async = context.dispatcher.run_async bot = context.bot message = update.callback_query.message user = User.validate_user(update.effective_user) if message.text: deleting_note = run_async(message.edit_text, "注销中…").result() user.delete() run_async(deleting_note.delete) run_async(bot.send_message, chat_id=user.user_id, text='账号已注销,感谢您这段时间的使用!', reply_markup=InlineKeyboardMarkup.from_button( InlineKeyboardButton( '重新开始', url=f"https://t.me/{manifest.bot_id}?start=login"))) else: user.delete() run_async(delete_manage_starter, context) context.chat_data.clear() context.user_data.clear()
def favorite(update, context): user = User.validate_user(update.effective_user) fav_episodes = Episode.objects(starrers=user) if len(fav_episodes) == 1: update.message.reply_audio( audio=fav_episodes.first().file_id ) elif len(fav_episodes) >= 2 and len(fav_episodes) <= 5: update.message.reply_media_group( media=list(map(lambda episode: InputMediaAudio( media=episode.file_id ), fav_episodes)) ) elif len(fav_episodes) > 5: #!!! update.message.reply_media_group( media=list(map(lambda x: InputMediaAudio(x.file_id), fav_episodes)) ) else: update.message.reply_text( text='还没有收藏的单集~', reply_markup=InlineKeyboardMarkup.from_button( InlineKeyboardButton('订阅列表', switch_inline_query_current_chat='')) )
def start(update, context): run_async = context.dispatcher.run_async message = update.message if User.objects(user_id=update.effective_user.id): message.reply_text('您已经注册过啦,无需接受邀请 :)') return user = User.validate_user(update.effective_user) if context.args and context.args[0] != 'login': match = re.match(r'^(u|p)([0-9]*)$', context.args[0]) id_type, id_value = match[1], int(match[2]) if id_type == 'u': # 由其他用户推荐登入u from_user = User.objects.get(user_id=id_value).only('bonus') from_user.update(inc__bonus=10) text = ( f'您已接受 {from_user.first_name} 的邀请,欢迎使用 {manifest.name}! ' f'\n\n发送 OPML 文件或者 RSS 链接均可以导入播客订阅。\n' f'\n⚠️ 目前还*没有正式上线*,主要的问题是订阅的播客不能获取更新。遇到问题或提供建议请移步[内测聊天室](https://t.me/castpodchat)。' ) run_async( message.reply_text, text=text, reply_markup=InlineKeyboardMarkup.from_button( InlineKeyboardButton( '搜索播客', switch_inline_query_current_chat="" ) ) ) return elif id_type == 'p': # 订阅播客 podcast = Podcast.objects(id=id_value).first() if not podcast: update.reply_message( f'抱歉,该播客不存在。如需订阅,请尝试在对话框输入 `@{manifest.bot_id} 播客关键词` 检索。') return if not user in podcast.subscribers: subscribing_note = run_async( update.message.reply_text, "正在订阅…").result() user.subscribe(podcast) run_async(subscribing_note.delete) page = PodcastPage(podcast) manage_page = ManagePage( Podcast.subscribe_by(user), f'`{podcast.name}` 订阅成功!' ) photo = podcast.logo.file_id or podcast.logo.url msg = run_async(message.reply_photo, photo=photo, caption=page.text(), reply_markup=InlineKeyboardMarkup(page.keyboard()), parse_mode="HTML" ).result() podcast.logo.file_id = msg.photo[0].file_id podcast.save() run_async( update.message.reply_text, text=manage_page.text, reply_markup=ReplyKeyboardMarkup(manage_page.keyboard()) ) else: welcome_text = ( f'欢迎使用 {manifest.name}! ' f'\n\n发送 OPML 文件或者 RSS 链接均可以导入播客订阅。\n' f'\n⚠️ 目前还*没有正式上线*,主要的问题是订阅的播客还不能更新。遇到问题或提供建议请移步[内测聊天室](https://t.me/castpodchat)。' ) run_async( message.reply_text, text=welcome_text, reply_markup=InlineKeyboardMarkup.from_button( InlineKeyboardButton( '搜索播客', switch_inline_query_current_chat="" ) ) )