def explore(bot, update, chat_data): cid = update.effective_chat.id uid = update.effective_user.id mid = util.mid_from_update(update) explorable_bots = Bot.explorable_bots() chat_data["explored"] = chat_data.get("explored", list()) # don't explore twice for explored in chat_data["explored"]: explorable_bots.remove(explored) if len(explorable_bots) == 0: util.send_md_message( bot, cid, mdformat.none_action( "You have explored all the bots. Congratulations, you might be the first 😜" ), ) return random_bot = random.choice(explorable_bots) buttons = [ [ InlineKeyboardButton( captions.ADD_TO_FAVORITES, callback_data=util.callback_for_action( CallbackActions.ADD_TO_FAVORITES, {"id": random_bot.id}), ), InlineKeyboardButton(captions.SHARE, switch_inline_query=random_bot.username), ], [ InlineKeyboardButton( random_explore_text(), callback_data=util.callback_for_action( CallbackActions.EXPLORE_NEXT), ) ], ] markup = InlineKeyboardMarkup(buttons) text = random_bot.detail_text if uid in settings.MODERATORS and util.is_private_message(update): text += "\n\n🛃 /edit{}".format(random_bot.id) msg = bot.formatter.send_or_edit(cid, text, to_edit=mid, reply_markup=markup) chat_data["explored"].append(random_bot)
def random_bot(): """ Returns a random bot from the BotList. By default, only "interesting" bots with description and tags are shown. Use the parameter `?all=True` to receive _all_ possible choices. """ show_all = bool(request.args.get("all", False)) if show_all: random_bot = Bot.select().order_by(fn.Random()).limit(1)[0] else: random_bot = random.choice(Bot.explorable_bots()) data = random_bot.serialize if data: res = jsonify({'search_result': data, 'meta': {'url': request.url}}) res.status_code = 200 else: res = _error("No bot found.") return res