Support log notice

This commit is contained in:
xtaodada 2023-11-07 20:05:06 +08:00
parent 3db24a013c
commit db2f11ca9a
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659

View File

@ -3,7 +3,7 @@ import contextlib
from typing import Callable, Awaitable, Set, Dict from typing import Callable, Awaitable, Set, Dict
from coloredlogs import ColoredFormatter from coloredlogs import ColoredFormatter
from datetime import datetime, timezone from datetime import datetime, timezone, timedelta
from logging import ( from logging import (
getLogger, getLogger,
StreamHandler, StreamHandler,
@ -81,12 +81,16 @@ bot = Client(
bot.job = scheduler bot.job = scheduler
async def log(message): async def log(message: str, notice: bool = False):
logs.info(message.replace("`", '"')) logs.info(message.replace("`", '"'))
if not Config.LOG: if not Config.LOG:
return return
try: try:
await bot.send_message(Config.LOG_ID, message) await bot.send_message(
Config.LOG_ID,
message,
schedule_date=(datetime.now() + timedelta(seconds=3)) if notice else None,
)
except Exception: except Exception:
Config.LOG = False Config.LOG = False
Config.LOG_ID = "me" Config.LOG_ID = "me"