コード例 #1
0
ファイル: bot.py プロジェクト: Linux-Doc/YYeTsBot
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
ファイル: bot.py プロジェクト: zhengdaguang/YYeTsBot
def send_search(message):
    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:
        send_my_response(message)
        return
    bot.send_chat_action(message.chat.id, 'record_video')

    name = message.text
    if name is None:
        with open('assets/warning.webp', 'rb') as sti:
            bot.send_message(message.chat.id, "不要调戏我!我会报警的")
            bot.send_sticker(message.chat.id, sti)
        return

    logging.info('Receiving message about %s from user %s(%s)', name,
                 message.chat.username, message.chat.id)
    html = get_search_html(name)
    result = analyse_search_html(html)

    markup = types.InlineKeyboardMarkup()
    for url, detail in result.items():
        btn = types.InlineKeyboardButton(detail['name'],
                                         callback_data="choose%s" % url)
        markup.add(btn)

    if result:
        bot.send_message(message.chat.id, "呐,💐🌷🌹选一个呀!", reply_markup=markup)
    else:
        bot.send_chat_action(message.chat.id, 'typing')

        encoded = quote_plus(name)
        bot.send_message(message.chat.id, f"没有找到你想要的信息🤪\n莫非你是想调戏我哦,😏\n\n"
                         f"你先看看这个链接有没有结果。 {SEARCH_URL.format(kw=encoded)} "
                         "如果有的话,那报错给我吧",
                         reply_markup=markup,
                         disable_web_page_preview=True)
        markup = types.InlineKeyboardMarkup()
        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机器人不好用了?点下面的按钮叫 @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:{SEARCH_URL.format(kw=encoded)}\n\n
                        返回内容:{html}
                    """
        save_error_dump(message.chat.id, content)
コード例 #3
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)