def inline_query(bot, update): query = update.inline_query.query key_word = query.split()[0] if not re.search(r"\d", key_word): briefs = Functions.search_by_actress(key_word, 20) else: briefs = [Functions.get_brief(key_word)] if not briefs: return results = [ telegram.InlineQueryResultPhoto( uuid4(), brief.preview_img_url, brief.preview_img_url, caption="\n".join( filter(lambda x: x, (brief.code, brief.title, brief.actress)))) for brief in briefs ] update.inline_query.answer(results)
def message(cls, bot, update): cmd_chat_history = chat_history.history[update.message.from_user.id][0] if len(cmd_chat_history) == 1: if cmd_chat_history[-1] == "Search": reply_markup = telegram.ReplyKeyboardRemove(selective=True) bot.send_message( chat_id=update.message.chat_id, text="Search a code or an actress. e.g. ABP-231 or 桃乃木かな", reply_markup=reply_markup, reply_to_message_id=update.message.message_id) elif cmd_chat_history[-1] == "New": bot.send_message(chat_id=update.message.chat_id, text="How many results? [Integer]") elif cmd_chat_history[-1] == "Random": cls.random(bot, update) chat_history.clear_history(update.message.from_user.id) elif cmd_chat_history[-1] == "Brief": bot.send_message(chat_id=update.message.chat_id, text="Search a code. e.g. ABP-231") elif cmd_chat_history[-1] == "Magnet": bot.send_message(chat_id=update.message.chat_id, text="Search a code. e.g. ABP-231") elif len(cmd_chat_history) == 2: if cmd_chat_history[-2] == "Search": if re.search(r"\d", update.message.text): res = Functions.search_by_code(update.message.text) send_av(bot, update, res) chat_history.clear_history(update.message.from_user.id) else: if cmd_chat_history[-2] == "Search": bot.send_message(chat_id=update.message.chat_id, text="How many results? [Integer]") elif cmd_chat_history[-2] == "New": send_brief( bot, update, Functions.get_newly_released(int(cmd_chat_history[-1]), False)) chat_history.clear_history(update.message.from_user.id) elif cmd_chat_history[-2] == "Brief": send_brief(bot, update, Functions.get_brief(cmd_chat_history[-1])) chat_history.clear_history(update.message.from_user.id) elif cmd_chat_history[-2] == "Magnet": send_magnet(bot, update, Functions.get_magnet(cmd_chat_history[-1])) chat_history.clear_history(update.message.from_user.id) elif len(cmd_chat_history) == 3: if cmd_chat_history[-3] == "Search": res, _ = Functions.search_by_actress(cmd_chat_history[-2], int(cmd_chat_history[-1])) send_brief(bot, update, res) chat_history.clear_history(update.message.from_user.id) return
def search(bot, update, args): """ search command like this: 1. /search ABP-123 2. /search 桃乃木かな -m, --many-actresses [allow|deny/1/0] default=0 -u, --upto [20] default=10 :param bot: :param update: :param args: :return: """ first = args[0] if re.search("\\d", first): # /search ABP-123 if len(args) != 1: bot.send_message(chat_id=update.message.chat_id, text="Sorry, Wrong Usage") return res = Functions.search_by_code(first) send_av(bot, update, res) else: # /search 桃乃木かな [-m/--many-actresses] [on/off] [-u/--upto] [20] try: actress = first options, _ = getopt.getopt( [x.replace(u"—", u"--") for x in args[1:]], 'm:u:', ['many-actress=', 'upto='] ) allow_many_actresses = False up_to = 10 for o, a in options: if o in ("-m", "--many-actresses") and a in ("on", "off", "1", "0"): if a in ("on", "1"): allow_many_actresses = True continue elif o in ("-u", "--upto"): try: up_to = int(a) continue except ValueError: bot.send_message(chat_id=update.message.chat_id, text=helps["search-by-actress"]) return briefs, _ = Functions.search_by_actress(actress, up_to) if not allow_many_actresses: briefs = list(filter(lambda x: "," not in x.actress, briefs)) send_brief(bot, update, briefs) except getopt.GetoptError: bot.send_message(chat_id=update.message.chat_id, text=helps["search-by-actress"]) return
def get_new(bot, update, args): try: options, _ = getopt.getopt([x.replace("—", "--") for x in args], "m:u:", ["many-actress=", "upto="]) allow_many_actresses = False up_to = 10 for o, a in options: if o in ("-m", "--many-actresses") and a in ("on", "off", "1", "0"): if a in ("on", "1"): allow_many_actresses = True continue elif o in ("-u", "--upto"): try: up_to = int(a) continue except ValueError: bot.send_message(chat_id=update.message.chat_id, text=helps["get-new"]) return briefs = Functions.get_newly_released(allow_many_actresses, up_to) send_brief(bot, update, briefs) except getopt.GetoptError: bot.send_message(chat_id=update.message.chat_id, text=helps["get-new"]) return
def get_tags(): params = json.loads(request.data.decode("utf-8")) print(params) res = Functions.get_tags() rsp = jsonify(res) rsp.headers["Access-Control-Allow-Origin"] = "*" return rsp
def actress_info(): params = json.loads(request.data.decode("utf-8")) print(params) res = Functions.get_actress_info(params["actress"]) rsp = jsonify(res.to_dict()) rsp.headers["Access-Control-Allow-Origin"] = "*" return rsp
def search_by_actress(): params = json.loads(request.data.decode("utf-8")) print(params) actress = params["actress"] with_profile = params["with_profile"] == "true" briefs, profile = Functions.search_by_actress(actress, None, with_profile) if not briefs and profile is None: return "", 404 if with_profile: history_names = profile.other["history_names"] res = { "videos": [brief.to_dict() for brief in briefs], "profile": profile.to_dict(), "history_names": history_names, } else: res = {"videos": [brief.to_dict() for brief in briefs]} rsp = jsonify(res) rsp.headers["Access-Control-Allow-Origin"] = "*" return rsp
def new(): params = json.loads(request.data.decode("utf-8")) print(params) if "up_to" in params: res = Functions.get_newly_released(params["up_to"], False) elif "page" in params: res = Functions.get_newly_released(False, params["page"]) else: res = Functions.get_newly_released(30, False) if res: res = [x.to_dict() for x in res] rsp = jsonify(res) rsp.headers["Access-Control-Allow-Origin"] = "*" return rsp
def search_magnet_by_code(): params = json.loads(request.data.decode("utf-8")) print(params) res = [] if params["code"]: res = Functions.get_magnet(params["code"]) if res: res = [x.to_dict() for x in res] rsp = jsonify(res) rsp.headers["Access-Control-Allow-Origin"] = "*" return rsp
def search_by_code(): params = json.loads(request.data.decode("utf-8")) print(params) res = {"videos": None, "other": None} if params["code"]: try: res["videos"] = [Functions.search_by_code(params["code"]).to_dict()] rsp = jsonify(res) except AttributeError: rsp = make_response("") else: rsp = make_response("") rsp.headers["Access-Control-Allow-Origin"] = "*" return rsp
def search_by_actress(): params = json.loads(request.data.decode("utf-8")) print(params) actress = params["actress"] history_name = params["history_name"] == "true" briefs, names = Functions.search_by_actress(actress, None, history_name) res = { "videos": [brief.to_dict() for brief in briefs], "other": { "history_names": names }, } rsp = jsonify(res) rsp.headers["Access-Control-Allow-Origin"] = "*" return rsp
def get_brief(bot, update, args): if len(args) != 1 and len(args) != 3: bot.send_message(chat_id=update.message.chat_id, text=helps["get-brief"]) return if len(args) == 3: bot.send_message(chat_id=update.message.chat_id, text="Sorry, temporarily only English is supported") code = args[0] res = Functions.get_brief(code) if not res: bot.send_message(chat_id=update.message.chat_id, text="Sorry, No Video Found") return send_brief(bot, update, res)
def get_magnet(bot, update, args): send_magnet(bot, update, Functions.get_magnet(args[0]))