mirror of
https://github.com/Xtao-Labs/misskey2telegram.git
synced 2024-11-22 05:53:09 +00:00
chore: fix mult logging
This commit is contained in:
parent
0a957f9495
commit
0964f9f3f4
@ -29,7 +29,7 @@ def get_note_url(host: str, note: Note) -> str:
|
||||
def gen_button(host: str, note: Note, author: str, show_second: bool):
|
||||
source = get_note_url(host, note)
|
||||
reply_source = get_note_url(host, note.reply) if note.reply else None
|
||||
renote_id = note.renote_id if note.reply else note.id
|
||||
renote_id = note.renote_id or note.id
|
||||
if reply_source:
|
||||
first_line = [
|
||||
InlineKeyboardButton(text="Source", url=source),
|
||||
@ -86,10 +86,19 @@ def get_content(host: str, note: Note) -> str:
|
||||
f"\n{get_user_alink(host, note.renote.author)} "
|
||||
f"发表于 {get_post_time(note.renote.created_at)}"
|
||||
)
|
||||
if note.reply:
|
||||
show_note = note.reply
|
||||
action = "回复"
|
||||
if note.reply.content:
|
||||
content = f"> {note.reply.content}\n\n{content}"
|
||||
origin = (
|
||||
f"\n{get_user_alink(host, note.reply.author)} "
|
||||
f"发表于 {get_post_time(note.reply.created_at)}"
|
||||
)
|
||||
content = content[:768]
|
||||
return f"""<b>Misskey Timeline Update</b>
|
||||
|
||||
<code>{content}</code>
|
||||
{content}
|
||||
|
||||
{get_user_alink(host, note.author)} {action}于 {get_post_time(note.created_at)}{origin}
|
||||
点赞: {sum(show_note.reactions.values())} | 回复: {show_note.replies_count} | 转发: {show_note.renote_count}"""
|
||||
|
16
init.py
16
init.py
@ -1,4 +1,4 @@
|
||||
from logging import getLogger, INFO, ERROR, StreamHandler, basicConfig
|
||||
from logging import getLogger, INFO, ERROR, StreamHandler, basicConfig, CRITICAL, Formatter
|
||||
|
||||
import httpx
|
||||
import pyrogram
|
||||
@ -9,11 +9,19 @@ from models.services.scheduler import scheduler
|
||||
from models.sqlite import Sqlite
|
||||
|
||||
# Enable logging
|
||||
logs = getLogger("misskey2telegram")
|
||||
logs = getLogger(__name__)
|
||||
logging_handler = StreamHandler()
|
||||
root_logger = getLogger("pyrogram")
|
||||
root_logger.setLevel(ERROR)
|
||||
dt_fmt = '%Y-%m-%d %H:%M:%S'
|
||||
formatter = Formatter(
|
||||
'[{asctime}] [{levelname:<8}] {name}: {message}', dt_fmt, style='{'
|
||||
)
|
||||
logging_handler.setFormatter(formatter)
|
||||
root_logger = getLogger()
|
||||
root_logger.setLevel(CRITICAL)
|
||||
root_logger.addHandler(logging_handler)
|
||||
pyro_logger = getLogger("pyrogram")
|
||||
pyro_logger.setLevel(CRITICAL)
|
||||
pyro_logger.addHandler(logging_handler)
|
||||
basicConfig(level=INFO)
|
||||
logs.setLevel(INFO)
|
||||
|
||||
|
@ -118,7 +118,7 @@ async def run(user: User):
|
||||
misskey = await create_or_get_misskey_bot(user)
|
||||
try:
|
||||
logs.info(f"尝试启动 Misskey Bot WS 任务 {user.user_id}")
|
||||
await misskey.start(f"wss://{user.host}/streaming", user.token)
|
||||
await misskey.start(f"wss://{user.host}/streaming", user.token, log_level=None)
|
||||
except ClientConnectorError:
|
||||
logs.warning(f"Misskey Bot WS 任务 {user.user_id} 掉线重连")
|
||||
await sleep(3)
|
||||
@ -128,7 +128,7 @@ async def run(user: User):
|
||||
async def test_token(host: str, token: str) -> Union[str, bool]:
|
||||
try:
|
||||
logs.info(f"验证 Token {host} {token}")
|
||||
client = MisskeyClient(f"https://{host}", token)
|
||||
client = MisskeyClient(f"https://{host}", token, log_level=None)
|
||||
await client.http.login()
|
||||
me = await client.api.user.action.get_me()
|
||||
await client.http.close_session()
|
||||
|
Loading…
Reference in New Issue
Block a user