Пример #1
0
def send_search(message):
    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
    bot.send_chat_action(message.chat.id, 'record_video')

    name = message.text
    if name is None:
        today_request("invalid")
        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:
        logging.info("🎉 Resource match.")
        today_request("success")
        bot.send_message(message.chat.id, "呐,💐🌷🌹选一个呀!", 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"
                                          f"可以看看这个链接,看看有没有结果。 {SEARCH_URL.format(kw=encoded)} \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:{SEARCH_URL.format(kw=encoded)}\n\n
                            返回内容:{html}
                        """
            save_error_dump(message.chat.id, content)
Пример #2
0
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)