mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-08 13:20:01 +08:00
✨ 移除saa依赖
This commit is contained in:
@@ -108,19 +108,21 @@ class BuildImage:
|
||||
返回:
|
||||
Self: Self
|
||||
"""
|
||||
if not text.strip():
|
||||
return cls(1, 1)
|
||||
_font = None
|
||||
if isinstance(font, FreeTypeFont):
|
||||
_font = font
|
||||
elif isinstance(font, (str, Path)):
|
||||
_font = cls.load_font(font, size)
|
||||
width, height = cls.get_text_size(text or "A", _font)
|
||||
width, height = cls.get_text_size(text, _font)
|
||||
if isinstance(padding, int):
|
||||
width += padding * 2
|
||||
height += padding * 2
|
||||
elif isinstance(padding, tuple):
|
||||
width += padding[1] + padding[3]
|
||||
height += padding[0] + padding[2]
|
||||
markImg = cls(width, height, color)
|
||||
markImg = cls(width, height, color, font=_font)
|
||||
await markImg.text(
|
||||
(0, 0), text, fill=font_color, font=_font, center_type="center"
|
||||
)
|
||||
@@ -380,7 +382,6 @@ class BuildImage:
|
||||
text = str(text)
|
||||
if center_type and center_type not in ["center", "height", "width"]:
|
||||
raise ValueError("center_type must be 'center', 'width' or 'height'")
|
||||
width, height = 0, 0
|
||||
max_length_text = ""
|
||||
sentence = text.split("\n")
|
||||
for x in sentence:
|
||||
@@ -392,7 +393,7 @@ class BuildImage:
|
||||
font = self.font
|
||||
if center_type:
|
||||
ttf_w, ttf_h = self.getsize(max_length_text) # type: ignore
|
||||
ttf_h = ttf_h * len(sentence)
|
||||
# ttf_h = ttf_h * len(sentence)
|
||||
pos = self.__center_xy(pos, ttf_w, ttf_h, center_type)
|
||||
self.draw.text(pos, text, fill=fill, font=font)
|
||||
return self
|
||||
|
||||
@@ -3,11 +3,11 @@ from typing import Any
|
||||
from nonebot.internal.params import Depends
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import Command
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
from nonebot_plugin_userinfo import EventUserInfo, UserInfo
|
||||
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
|
||||
def CheckUg(check_user: bool = True, check_group: bool = True):
|
||||
@@ -22,11 +22,11 @@ def CheckUg(check_user: bool = True, check_group: bool = True):
|
||||
if check_user:
|
||||
user_id = session.id1
|
||||
if not user_id:
|
||||
await Text("用户id为空").finish()
|
||||
await MessageUtils.build_message("用户id为空").finish()
|
||||
if check_group:
|
||||
group_id = session.id3 or session.id2
|
||||
if not group_id:
|
||||
await Text("群组id为空").finish()
|
||||
await MessageUtils.build_message("群组id为空").finish()
|
||||
|
||||
return Depends(dependency)
|
||||
|
||||
|
||||
+29
-42
@@ -10,24 +10,14 @@ 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.utils import is_coroutine_callable
|
||||
from nonebot_plugin_saa import (
|
||||
Image,
|
||||
MessageFactory,
|
||||
TargetDoDoChannel,
|
||||
TargetDoDoPrivate,
|
||||
TargetKaiheilaChannel,
|
||||
TargetKaiheilaPrivate,
|
||||
TargetQQGroup,
|
||||
TargetQQPrivate,
|
||||
Text,
|
||||
)
|
||||
from nonebot_plugin_saa.abstract_factories import Receipt
|
||||
from nonebot_plugin_alconna.uniseg import Receipt, Target, UniMessage
|
||||
from pydantic import BaseModel
|
||||
|
||||
from zhenxun.models.friend_user import FriendUser
|
||||
from zhenxun.models.group_console import GroupConsole
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.exception import NotFindSuperuser
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
|
||||
class UserData(BaseModel):
|
||||
@@ -71,7 +61,7 @@ class PlatformUtils:
|
||||
async def send_superuser(
|
||||
cls,
|
||||
bot: Bot,
|
||||
message: str | MessageFactory | Text | Image,
|
||||
message: UniMessage,
|
||||
superuser_id: str | None = None,
|
||||
) -> Receipt | None:
|
||||
"""发送消息给超级用户
|
||||
@@ -324,7 +314,7 @@ class PlatformUtils:
|
||||
bot: Bot,
|
||||
user_id: str | None,
|
||||
group_id: str | None,
|
||||
message: str | Text | MessageFactory | Image,
|
||||
message: str | UniMessage,
|
||||
) -> Receipt | None:
|
||||
"""发送消息
|
||||
|
||||
@@ -338,8 +328,12 @@ class PlatformUtils:
|
||||
Receipt | None: 是否发送成功
|
||||
"""
|
||||
if target := cls.get_target(bot, user_id, group_id):
|
||||
send_message = Text(message) if isinstance(message, str) else message
|
||||
return await send_message.send_to(target, bot)
|
||||
send_message = (
|
||||
MessageUtils.build_message(message)
|
||||
if isinstance(message, str)
|
||||
else message
|
||||
)
|
||||
return await send_message.send(target=target, bot=bot)
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
@@ -383,12 +377,12 @@ class PlatformUtils:
|
||||
"""
|
||||
if isinstance(bot, (v11Bot, v12Bot)):
|
||||
return "qq"
|
||||
if isinstance(bot, DodoBot):
|
||||
return "dodo"
|
||||
if isinstance(bot, KaiheilaBot):
|
||||
return "kaiheila"
|
||||
if isinstance(bot, DiscordBot):
|
||||
return "discord"
|
||||
# if isinstance(bot, DodoBot):
|
||||
# return "dodo"
|
||||
# if isinstance(bot, KaiheilaBot):
|
||||
# return "kaiheila"
|
||||
# if isinstance(bot, DiscordBot):
|
||||
# return "discord"
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
@@ -524,6 +518,7 @@ class PlatformUtils:
|
||||
bot: Bot,
|
||||
user_id: str | None = None,
|
||||
group_id: str | None = None,
|
||||
channel_id: str | None = None,
|
||||
):
|
||||
"""获取发生Target
|
||||
|
||||
@@ -531,6 +526,7 @@ class PlatformUtils:
|
||||
bot: Bot
|
||||
user_id: 用户id
|
||||
group_id: 频道id或群组id
|
||||
channel_id: 频道id
|
||||
|
||||
返回:
|
||||
target: 对应平台Target
|
||||
@@ -538,25 +534,19 @@ class PlatformUtils:
|
||||
target = None
|
||||
if isinstance(bot, (v11Bot, v12Bot)):
|
||||
if group_id:
|
||||
target = TargetQQGroup(group_id=int(group_id))
|
||||
target = Target(group_id)
|
||||
elif user_id:
|
||||
target = TargetQQPrivate(user_id=int(user_id))
|
||||
elif isinstance(bot, DodoBot):
|
||||
if group_id:
|
||||
target = TargetDoDoChannel(channel_id=group_id)
|
||||
target = Target(user_id, private=True)
|
||||
elif isinstance(bot, (DodoBot, KaiheilaBot)):
|
||||
if group_id and channel_id:
|
||||
target = Target(channel_id, parent_id=group_id, channel=True)
|
||||
elif user_id:
|
||||
# target = TargetDoDoPrivate(user_id=user_id)
|
||||
pass
|
||||
elif isinstance(bot, KaiheilaBot):
|
||||
if group_id:
|
||||
target = TargetKaiheilaChannel(channel_id=group_id)
|
||||
elif user_id:
|
||||
target = TargetKaiheilaPrivate(user_id=user_id)
|
||||
target = Target(user_id, private=True)
|
||||
return target
|
||||
|
||||
|
||||
async def broadcast_group(
|
||||
message: str | MessageFactory,
|
||||
message: str | UniMessage,
|
||||
bot: Bot | list[Bot] | None = None,
|
||||
bot_id: str | Set[str] | None = None,
|
||||
ignore_group: Set[int] | None = None,
|
||||
@@ -624,17 +614,14 @@ async def broadcast_group(
|
||||
if not is_run:
|
||||
continue
|
||||
target = PlatformUtils.get_target(
|
||||
_bot,
|
||||
None,
|
||||
group.channel_id or group.group_id,
|
||||
# , group.channel_id
|
||||
_bot, None, group.group_id, group.channel_id
|
||||
)
|
||||
if target:
|
||||
_used_group.append(key)
|
||||
message_list = message
|
||||
if isinstance(message, str):
|
||||
message_list = MessageFactory([Text(message)])
|
||||
await MessageFactory(message_list).send_to(target, _bot)
|
||||
await MessageUtils.build_message(message_list).send(
|
||||
target, _bot
|
||||
)
|
||||
logger.debug("发送成功", log_cmd, target=key)
|
||||
else:
|
||||
logger.warning("target为空", log_cmd, target=key)
|
||||
|
||||
@@ -3,16 +3,13 @@ import time
|
||||
from collections import defaultdict
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from re import L
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
import pypinyin
|
||||
import pytz
|
||||
from nonebot.adapters.onebot.v11 import Message, MessageSegment
|
||||
from nonebot_plugin_saa import Image, MessageFactory, Text
|
||||
|
||||
from zhenxun.configs.config import NICKNAME, Config
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.services.log import logger
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import asyncio
|
||||
|
||||
from nonebot.adapters import Bot
|
||||
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.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_session import EventSession
|
||||
@@ -103,9 +104,9 @@ class WithdrawManager:
|
||||
elif isinstance(bot, v12Bot):
|
||||
logger.debug(f"v12Bot 撤回消息ID: {message_id}", "WithdrawManager")
|
||||
await bot.delete_message(message_id=str(message_id))
|
||||
elif isinstance(bot, KaiheilaBot):
|
||||
pass
|
||||
elif isinstance(bot, DodoBot):
|
||||
pass
|
||||
elif isinstance(bot, DiscordBot):
|
||||
pass
|
||||
# elif isinstance(bot, KaiheilaBot):
|
||||
# pass
|
||||
# elif isinstance(bot, DodoBot):
|
||||
# pass
|
||||
# elif isinstance(bot, DiscordBot):
|
||||
# pass
|
||||
|
||||
Reference in New Issue
Block a user