def reply_router(bot, update, chat_data): text = update.effective_message.reply_to_message.text if text == messages.ADD_FAVORITE: query = update.message.text favorites.add_favorite_handler(bot, update, query) elif text == messages.SEARCH_MESSAGE: query = update.message.text search_query(bot, update, chat_data, query) # BOTPROPERTIES bot_properties = ["description", "extra", "name", "username"] try: partition = text.partition(messages.BOTPROPERTY_STARTSWITH) except AttributeError: return if partition[1] != "": bot_property = next(p for p in bot_properties if partition[2].startswith(p)) # Reply for setting a bot property botproperties.set_text_property(bot, update, chat_data, bot_property) print("raising...") print(partition) print(partition[1]) raise DispatcherHandlerStop elif text == messages.BAN_MESSAGE: query = update.message.text admin.ban_handler(bot, update, query, chat_data, True) elif text == messages.UNBAN_MESSAGE: query = update.message.text admin.ban_handler(bot, update, query, chat_data, False)
def reply_router(bot, update, chat_data): text = update.message.reply_to_message.text if text == messages.ADD_FAVORITE: query = update.message.text favorites.add_favorite_handler(bot, update, query) elif text == messages.SEARCH_MESSAGE: query = update.message.text search_query(bot, update, chat_data, query) # BOTPROPERTIES bot_properties = ['description', 'extra', 'name', 'username'] try: partition = text.partition(messages.BOTPROPERTY_STARTSWITH) except AttributeError as e: return # raise DispatcherHandlerStop # TODO if partition[1] != '': bot_property = next(p for p in bot_properties if partition[2].startswith(p)) # Reply for setting a bot property botproperties.set_text_property(bot, update, chat_data, bot_property) return # raise DispatcherHandlerStop # TODO elif text == messages.BAN_MESSAGE: query = update.message.text admin.ban_handler(bot, update, query, True) elif text == messages.UNBAN_MESSAGE: query = update.message.text admin.ban_handler(bot, update, query, False)
def register(dp): keywords_handler = ConversationHandler( entry_points=[ InlineCallbackHandler( CallbackActions.EDIT_BOT_KEYWORDS, botproperties.set_keywords_init, serialize=lambda data: dict(to_edit=Bot.get(id=data['id'])), pass_chat_data=True) ], states={ BotStates.SENDING_KEYWORDS: [ MessageHandler(Filters.text, botproperties.add_keyword, pass_chat_data=True), InlineCallbackHandler( CallbackActions.REMOVE_KEYWORD, botproperties.remove_keyword, serialize=lambda data: dict(to_edit=Bot.get(id=data['id']), keyword=Keyword.get(id=data[ 'kwid'])), pass_chat_data=True) ], }, fallbacks=[ CallbackQueryHandler(callback_router, pass_chat_data=True, pass_user_data=True, pass_job_queue=True) ], per_user=True, allow_reentry=False) dp.add_handler(keywords_handler) broadcasting_handler = ConversationHandler( entry_points=[ InlineCallbackHandler('broadcast', broadcasts.broadcast, pass_user_data=True), CommandHandler("broadcast", broadcasts.broadcast, pass_user_data=True), CommandHandler("bc", broadcasts.broadcast, pass_user_data=True) ], states={ BotStates.BROADCASTING: [ MessageHandler(Filters.text, broadcasts.broadcast_preview, pass_user_data=True), ], }, fallbacks=[], per_user=True, per_chat=False, allow_reentry=True) dp.add_handler(broadcasting_handler) dp.add_handler( CallbackQueryHandler(callback_router, pass_chat_data=True, pass_user_data=True, pass_job_queue=True)) dp.add_handler( CommandHandler(('cat', 'category', 'categories'), select_category, pass_chat_data=True)) dp.add_handler( CommandHandler(('s', 'search'), search_handler, pass_args=True, pass_chat_data=True)) dp.add_handler(MessageHandler(Filters.reply, reply_router, pass_chat_data=True), group=0) dp.add_handler( MessageHandler(Filters.forwarded, forward_router, pass_chat_data=True)) dp.add_handler(CommandHandler("admin", admin.menu)) dp.add_handler(CommandHandler("a", admin.menu)) # admin menu dp.add_handler( RegexHandler(captions.APPROVE_BOTS + '.*', admin.approve_bots)) dp.add_handler( RegexHandler(captions.APPROVE_SUGGESTIONS + '.*', admin.approve_suggestions)) dp.add_handler( RegexHandler(captions.PENDING_UPDATE + '.*', admin.pending_update)) dp.add_handler( RegexHandler(captions.SEND_BOTLIST, admin.prepare_transmission, pass_chat_data=True)) dp.add_handler(RegexHandler(captions.FIND_OFFLINE, admin.send_offline)) dp.add_handler( RegexHandler(captions.SEND_CONFIG_FILES, admin.send_runtime_files)) dp.add_handler( RegexHandler(captions.SEND_ACTIVITY_LOGS, admin.send_activity_logs)) # main menu dp.add_handler(RegexHandler(captions.ADMIN_MENU, admin.menu)) dp.add_handler(RegexHandler(captions.REFRESH, admin.menu)) dp.add_handler( RegexHandler(captions.CATEGORIES, select_category, pass_chat_data=True)) dp.add_handler( RegexHandler(captions.EXPLORE, explore.explore, pass_chat_data=True)) dp.add_handler( RegexHandler(captions.FAVORITES, favorites.send_favorites_list)) dp.add_handler( RegexHandler(captions.NEW_BOTS, show_new_bots, pass_chat_data=True)) dp.add_handler( RegexHandler(captions.SEARCH, search_handler, pass_chat_data=True)) dp.add_handler(RegexHandler(captions.CONTRIBUTING, help.contributing)) dp.add_handler(RegexHandler(captions.EXAMPLES, help.examples)) dp.add_handler(RegexHandler(captions.HELP, help.help)) dp.add_handler(RegexHandler("^/edit\d+$", admin.edit_bot, pass_chat_data=True), group=1) dp.add_handler(CommandHandler('reject', admin.reject_bot_submission)) dp.add_handler(CommandHandler('rej', admin.reject_bot_submission)) dp.add_handler(RegexHandler("^/approve\d+$", admin.edit_bot, pass_chat_data=True), group=1) dp.add_handler(CommandHandler('approve', admin.short_approve_list)) dp.add_handler(CommandHandler(('manybot', 'manybots'), admin.manybots)) dp.add_handler( CommandHandler('new', contributions.new_bot_submission, pass_args=True, pass_chat_data=True)) dp.add_handler(RegexHandler('.*#new.*', contributions.new_bot_submission, pass_chat_data=True), group=1) dp.add_handler( CommandHandler('offline', contributions.notify_bot_offline, pass_args=True)) dp.add_handler(RegexHandler('.*#offline.*', contributions.notify_bot_offline), group=1) dp.add_handler( CommandHandler('spam', contributions.notify_bot_spam, pass_args=True)) dp.add_handler(RegexHandler('.*#spam.*', contributions.notify_bot_spam), group=1) dp.add_handler( RegexHandler('^{}$'.format(settings.REGEX_BOT_ONLY), send_bot_details, pass_chat_data=True)) dp.add_handler(CommandHandler('help', help.help)) dp.add_handler( CommandHandler(("contribute", "contributing"), help.contributing)) dp.add_handler(CommandHandler("examples", help.examples)) dp.add_handler(CommandHandler("rules", help.rules)) dp.add_handler( CommandHandler(("addfav", "addfavorite"), favorites.add_favorite_handler, pass_args=True)) dp.add_handler( CommandHandler(("f", "fav", "favorites"), favorites.send_favorites_list)) dp.add_handler( CommandHandler(("e", "explore"), explore.explore, pass_chat_data=True)) dp.add_handler(CommandHandler("official", explore.show_official)) dp.add_handler( CommandHandler('ban', lambda bot, update, args: admin.ban_handler( bot, update, args, True), pass_args=True)) dp.add_handler( CommandHandler('unban', lambda bot, update, args: admin.ban_handler( bot, update, args, False), pass_args=True)) dp.add_handler(CommandHandler('t3chno', t3chnostats)) dp.add_handler(CommandHandler('random', eastereggs.send_random_bot)) dp.add_handler( CommandHandler('easteregg', eastereggs.send_next, pass_args=True)) dp.add_handler(CommandHandler("subscribe", manage_subscription)) dp.add_handler( CommandHandler("newbots", show_new_bots, pass_chat_data=True)) dp.add_handler(CommandHandler("accesstoken", access_token)) dp.add_handler( CommandHandler(('stat', 'stats', 'statistic', 'statistics'), admin.send_statistic)) dp.add_handler( CommandHandler(('log', 'logs'), admin.send_activity_logs, pass_args=True)) dp.add_handler( CommandHandler(('debug', 'analysis', 'ana', 'analyze'), lambda bot, update, args: admin.send_activity_logs( bot, update, args, Statistic.ANALYSIS), pass_args=True)) dp.add_handler( CommandHandler('info', lambda bot, update, args: admin.send_activity_logs( bot, update, args, Statistic.INFO), pass_args=True)) dp.add_handler( CommandHandler(('detail', 'detailed'), lambda bot, update, args: admin.send_activity_logs( bot, update, args, Statistic.DETAILED), pass_args=True)) dp.add_handler( CommandHandler(('warn', 'warning'), lambda bot, update, args: admin.send_activity_logs( bot, update, args, Statistic.WARN), pass_args=True)) dp.add_handler( CommandHandler('important', lambda bot, update, args: admin.send_activity_logs( bot, update, args, Statistic.IMPORTANT), pass_args=True)) dp.add_handler(MessageHandler( Filters.text, lambda bot, update: botlistchat.text_message_logger(bot, update, log)), group=99) for hashtag in HINTS.keys(): dp.add_handler(RegexHandler(r'{}.*'.format(hashtag), botlistchat.hint_handler), group=1) dp.add_handler( CommandHandler(('hint', 'hints'), botlistchat.show_available_hints)) dp.add_handler( ChosenInlineResultHandler(inlinequeries.chosen_result, pass_chat_data=True)) dp.add_handler( InlineQueryHandler(inlinequeries.inlinequery_handler, pass_chat_data=True)) dp.add_handler(MessageHandler(Filters.all, all_handler, pass_chat_data=True), group=98)