diff --git a/liteyuki/liteyuki_main/core.py b/liteyuki/liteyuki_main/core.py index c675831..0bfbc66 100644 --- a/liteyuki/liteyuki_main/core.py +++ b/liteyuki/liteyuki_main/core.py @@ -13,7 +13,7 @@ from liteyuki.utils.config import get_config, load_from_yaml from liteyuki.utils.data_manager import StoredConfig, TempConfig, common_db from liteyuki.utils.language import get_user_lang from liteyuki.utils.ly_typing import T_Bot, T_MessageEvent -from liteyuki.utils.message import Markdown as md +from liteyuki.utils.message import Markdown as md, broadcast_to_superusers from liteyuki.utils.reloader import Reloader from .api import update_liteyuki @@ -225,7 +225,8 @@ async def every_day_update(): if get_config("auto_update", True): result, logs = update_liteyuki() if result: + await broadcast_to_superusers(f"Liteyuki updated: ```\n{logs}\n```") nonebot.logger.info(f"Liteyuki updated: {logs}") Reloader.reload(1) else: - nonebot.logger.info(logs) \ No newline at end of file + nonebot.logger.info(logs) diff --git a/liteyuki/utils/message.py b/liteyuki/utils/message.py index 45ff7ce..a612db8 100644 --- a/liteyuki/utils/message.py +++ b/liteyuki/utils/message.py @@ -13,7 +13,7 @@ from typing import Any from . import load_from_yaml from .ly_api import liteyuki_api -from .ly_typing import T_Bot, T_MessageEvent +from .ly_typing import T_Bot, T_Message, T_MessageEvent require("nonebot_plugin_htmlrender") from nonebot_plugin_htmlrender import md_to_pic @@ -23,6 +23,16 @@ config = load_from_yaml("config.yml") can_send_markdown = {} # 用于存储机器人是否支持发送markdown消息,id->bool +async def broadcast_to_superusers(message: str | T_Message, markdown: bool = False): + """广播消息给超级用户""" + for bot in nonebot.get_bots().values(): + for user_id in config.get("superusers", []): + if markdown: + await Markdown.send_md(message, bot, message_type="private", session_id=user_id) + else: + await bot.send_private_msg(user_id=user_id, message=message) + + class Markdown: @staticmethod async def send_md(