From 6a4c88a6ba7334758693e9070d019de7f6c0f45f Mon Sep 17 00:00:00 2001 From: snowy Date: Fri, 12 Apr 2024 01:15:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/liteyuki_main/core.py | 5 +++-- liteyuki/utils/message.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) 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(