Пример #1
0
def send_search(message):
    fan = fansub.FansubEntrance()
    bot.send_chat_action(message.chat.id, 'typing')

    today_request("total")
    if message.reply_to_message and message.reply_to_message.document and \
            message.reply_to_message.document.file_name.startswith("error") and str(message.chat.id) == MAINTAINER:
        today_request("answer")
        send_my_response(message)
        return

    name = message.text
    logging.info('Receiving message: %s from user %s(%s)', name, message.chat.username, message.chat.id)
    if name is None:
        today_request("invalid")
        with open('warning.webp', 'rb') as sti:
            bot.send_message(message.chat.id, "不要调戏我!我会报警的")
            bot.send_sticker(message.chat.id, sti)
        return

    result = fan.search_preview(name)

    markup = types.InlineKeyboardMarkup()

    source = result.get("source")
    result.pop("source")
    for url, detail in result.items():
        btn = types.InlineKeyboardButton(detail, callback_data="choose%s" % url)
        markup.add(btn)

    if result:
        logging.info("🎉 Resource match.")
        today_request("success")
        bot.send_message(message.chat.id, "呐,💐🌷🌹选一个呀!来源:%s" % source, reply_markup=markup)
    else:
        logging.warning("⚠️️ Resource not found")
        today_request("fail")
        bot.send_chat_action(message.chat.id, 'typing')

        encoded = quote_plus(name)
        bot.send_message(message.chat.id, f"没有找到你想要的信息,是不是你打了错别字,或者搜索了一些国产影视剧。🤪\n"
                                          f"还是你想调戏我哦🙅‍️\n\n"
                                          "⚠️如果确定要我背锅,那么请使用 /help 来提交错误", disable_web_page_preview=True)
        if REPORT:
            btn = types.InlineKeyboardButton("快来修复啦", callback_data="fix")
            markup.add(btn)
            bot.send_chat_action(message.chat.id, 'upload_document')
            bot.send_message(message.chat.id, f"《{name}》😭\n大部分情况下机器人是好用的,不要怀疑我的代码质量.\n"
                                              f"如果你真的确定是机器人出问题了,那么点下面的按钮叫 @BennyThink 来修!\n"
                                              f"⚠️报错前请三思,不要乱点,确保这锅应该甩给我。否则我会很生气的😡小心被拉黑哦",
                             reply_markup=markup)
            content = f""" 报告者:{message.chat.first_name}{message.chat.last_name or ""}@{message.chat.username or ""}({message.chat.id})
                            问题发生时间:{time.strftime("%Y-%m-%data %H:%M:%S", time.localtime(message.date))}
                            请求内容:{name} 
                            请求URL:{YYETS_SEARCH_URL.format(kw=encoded)}\n\n
                            
                        """
            save_error_dump(message.chat.id, content)
Пример #2
0
def share_page(call):
    fan = fansub.FansubEntrance()
    # need class name as str
    bot.send_chat_action(call.message.chat.id, 'typing')
    resource_url_hash = re.findall(r"share(\S*)", call.data)[0]
    if magic_recycle(fan, call, resource_url_hash):
        return

    result = fan.search_result(resource_url_hash)
    bot.send_message(call.message.chat.id, "{}  {}".format(result['cnname'], result['share']))
Пример #3
0
def all_episode(call):
    # just send a file
    fan = fansub.FansubEntrance()
    bot.send_chat_action(call.message.chat.id, 'typing')
    resource_url = re.findall(r"all(\S*)", call.data)[0]
    result = fan.search_result(resource_url)

    with tempfile.NamedTemporaryFile(mode='wb+', prefix=result["cnname"], suffix=".txt") as tmp:
        bytes_data = json.dumps(result["all"], ensure_ascii=False, indent=4).encode('u8')
        tmp.write(bytes_data)
        tmp.flush()
        with open(tmp.name, "rb") as f:
            bot.send_chat_action(call.message.chat.id, 'upload_document')
            bot.send_document(call.message.chat.id, f)
Пример #4
0
def choose_link(call):
    fan = fansub.FansubEntrance()
    bot.send_chat_action(call.message.chat.id, 'typing')
    # call.data is url, http://www.rrys2020.com/resource/36588
    resource_url = re.findall(r"choose(\S*)", call.data)[0]
    markup = types.InlineKeyboardMarkup()

    btn1 = types.InlineKeyboardButton("分享页面", callback_data="share%s" % resource_url)
    btn2 = types.InlineKeyboardButton("我全都要", callback_data="all%s" % resource_url)
    markup.add(btn1, btn2)
    text = "想要分享页面,还是我全都要?\n\n" \
           "名词解释:“分享页面”会返回给你一个网站,从那里可以看到全部的下载链接。\n" \
           "“我全都要”会给你发送一个txt文件,文件里包含全部下载连接\n"
    bot.send_message(call.message.chat.id, text, reply_markup=markup)
Пример #5
0
def choose_link(call):
    fan = fansub.FansubEntrance()
    bot.send_chat_action(call.message.chat.id, 'typing')
    # call.data is url_hash, with sha1, http://www.rrys2020.com/resource/36588
    resource_url_hash = re.findall(r"choose(\S*)", call.data)[0]
    if magic_recycle(fan, call, resource_url_hash):
        return

    result = fan.search_result(resource_url_hash)
    with tempfile.NamedTemporaryFile(mode='wb+', prefix=result["cnname"].replace("/", " "), suffix=".txt") as tmp:
        bytes_data = json.dumps(result["all"], ensure_ascii=False, indent=4).encode('u8')
        tmp.write(bytes_data)
        tmp.flush()
        with open(tmp.name, "rb") as f:
            if result.get("type") == "resource":
                caption = "{}\n\n{}".format(result["cnname"], result["share"])
            else:
                caption = result["all"]
            bot.send_chat_action(call.message.chat.id, 'upload_document')
            bot.send_document(call.message.chat.id, f, caption=caption)
Пример #6
0
def share_page(call):
    fan = fansub.FansubEntrance()
    bot.send_chat_action(call.message.chat.id, 'typing')
    resource_url = re.findall(r"share(\S*)", call.data)[0]
    result = fan.search_result(resource_url)
    bot.send_message(call.message.chat.id, result['share'])
Пример #7
0
def base_send_search(message, instance=None):
    if instance is None:
        fan = fansub.FansubEntrance()
    else:
        fan = instance
    bot.send_chat_action(message.chat.id, 'typing')

    today_request("total")
    if message.reply_to_message and message.reply_to_message.document and \
            message.reply_to_message.document.file_name.startswith("error") and str(message.chat.id) == MAINTAINER:
        today_request("answer")
        send_my_response(message)
        return

    name = zhconv.convert(message.text, "zh-hans")
    logging.info('Receiving message: %s from user %s(%s)', name,
                 message.chat.username, message.chat.id)
    if name is None:
        today_request("invalid")
        with open('warning.webp', 'rb') as sti:
            bot.send_message(message.chat.id, "不要调戏我!我会报警的")
            bot.send_sticker(message.chat.id, sti)
        return

    result = fan.search_preview(name)

    markup = types.InlineKeyboardMarkup()

    source = result.get("class")
    result.pop("class")
    count, MAX, warning = 0, 20, ""
    for url_hash, detail in result.items():
        if count > MAX:
            warning = f"*结果太多啦,目前只显示前{MAX}个。关键词再精准一下吧!*\n\n"
            break
        btn = types.InlineKeyboardButton(detail["name"],
                                         callback_data="choose%s" % url_hash)
        markup.add(btn)
        count += 1

    if result:
        logging.info("🎉 Resource match.")
        today_request("success")
        bot.reply_to(message,
                     f"{warning}呐🌹,一共%d个结果,选一个呀!来源:%s" % (len(result), source),
                     reply_markup=markup,
                     parse_mode="markdown")
    else:
        logging.warning("⚠️️ Resource not found")
        today_request("fail")
        bot.send_chat_action(message.chat.id, 'typing')

        encoded = quote_plus(name)
        bot.reply_to(message, f"没有找到你想要的信息,是不是你打了错别字,或者搜索了一些国产影视剧。🤪\n"
                     f"还是你想调戏我哦🙅‍ 本小可爱拒绝被调戏️\n\n"
                     "⚠️如果确定要我背锅,那么请使用 /help 来提交错误",
                     disable_web_page_preview=True)
        if REPORT:
            btn = types.InlineKeyboardButton("快来修复啦", callback_data="fix")
            markup.add(btn)
            bot.send_chat_action(message.chat.id, 'upload_document')
            bot.send_message(message.chat.id,
                             f"《{name}》😭\n大部分情况下机器人是好用的,不要怀疑我的代码质量.\n"
                             f"如果你真的确定是机器人出问题了,那么点下面的按钮叫 @BennyThink 来修!\n"
                             f"⚠️报错前请三思,不要乱点,确保这锅应该甩给我。否则我会很生气的😡小心被拉黑哦",
                             reply_markup=markup)
            content = f""" 报告者:{message.chat.first_name}{message.chat.last_name or ""}@{message.chat.username or ""}({message.chat.id})
                            问题发生时间:{time.strftime("%Y-%m-%data %H:%M:%S", time.localtime(message.date))}
                            请求内容:{name} 
                            请求URL:{YYETS_SEARCH_URL.format(kw=encoded)}\n\n
                            
                        """
            save_error_dump(message.chat.id, content)