From 476e76842688baeaffa691c83b3392d535931b79 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 1 Dec 2023 22:23:51 +0800 Subject: [PATCH] fix: add invalid user --- defs/glover.py.example | 1 + defs/update.py | 1 - init.py | 6 +++++- plugins/manage_user.py | 15 +++++++++++++++ plugins/update.py | 2 +- requirements.txt | 1 + 6 files changed, 23 insertions(+), 3 deletions(-) diff --git a/defs/glover.py.example b/defs/glover.py.example index 841a1e4..8122d5e 100644 --- a/defs/glover.py.example +++ b/defs/glover.py.example @@ -4,3 +4,4 @@ rss_hub_host = ["https://rsshub.app"] cid = 11 tid = None owner = 11 +logtail_token = None diff --git a/defs/update.py b/defs/update.py index 46638cd..0476080 100644 --- a/defs/update.py +++ b/defs/update.py @@ -122,7 +122,6 @@ async def async_get_user(user_data: Dict, username: str) -> None: user_data[username] = UsernameNotFound except Exception: logs.error(f"获取 {username} 的数据失败") - traceback.print_exc() user_data[username] = None diff --git a/init.py b/init.py index 3332304..7cc1258 100644 --- a/init.py +++ b/init.py @@ -1,10 +1,11 @@ import pyrogram import httpx -from defs.glover import api_id, api_hash +from defs.glover import api_id, api_hash, logtail_token from scheduler import scheduler from logging import getLogger, INFO, ERROR, StreamHandler, basicConfig, FileHandler, Formatter from coloredlogs import ColoredFormatter +from logtail import LogtailHandler # Enable logging logs = getLogger("T2G") @@ -13,10 +14,13 @@ logging_handler = StreamHandler() logging_handler.setFormatter(ColoredFormatter(logging_format)) file_handler = FileHandler("log.txt", mode="w", encoding="utf-8") file_handler.setFormatter(Formatter(logging_format)) +logtail_handler = LogtailHandler(source_token=logtail_token) root_logger = getLogger() root_logger.setLevel(ERROR) root_logger.addHandler(logging_handler) root_logger.addHandler(file_handler) +if logtail_token: + root_logger.addHandler(logtail_handler) basicConfig(level=INFO) logs.setLevel(INFO) diff --git a/plugins/manage_user.py b/plugins/manage_user.py index e9dac75..9d0fbad 100644 --- a/plugins/manage_user.py +++ b/plugins/manage_user.py @@ -3,12 +3,21 @@ import re from pyrogram import filters from pyrogram.types import Message +from defs.feed import get_user from init import bot from defs.sqlite import UserDB from defs.glover import owner +async def check_user(username: str) -> bool: + try: + await get_user(username) + return True + except: + return False + + @bot.on_message(filters=filters.command("add_user") & filters.user(owner)) async def add_user(_, message: Message): try: @@ -19,6 +28,9 @@ async def add_user(_, message: Message): if UserDB.check(username): await message.reply("该用户添加过了!") return + if not await check_user(username): + await message.reply("该用户不存在!或者 rss 服务出现问题!") + return UserDB.add(username) await message.reply("添加成功!") @@ -35,6 +47,9 @@ async def add_user_regex(_, message: Message): if UserDB.check(username): await message.reply("该用户添加过了!") return + if not await check_user(username): + await message.reply("该用户不存在!或者 rss 服务出现问题!") + return UserDB.add(username) await message.reply(f"添加 {username} 成功!") diff --git a/plugins/update.py b/plugins/update.py index 793c308..75081c8 100644 --- a/plugins/update.py +++ b/plugins/update.py @@ -16,6 +16,6 @@ async def update_all(_, message: Message): await msg.edit("检查更新完毕!") -@scheduler.scheduled_job("cron", minute="*/30", id="update_all") +@scheduler.scheduled_job("cron", minute="*/15", id="update_all") async def update_all_30_minutes(): await check_update() diff --git a/requirements.txt b/requirements.txt index 24bc539..f78f828 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ coloredlogs apscheduler sqlitedict pydantic +logtail-python