mirror of
https://github.com/tgbot-collection/YYeTsBot.git
synced 2025-11-25 11:29:38 +08:00
usage
This commit is contained in:
28
bot.py
28
bot.py
@@ -17,9 +17,11 @@ from urllib.parse import quote_plus
|
||||
import telebot
|
||||
from telebot import types, apihelper
|
||||
from tgbot_ping import get_runtime
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
|
||||
from html_request import get_search_html, analyse_search_html, get_detail_page
|
||||
from utils import save_error_dump, save_to_cache, get_from_cache, get_error_dump
|
||||
from utils import (save_error_dump, save_to_cache, get_from_cache, get_error_dump,
|
||||
reset_request, today_request, show_usage)
|
||||
from config import PROXY, TOKEN, SEARCH_URL, MAINTAINER, REPORT
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(filename)s [%(levelname)s]: %(message)s')
|
||||
@@ -51,9 +53,17 @@ def send_help(message):
|
||||
|
||||
@bot.message_handler(commands=['ping'])
|
||||
def send_ping(message):
|
||||
logging.info("Pong!")
|
||||
bot.send_chat_action(message.chat.id, 'typing')
|
||||
|
||||
info = get_runtime("botsrunner_yyets_1")
|
||||
bot.send_message(message.chat.id, info, parse_mode='markdown')
|
||||
redis = get_runtime("botsrunner_redis_1", "Redis")
|
||||
|
||||
usage = ""
|
||||
if str(message.chat.id) == MAINTAINER:
|
||||
usage = show_usage()
|
||||
|
||||
bot.send_message(message.chat.id, f"{info}\n{redis}\n\n{usage}", parse_mode='markdown')
|
||||
|
||||
|
||||
@bot.message_handler(commands=['credits'])
|
||||
@@ -103,14 +113,17 @@ def send_my_response(message):
|
||||
|
||||
@bot.message_handler(content_types=["photo", "text"])
|
||||
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)
|
||||
@@ -126,10 +139,12 @@ def send_search(message):
|
||||
markup.add(btn)
|
||||
|
||||
if result:
|
||||
logging.info("🎉Resource match.")
|
||||
logging.info("🎉 Resource match.")
|
||||
today_request("success")
|
||||
bot.send_message(message.chat.id, "呐,💐🌷🌹选一个呀!", reply_markup=markup)
|
||||
else:
|
||||
logging.warning("⚠️Resource not found")
|
||||
logging.warning("⚠️️ Resource not found")
|
||||
today_request("fail")
|
||||
bot.send_chat_action(message.chat.id, 'typing')
|
||||
|
||||
encoded = quote_plus(name)
|
||||
@@ -249,4 +264,7 @@ def report_error(call):
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.info('YYeTs bot is running...')
|
||||
bot.polling(none_stop=True, )
|
||||
scheduler = BackgroundScheduler()
|
||||
scheduler.add_job(reset_request, 'cron', hour=0, minute=0)
|
||||
scheduler.start()
|
||||
bot.polling(none_stop=True)
|
||||
|
||||
@@ -6,4 +6,5 @@ feedparser
|
||||
pysocks
|
||||
tgbot-ping
|
||||
redis
|
||||
cchardet
|
||||
cchardet
|
||||
apscheduler
|
||||
29
utils.py
29
utils.py
@@ -72,3 +72,32 @@ def login():
|
||||
logging.error("Login failed! %s", resp)
|
||||
sys.exit(1)
|
||||
r.close()
|
||||
|
||||
|
||||
def today_request(request_type: str):
|
||||
data_format: dict = dict(total=0, invalid=0, answer=0, success=0, fail=0)
|
||||
data: str = r.get("usage")
|
||||
if data:
|
||||
dict_data: dict = json.loads(data)
|
||||
dict_data[request_type] += 1
|
||||
saved_data: str = json.dumps(dict_data)
|
||||
else:
|
||||
data_format[request_type] = 1
|
||||
saved_data: str = json.dumps(data_format)
|
||||
|
||||
r.set("usage", saved_data)
|
||||
|
||||
|
||||
def reset_request():
|
||||
r.delete("usage")
|
||||
|
||||
|
||||
def show_usage():
|
||||
m = "今天我已经服务了{total}次🤓,无效请求{invalid}😆,主人回复{answer}次🤨,成功请求{success}次😝,失败请求{fail}次🤣"
|
||||
data: str = r.get("usage")
|
||||
if data:
|
||||
dict_data: dict = json.loads(data)
|
||||
else:
|
||||
dict_data: dict = dict(total=0, invalid=0, answer=0, success=0, fail=0)
|
||||
|
||||
return m.format(**dict_data)
|
||||
|
||||
Reference in New Issue
Block a user