mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-14 13:42:56 +08:00
* ♻️ 使用Uninfo重构PlatformUtils基础方法 * 🩹 优化插件加载与模块格式转换逻辑 * 🚑 修复商店道具无法使用 * 🚑 修复道具无法正常使用 * 🔧 增加Bot状态管理及模块禁用功能 * 🎨 优化Web UI代码结构,修改target方法 * 🚨 auto fix by pre-commit hooks * 🎨 添加菜单API及优化异常处理 * 🐛 优化菜单API及模型结构,修复WebUi插件列表Api * 📝 更新仓库readme * 🚨 add mdlint file * 📝 Add help chapter. * 🐛 修复优化AuthChecker逻辑 * 🐛 优化数据库API,移除冗余导入及修正SQL_DICT引用 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: BalconyJH <balconyjh@gmail.com>
75 lines
2.8 KiB
Python
75 lines
2.8 KiB
Python
from nonebot.adapters import Bot
|
|
import nonebot_plugin_alconna as alc
|
|
|
|
# from nonebot.adapters.discord import Bot as DiscordBot
|
|
# from nonebot.adapters.dodo import Bot as DodoBot
|
|
# from nonebot.adapters.kaiheila import Bot as KaiheilaBot
|
|
# from nonebot.adapters.onebot.v11 import Bot as v11Bot
|
|
# from nonebot.adapters.onebot.v12 import Bot as v12Bot
|
|
from nonebot_plugin_alconna import Image, UniMsg
|
|
from nonebot_plugin_session import EventSession
|
|
|
|
from zhenxun.services.log import logger
|
|
from zhenxun.utils.common_utils import CommonUtils
|
|
from zhenxun.utils.message import MessageUtils
|
|
from zhenxun.utils.platform import PlatformUtils
|
|
|
|
|
|
class BroadcastManage:
|
|
@classmethod
|
|
async def send(
|
|
cls, bot: Bot, message: UniMsg, session: EventSession
|
|
) -> tuple[int, int]:
|
|
"""发送广播消息
|
|
|
|
参数:
|
|
bot: Bot
|
|
message: 消息内容
|
|
session: Session
|
|
|
|
返回:
|
|
tuple[int, int]: 发送成功的群组数量, 发送失败的群组数量
|
|
"""
|
|
message_list = []
|
|
for msg in message:
|
|
if isinstance(msg, alc.Image) and msg.url:
|
|
message_list.append(Image(url=msg.url))
|
|
elif isinstance(msg, alc.Text):
|
|
message_list.append(msg.text)
|
|
group_list, _ = await PlatformUtils.get_group_list(bot)
|
|
if group_list:
|
|
error_count = 0
|
|
for group in group_list:
|
|
try:
|
|
if not await CommonUtils.task_is_block(
|
|
bot,
|
|
"broadcast", # group.channel_id
|
|
group.group_id,
|
|
):
|
|
target = PlatformUtils.get_target(
|
|
group_id=group.group_id, channel_id=group.channel_id
|
|
)
|
|
if target:
|
|
await MessageUtils.build_message(message_list).send(
|
|
target, bot
|
|
)
|
|
logger.debug(
|
|
"发送成功",
|
|
"广播",
|
|
session=session,
|
|
target=f"{group.group_id}:{group.channel_id}",
|
|
)
|
|
else:
|
|
logger.warning("target为空", "广播", session=session)
|
|
except Exception as e:
|
|
error_count += 1
|
|
logger.error(
|
|
"发送失败",
|
|
"广播",
|
|
session=session,
|
|
target=f"{group.group_id}:{group.channel_id}",
|
|
e=e,
|
|
)
|
|
return len(group_list) - error_count, error_count
|
|
return 0, 0
|