fix: add invalid user

This commit is contained in:
xtaodada 2023-12-01 22:23:51 +08:00
parent fd133a7de2
commit 476e768426
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
6 changed files with 23 additions and 3 deletions

View File

@ -4,3 +4,4 @@ rss_hub_host = ["https://rsshub.app"]
cid = 11
tid = None
owner = 11
logtail_token = None

View File

@ -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

View File

@ -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)

View File

@ -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} 成功!")

View File

@ -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()

View File

@ -8,3 +8,4 @@ coloredlogs
apscheduler
sqlitedict
pydantic
logtail-python