mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-14 21:52:56 +08:00
✨ 移除saa依赖
This commit is contained in:
parent
71f3b031d4
commit
d0792e0a1c
3
.gitignore
vendored
3
.gitignore
vendored
@ -180,4 +180,5 @@ plugins/csgo_server/
|
||||
plugins/activity/
|
||||
!/resources/image/genshin/alc/back.png
|
||||
!/data/genshin_alc/
|
||||
.vscode/launch.json
|
||||
.vscode/launch.json
|
||||
/resources/template/my_info
|
||||
2060
poetry.lock
generated
2060
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -20,7 +20,6 @@ cattrs = "^23.2.3"
|
||||
ruamel-yaml = "^0.18.5"
|
||||
strenum = "^0.4.15"
|
||||
nonebot-plugin-session = "^0.2.3"
|
||||
nonebot-plugin-send-anything-anywhere = "^0.5.0"
|
||||
ujson = "^5.9.0"
|
||||
nonebot-adapter-kaiheila = "^0.3.0"
|
||||
nb-cli = "^1.3.0"
|
||||
|
||||
@ -15,12 +15,8 @@ from zhenxun.utils.decorator.shop import shop_register
|
||||
require("nonebot_plugin_apscheduler")
|
||||
require("nonebot_plugin_alconna")
|
||||
require("nonebot_plugin_session")
|
||||
require("nonebot_plugin_saa")
|
||||
require("nonebot_plugin_userinfo")
|
||||
|
||||
from nonebot_plugin_saa import enable_auto_select_bot
|
||||
|
||||
enable_auto_select_bot()
|
||||
|
||||
import nonebot
|
||||
import ujson as json
|
||||
|
||||
@ -155,6 +155,6 @@ async def _(
|
||||
try:
|
||||
await build_help()
|
||||
except EmptyError:
|
||||
await MessageUtils.build_message("管理员帮助为空").finish(reply=True)
|
||||
await MessageUtils.build_message("管理员帮助为空").finish(reply_to=True)
|
||||
await MessageUtils.build_message(ADMIN_HELP_IMAGE).send()
|
||||
logger.info("查看管理员帮助", arparma.header_result, session=session)
|
||||
|
||||
@ -237,7 +237,7 @@ async def _(
|
||||
At(flag="user", target=user_id) if isinstance(user.result, At) else user_id, # type: ignore
|
||||
f" 从黑屋中拉了出来并急救了一下!",
|
||||
]
|
||||
).finish(reply=True)
|
||||
).finish(reply_to=True)
|
||||
else:
|
||||
await MessageUtils.build_message(f"该用户不在黑名单中捏...").finish(
|
||||
reply_to=True
|
||||
|
||||
@ -2,10 +2,12 @@ import time
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.adapters.discord import Bot as DiscordBot
|
||||
from nonebot.adapters.dodo import Bot as DodoBot
|
||||
|
||||
# from nonebot.adapters.discord import Bot as DiscordBot
|
||||
# from nonebot.adapters.dodo import Bot as DodoBot
|
||||
from nonebot.adapters.dodo.models import MemberInfo
|
||||
from nonebot.adapters.kaiheila import Bot as KaiheilaBot
|
||||
|
||||
# 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
|
||||
|
||||
@ -23,63 +25,63 @@ class MemberUpdateManage:
|
||||
await cls.v11(bot, group_id)
|
||||
elif isinstance(bot, v12Bot):
|
||||
await cls.v12(bot, group_id)
|
||||
elif isinstance(bot, KaiheilaBot):
|
||||
await cls.kaiheila(bot, group_id)
|
||||
elif isinstance(bot, DodoBot):
|
||||
await cls.dodo(bot, group_id)
|
||||
elif isinstance(bot, DiscordBot):
|
||||
await cls.discord(bot, group_id)
|
||||
# elif isinstance(bot, KaiheilaBot):
|
||||
# await cls.kaiheila(bot, group_id)
|
||||
# elif isinstance(bot, DodoBot):
|
||||
# await cls.dodo(bot, group_id)
|
||||
# elif isinstance(bot, DiscordBot):
|
||||
# await cls.discord(bot, group_id)
|
||||
|
||||
@classmethod
|
||||
async def discord(cls, bot: DiscordBot, group_id: str):
|
||||
# TODO: discord更新群组成员信息
|
||||
pass
|
||||
# @classmethod
|
||||
# async def discord(cls, bot: DiscordBot, group_id: str):
|
||||
# # TODO: discord更新群组成员信息
|
||||
# pass
|
||||
|
||||
@classmethod
|
||||
async def dodo(cls, bot: DodoBot, group_id: str):
|
||||
page_size = 100
|
||||
result_size = 100
|
||||
max_id = 0
|
||||
exist_member_list = []
|
||||
group_member_list: list[MemberInfo] = []
|
||||
while result_size == page_size:
|
||||
group_member_data = await bot.get_member_list(
|
||||
island_source_id=group_id, page_size=page_size
|
||||
)
|
||||
result_size = len(group_member_data.list)
|
||||
group_member_list += group_member_data.list
|
||||
max_id = group_member_data.max_id
|
||||
if group_member_list:
|
||||
for user in group_member_list:
|
||||
exist_member_list.append(user.dodo_source_id)
|
||||
await GroupInfoUser.update_or_create(
|
||||
user_id=user.dodo_source_id,
|
||||
group_id=group_id,
|
||||
defaults={
|
||||
"user_name": user.nick_name or user.personal_nick_name,
|
||||
"user_join_time": user.join_time,
|
||||
"platform": "dodo",
|
||||
},
|
||||
)
|
||||
if delete_member_list := list(
|
||||
set(exist_member_list).difference(
|
||||
set(await GroupInfoUser.get_group_member_id_list(group_id))
|
||||
)
|
||||
):
|
||||
await GroupInfoUser.filter(
|
||||
user_id__in=delete_member_list, group_id=group_id
|
||||
).delete()
|
||||
logger.info(
|
||||
f"删除已退群用户",
|
||||
"更新群组成员信息",
|
||||
group_id=group_id,
|
||||
platform="dodo",
|
||||
)
|
||||
# @classmethod
|
||||
# async def dodo(cls, bot: DodoBot, group_id: str):
|
||||
# page_size = 100
|
||||
# result_size = 100
|
||||
# max_id = 0
|
||||
# exist_member_list = []
|
||||
# group_member_list: list[MemberInfo] = []
|
||||
# while result_size == page_size:
|
||||
# group_member_data = await bot.get_member_list(
|
||||
# island_source_id=group_id, page_size=page_size
|
||||
# )
|
||||
# result_size = len(group_member_data.list)
|
||||
# group_member_list += group_member_data.list
|
||||
# max_id = group_member_data.max_id
|
||||
# if group_member_list:
|
||||
# for user in group_member_list:
|
||||
# exist_member_list.append(user.dodo_source_id)
|
||||
# await GroupInfoUser.update_or_create(
|
||||
# user_id=user.dodo_source_id,
|
||||
# group_id=group_id,
|
||||
# defaults={
|
||||
# "user_name": user.nick_name or user.personal_nick_name,
|
||||
# "user_join_time": user.join_time,
|
||||
# "platform": "dodo",
|
||||
# },
|
||||
# )
|
||||
# if delete_member_list := list(
|
||||
# set(exist_member_list).difference(
|
||||
# set(await GroupInfoUser.get_group_member_id_list(group_id))
|
||||
# )
|
||||
# ):
|
||||
# await GroupInfoUser.filter(
|
||||
# user_id__in=delete_member_list, group_id=group_id
|
||||
# ).delete()
|
||||
# logger.info(
|
||||
# f"删除已退群用户",
|
||||
# "更新群组成员信息",
|
||||
# group_id=group_id,
|
||||
# platform="dodo",
|
||||
# )
|
||||
|
||||
@classmethod
|
||||
async def kaiheila(cls, bot: KaiheilaBot, group_id: str):
|
||||
# TODO: kaiheila 更新群组成员信息
|
||||
pass
|
||||
# @classmethod
|
||||
# async def kaiheila(cls, bot: KaiheilaBot, group_id: str):
|
||||
# # TODO: kaiheila 更新群组成员信息
|
||||
# pass
|
||||
|
||||
@classmethod
|
||||
async def v11(cls, bot: v11Bot, group_id: str):
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.exception import IgnoredException
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot_plugin_alconna import UniMsg
|
||||
from nonebot_plugin_saa import Mention, MessageFactory, Text
|
||||
from nonebot_plugin_alconna import At, UniMsg
|
||||
from nonebot_plugin_session import EventSession
|
||||
from pydantic import BaseModel
|
||||
from tortoise.exceptions import IntegrityError
|
||||
@ -22,6 +21,7 @@ from zhenxun.utils.enum import (
|
||||
PluginType,
|
||||
)
|
||||
from zhenxun.utils.exception import InsufficientGold
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.utils import CountLimiter, FreqLimiter, UserBlockLimiter
|
||||
|
||||
|
||||
@ -146,7 +146,7 @@ class LimitManage:
|
||||
key_type = channel_id or group_id
|
||||
if is_limit and not limiter.check(key_type):
|
||||
if limit.result:
|
||||
await Text(limit.result).send()
|
||||
await MessageUtils.build_message(limit.result).send()
|
||||
logger.debug(
|
||||
f"{limit.module}({limit.limit_type}) 正在限制中...",
|
||||
"HOOK",
|
||||
@ -296,7 +296,9 @@ class AuthChecker:
|
||||
"""超级用户群组插件状态"""
|
||||
if self._flmt_s.check(group_id or user_id):
|
||||
self._flmt_s.start_cd(group_id or user_id)
|
||||
await Text("超级管理员禁用了该群此功能...").send(reply=True)
|
||||
await MessageUtils.build_message(
|
||||
"超级管理员禁用了该群此功能..."
|
||||
).send(reply_to=True)
|
||||
logger.debug(
|
||||
f"{plugin.name}({plugin.module}) 超级管理员禁用了该群此功能...",
|
||||
"HOOK",
|
||||
@ -309,7 +311,9 @@ class AuthChecker:
|
||||
"""群组插件状态"""
|
||||
if self._flmt_s.check(group_id or user_id):
|
||||
self._flmt_s.start_cd(group_id or user_id)
|
||||
await Text("该群未开启此功能...").send(reply=True)
|
||||
await MessageUtils.build_message("该群未开启此功能...").send(
|
||||
reply_to=True
|
||||
)
|
||||
logger.debug(
|
||||
f"{plugin.name}({plugin.module}) 未开启此功能...",
|
||||
"HOOK",
|
||||
@ -321,7 +325,9 @@ class AuthChecker:
|
||||
try:
|
||||
if self._flmt_c.check(group_id):
|
||||
self._flmt_c.start_cd(group_id)
|
||||
await Text("该功能在群组中已被禁用...").send(reply=True)
|
||||
await MessageUtils.build_message(
|
||||
"该功能在群组中已被禁用..."
|
||||
).send(reply_to=True)
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
"auth_plugin 发送消息失败", "HOOK", session=session, e=e
|
||||
@ -338,7 +344,9 @@ class AuthChecker:
|
||||
try:
|
||||
if self._flmt_c.check(user_id):
|
||||
self._flmt_c.start_cd(user_id)
|
||||
await Text("该功能在私聊中已被禁用...").send()
|
||||
await MessageUtils.build_message(
|
||||
"该功能在私聊中已被禁用..."
|
||||
).send()
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
"auth_admin 发送消息失败", "HOOK", session=session, e=e
|
||||
@ -356,7 +364,7 @@ class AuthChecker:
|
||||
raise IsSuperuserException()
|
||||
if self._flmt_s.check(group_id or user_id):
|
||||
self._flmt_s.start_cd(group_id or user_id)
|
||||
await Text("全局未开启此功能...").send()
|
||||
await MessageUtils.build_message("全局未开启此功能...").send()
|
||||
logger.debug(
|
||||
f"{plugin.name}({plugin.module}) 全局未开启此功能...",
|
||||
"HOOK",
|
||||
@ -381,14 +389,12 @@ class AuthChecker:
|
||||
try:
|
||||
if self._flmt.check(user_id):
|
||||
self._flmt.start_cd(user_id)
|
||||
await MessageFactory(
|
||||
await MessageUtils.build_message(
|
||||
[
|
||||
Mention(user_id),
|
||||
Text(
|
||||
f"你的权限不足喔,该功能需要的权限等级: {plugin.admin_level}"
|
||||
),
|
||||
At(flag="user", target=user_id),
|
||||
f"你的权限不足喔,该功能需要的权限等级: {plugin.admin_level}",
|
||||
]
|
||||
).send(reply=True)
|
||||
).send(reply_to=True)
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
"auth_admin 发送消息失败", "HOOK", session=session, e=e
|
||||
@ -402,7 +408,7 @@ class AuthChecker:
|
||||
else:
|
||||
if not await LevelUser.check_level(user_id, None, plugin.admin_level):
|
||||
try:
|
||||
await Text(
|
||||
await MessageUtils.build_message(
|
||||
f"你的权限不足喔,该功能需要的权限等级: {plugin.admin_level}"
|
||||
).send()
|
||||
except Exception as e:
|
||||
@ -428,9 +434,7 @@ class AuthChecker:
|
||||
"""
|
||||
if group_id := session.id3 or session.id2:
|
||||
text = message.extract_plain_text()
|
||||
group = await GroupConsole.get_or_none(
|
||||
group_id=group_id, channel_id__isnull=True
|
||||
)
|
||||
group = await GroupConsole.get_group(group_id)
|
||||
if not group:
|
||||
"""群不存在"""
|
||||
raise IgnoredException("群不存在")
|
||||
@ -468,7 +472,9 @@ class AuthChecker:
|
||||
if user.gold < plugin.cost_gold:
|
||||
"""插件消耗金币不足"""
|
||||
try:
|
||||
await Text(f"金币不足..该功能需要{plugin.cost_gold}金币..").send()
|
||||
await MessageUtils.build_message(
|
||||
f"金币不足..该功能需要{plugin.cost_gold}金币.."
|
||||
).send()
|
||||
except Exception as e:
|
||||
logger.error("auth_cost 发送消息失败", "HOOK", session=session, e=e)
|
||||
logger.debug(
|
||||
|
||||
@ -3,13 +3,13 @@ from nonebot.exception import IgnoredException
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.message import run_preprocessor
|
||||
from nonebot.typing import T_State
|
||||
from nonebot_plugin_saa import Mention, MessageFactory, Text
|
||||
from nonebot_plugin_alconna import At
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.models.ban_console import BanConsole
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.utils import FreqLimiter
|
||||
|
||||
Config.add_plugin_config(
|
||||
@ -61,10 +61,10 @@ async def _(
|
||||
time_str = f"{minute} 分钟"
|
||||
if ban_result and _flmt.check(user_id):
|
||||
_flmt.start_cd(user_id)
|
||||
await MessageFactory(
|
||||
await MessageUtils.build_message(
|
||||
[
|
||||
Mention(user_id),
|
||||
Text(f"{ban_result}\n在..在 {time_str} 后才会理你喔"),
|
||||
At(flag="user", target=user_id),
|
||||
f"{ban_result}\n在..在 {time_str} 后才会理你喔",
|
||||
]
|
||||
).send()
|
||||
raise IgnoredException("用户处于黑名单中...")
|
||||
|
||||
@ -1,20 +1,19 @@
|
||||
import time
|
||||
from collections import defaultdict
|
||||
|
||||
from click import command
|
||||
from nonebot.adapters.onebot.v11 import ActionFailed, Bot, GroupMessageEvent
|
||||
from nonebot.adapters.onebot.v11 import Bot
|
||||
from nonebot.exception import IgnoredException
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.message import run_preprocessor
|
||||
from nonebot.typing import T_State
|
||||
from nonebot_plugin_alconna import Arparma
|
||||
from nonebot_plugin_saa import Mention, MessageFactory, Text
|
||||
from nonebot_plugin_alconna import At
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.models.ban_console import BanConsole
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
malicious_check_time = Config.get_config("hook", "MALICIOUS_CHECK_TIME")
|
||||
malicious_ban_count = Config.get_config("hook", "MALICIOUS_BAN_COUNT")
|
||||
@ -88,10 +87,10 @@ async def _(matcher: Matcher, bot: Bot, session: EventSession, state: T_State):
|
||||
"HOOK",
|
||||
session=session,
|
||||
)
|
||||
await MessageFactory(
|
||||
await MessageUtils.build_message(
|
||||
[
|
||||
Mention(user_id),
|
||||
Text(f"检测到恶意触发命令,您将被封禁 30 分钟"),
|
||||
At(flag="user", target=user_id),
|
||||
f"检测到恶意触发命令,您将被封禁 30 分钟",
|
||||
]
|
||||
).send()
|
||||
logger.debug(
|
||||
|
||||
@ -9,7 +9,6 @@ from nonebot.adapters.onebot.v11 import FriendRequestEvent, GroupRequestEvent
|
||||
from nonebot.adapters.onebot.v12 import Bot as v12Bot
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot_plugin_saa import TargetQQPrivate, Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import NICKNAME, Config
|
||||
@ -19,6 +18,8 @@ from zhenxun.models.friend_user import FriendUser
|
||||
from zhenxun.models.group_console import GroupConsole
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType, RequestHandleType, RequestType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.platform import PlatformUtils
|
||||
|
||||
base_config = Config.get("invite_manager")
|
||||
|
||||
@ -76,14 +77,15 @@ async def _(bot: v12Bot | v11Bot, event: FriendRequestEvent, session: EventSessi
|
||||
# sex = user["sex"]
|
||||
# age = str(user["age"])
|
||||
comment = event.comment
|
||||
superuser = int(superuser)
|
||||
await Text(
|
||||
f"*****一份好友申请*****\n"
|
||||
f"昵称:{nickname}({event.user_id})\n"
|
||||
f"自动同意:{'√' if base_config.get('AUTO_ADD_FRIEND') else '×'}\n"
|
||||
f"日期:{str(datetime.now()).split('.')[0]}\n"
|
||||
f"备注:{event.comment}"
|
||||
).send_to(target=TargetQQPrivate(user_id=superuser), bot=bot)
|
||||
if superuser:
|
||||
superuser = int(superuser)
|
||||
await MessageUtils.build_message(
|
||||
f"*****一份好友申请*****\n"
|
||||
f"昵称:{nickname}({event.user_id})\n"
|
||||
f"自动同意:{'√' if base_config.get('AUTO_ADD_FRIEND') else '×'}\n"
|
||||
f"日期:{str(datetime.now()).split('.')[0]}\n"
|
||||
f"备注:{event.comment}"
|
||||
).send(target=PlatformUtils.get_target(bot, superuser))
|
||||
if base_config.get("AUTO_ADD_FRIEND"):
|
||||
logger.debug(
|
||||
f"已开启好友请求自动同意,成功通过该请求",
|
||||
|
||||
@ -58,8 +58,8 @@ async def _():
|
||||
# # 睡觉了
|
||||
@scheduler.scheduled_job(
|
||||
"cron",
|
||||
hour=1,
|
||||
minute=16,
|
||||
hour=23,
|
||||
minute=59,
|
||||
)
|
||||
async def _():
|
||||
message = MessageUtils.build_message(
|
||||
|
||||
@ -6,7 +6,6 @@ from typing import Any, Callable, Literal
|
||||
|
||||
from nonebot.adapters import Bot, Event
|
||||
from nonebot_plugin_alconna import UniMessage, UniMsg
|
||||
from nonebot_plugin_saa import MessageFactory
|
||||
from nonebot_plugin_session import EventSession
|
||||
from pydantic import BaseModel, create_model
|
||||
|
||||
@ -298,8 +297,9 @@ class ShopManage:
|
||||
raise ValueError("该商品使用函数已被注册!")
|
||||
kwargs["send_success_msg"] = send_success_msg
|
||||
kwargs["max_num_limit"] = max_num_limit
|
||||
# TODO: create_model(f"{uuid}_model", __base__=ShopParam, **kwargs)
|
||||
cls.uuid2goods[uuid] = Goods(
|
||||
model=create_model(f"{uuid}_model", __base__=ShopParam, **kwargs),
|
||||
model=None,# create_model(f"{uuid}_model", __base__=ShopParam, **kwargs),
|
||||
params=kwargs,
|
||||
before_handle=before_handle,
|
||||
after_handle=after_handle,
|
||||
|
||||
@ -17,7 +17,6 @@ from zhenxun.utils.image_utils import BuildImage, ImageTemplate
|
||||
from zhenxun.utils.utils import get_user_avatar
|
||||
|
||||
from ._random_event import random_event
|
||||
from .goods_register import driver
|
||||
from .utils import get_card
|
||||
|
||||
ICON_PATH = IMAGE_PATH / "_icon"
|
||||
|
||||
@ -172,8 +172,8 @@ async def _generate_card(
|
||||
uid_img = await BuildImage.build_text_image(
|
||||
f"UID: {uid}", size=30, font_color=(255, 255, 255)
|
||||
)
|
||||
image1 = await bk.build_text_image("Accumulative check-in for", bk.font)
|
||||
image2 = await bk.build_text_image("days", bk.font)
|
||||
image1 = await bk.build_text_image("Accumulative check-in for", bk.font, size=30)
|
||||
image2 = await bk.build_text_image("days", bk.font, size=30)
|
||||
sign_day_img = await BuildImage.build_text_image(
|
||||
f"{user.sign_count}", size=40, font_color=(211, 64, 33)
|
||||
)
|
||||
@ -181,8 +181,8 @@ async def _generate_card(
|
||||
tip_height = max([image1.height, image2.height, sign_day_img.height])
|
||||
tip_image = BuildImage(tip_width, tip_height, (255, 255, 255, 0))
|
||||
await tip_image.paste(image1, (0, 7))
|
||||
await tip_image.paste(sign_day_img, (image1.width + 15, 0))
|
||||
await tip_image.paste(image2, (image1.width + sign_day_img.width + 30, 7))
|
||||
await tip_image.paste(sign_day_img, (image1.width + 7, 0))
|
||||
await tip_image.paste(image2, (image1.width + sign_day_img.width + 15, 7))
|
||||
|
||||
lik_text1_img = await BuildImage.build_text_image("当前", size=20)
|
||||
lik_text2_img = await BuildImage.build_text_image(
|
||||
|
||||
@ -7,13 +7,12 @@ from nonebot.permission import SUPERUSER
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot_plugin_alconna import Text as alcText
|
||||
from nonebot_plugin_alconna import UniMsg
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.configs.utils import PluginExtraData, RegisterConfig, Task
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from ._data_source import BroadcastManage
|
||||
|
||||
@ -56,10 +55,10 @@ async def _(
|
||||
if isinstance(msg, alcText) and msg.text.strip().startswith(command[0]):
|
||||
msg.text = msg.text.replace(command[0], "", 1).strip()
|
||||
break
|
||||
await Text("正在发送..请等一下哦!").send()
|
||||
await MessageUtils.build_message("正在发送..请等一下哦!").send()
|
||||
count, error_count = await BroadcastManage.send(bot, message, session)
|
||||
result = f"成功广播 {count} 个群组"
|
||||
if error_count:
|
||||
result += f"\n广播失败 {error_count} 个群组"
|
||||
await Text(f"发送广播完成!\n{result}").send(reply=True)
|
||||
await MessageUtils.build_message(f"发送广播完成!\n{result}").send(reply_to=True)
|
||||
logger.info(f"发送广播信息: {message}", "广播", session=session)
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
import nonebot_plugin_alconna as alc
|
||||
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.onebot.v11 import Bot as v11Bot
|
||||
from nonebot.adapters.onebot.v12 import Bot as v12Bot
|
||||
from nonebot_plugin_alconna import UniMsg
|
||||
from nonebot_plugin_saa import Image, MessageFactory, Text
|
||||
|
||||
# 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.models.group_console import GroupConsole
|
||||
from zhenxun.models.task_info import TaskInfo
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.platform import PlatformUtils
|
||||
|
||||
|
||||
@ -34,9 +34,9 @@ class BroadcastManage:
|
||||
message_list = []
|
||||
for msg in message:
|
||||
if isinstance(msg, alc.Image) and msg.url:
|
||||
message_list.append(Image(msg.url))
|
||||
message_list.append(Image(url=msg.url))
|
||||
elif isinstance(msg, alc.Text):
|
||||
message_list.append(Text(msg.text))
|
||||
message_list.append(msg.text)
|
||||
group_list, _ = await PlatformUtils.get_group_list(bot)
|
||||
if group_list:
|
||||
error_count = 0
|
||||
@ -50,7 +50,9 @@ class BroadcastManage:
|
||||
bot, None, group.channel_id or group.group_id
|
||||
)
|
||||
if target:
|
||||
await MessageFactory(message_list).send_to(target, bot)
|
||||
await MessageUtils.build_message(message_list).send(
|
||||
target, bot
|
||||
)
|
||||
logger.debug(
|
||||
"发送成功",
|
||||
"广播",
|
||||
|
||||
@ -7,13 +7,13 @@ from nonebot.rule import to_me
|
||||
from nonebot.utils import run_sync
|
||||
from nonebot_plugin_alconna import Alconna, on_alconna
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.path_config import TEMP_PATH
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.utils import ResourceDirManager
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
@ -44,11 +44,14 @@ ResourceDirManager.add_temp_dir(TEMP_PATH, True)
|
||||
|
||||
@_matcher.handle()
|
||||
async def _(session: EventSession):
|
||||
await Text("开始清理临时数据...").send()
|
||||
await MessageUtils.build_message("开始清理临时数据...").send()
|
||||
size = await _clear_data()
|
||||
await Text("共清理了 {:.2f}MB 的数据...".format(size / 1024 / 1024)).send()
|
||||
await MessageUtils.build_message(
|
||||
"共清理了 {:.2f}MB 的数据...".format(size / 1024 / 1024)
|
||||
).send()
|
||||
logger.info(
|
||||
"清理临时数据完成,共清理了 {:.2f}MB 的数据...".format(size / 1024 / 1024), session=session
|
||||
"清理临时数据完成,共清理了 {:.2f}MB 的数据...".format(size / 1024 / 1024),
|
||||
session=session,
|
||||
)
|
||||
|
||||
|
||||
@ -71,8 +74,14 @@ def _clear_data() -> float:
|
||||
dir_size += file_size
|
||||
logger.debug(f"移除临时文件: {file.absolute()}", "清理临时数据")
|
||||
except Exception as e:
|
||||
logger.error(f"清理临时数据错误,临时文件夹: {dir_.absolute()}...", "清理临时数据", e=e)
|
||||
logger.debug("清理临时文件夹大小: {:.2f}MB".format(size / 1024 / 1024), "清理临时数据")
|
||||
logger.error(
|
||||
f"清理临时数据错误,临时文件夹: {dir_.absolute()}...",
|
||||
"清理临时数据",
|
||||
e=e,
|
||||
)
|
||||
logger.debug(
|
||||
"清理临时文件夹大小: {:.2f}MB".format(size / 1024 / 1024), "清理临时数据"
|
||||
)
|
||||
return float(size)
|
||||
|
||||
|
||||
@ -83,4 +92,7 @@ def _clear_data() -> float:
|
||||
)
|
||||
async def _():
|
||||
size = await _clear_data()
|
||||
logger.info("自动清理临时数据完成,共清理了 {:.2f}MB 的数据...".format(size / 1024 / 1024), "定时任务")
|
||||
logger.info(
|
||||
"自动清理临时数据完成,共清理了 {:.2f}MB 的数据...".format(size / 1024 / 1024),
|
||||
"定时任务",
|
||||
)
|
||||
|
||||
@ -4,12 +4,12 @@ from nonebot.permission import SUPERUSER
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot.rule import to_me
|
||||
from nonebot_plugin_alconna import Alconna, on_alconna
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.rules import admin_check, ensure_group
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
@ -70,13 +70,13 @@ async def _(
|
||||
msg = ["{user_id} {nickname}".format_map(g) for g in fl]
|
||||
msg = "\n".join(msg)
|
||||
msg = f"| UID | 昵称 | 共{len(fl)}个好友\n" + msg
|
||||
await Text(msg).send()
|
||||
await MessageUtils.build_message(msg).send()
|
||||
logger.info("查看好友列表", "好友列表", session=session)
|
||||
except (ApiNotAvailable, AttributeError) as e:
|
||||
await Text("Api未实现...").send()
|
||||
await MessageUtils.build_message("Api未实现...").send()
|
||||
except Exception as e:
|
||||
logger.error("好友列表发生错误", "好友列表", session=session, e=e)
|
||||
await Text("其他未知错误...").send()
|
||||
await MessageUtils.build_message("其他未知错误...").send()
|
||||
|
||||
|
||||
@_group_matcher.handle()
|
||||
@ -90,10 +90,10 @@ async def _(
|
||||
msg = ["{group_id} {group_name}".format_map(g) for g in gl]
|
||||
msg = "\n".join(msg)
|
||||
msg = f"| GID | 名称 | 共{len(gl)}个群组\n" + msg
|
||||
await Text(msg).send()
|
||||
await MessageUtils.build_message(msg).send()
|
||||
logger.info("查看群组列表", "群组列表", session=session)
|
||||
except (ApiNotAvailable, AttributeError) as e:
|
||||
await Text("Api未实现...").send()
|
||||
await MessageUtils.build_message("Api未实现...").send()
|
||||
except Exception as e:
|
||||
logger.error("查看群组列表发生错误", "群组列表", session=session, e=e)
|
||||
await Text("其他未知错误...").send()
|
||||
await MessageUtils.build_message("其他未知错误...").send()
|
||||
|
||||
@ -14,7 +14,6 @@ from nonebot_plugin_alconna import (
|
||||
on_alconna,
|
||||
store_true,
|
||||
)
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import NICKNAME
|
||||
@ -22,6 +21,7 @@ from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.models.group_console import GroupConsole
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name="管理群操作",
|
||||
@ -139,7 +139,7 @@ def CheckGroupId():
|
||||
if group_id.available:
|
||||
gid = group_id.result
|
||||
if not gid:
|
||||
await Text("群组id不能为空...").finish()
|
||||
await MessageUtils.build_message("群组id不能为空...").finish()
|
||||
state["group_id"] = gid
|
||||
|
||||
return Depends(dependency)
|
||||
@ -152,7 +152,7 @@ async def _(session: EventSession, arparma: Arparma, state: T_State, level: int)
|
||||
old_level = group.level
|
||||
group.level = level
|
||||
await group.save(update_fields=["level"])
|
||||
await Text("群权限修改成功!").send(reply=True)
|
||||
await MessageUtils.build_message("群权限修改成功!").send(reply_to=True)
|
||||
logger.info(
|
||||
f"修改群权限: {old_level} -> {level}",
|
||||
arparma.header_result,
|
||||
@ -166,11 +166,11 @@ async def _(session: EventSession, arparma: Arparma, state: T_State):
|
||||
gid = state["group_id"]
|
||||
group = await GroupConsole.get_or_none(group_id=gid)
|
||||
if not group:
|
||||
await Text("群组信息不存在, 请更新群组信息...").finish()
|
||||
await MessageUtils.build_message("群组信息不存在, 请更新群组信息...").finish()
|
||||
s = "删除" if arparma.find("del") else "添加"
|
||||
group.is_super = not arparma.find("del")
|
||||
await group.save(update_fields=["is_super"])
|
||||
await Text(f"{s}群白名单成功!").send(reply=True)
|
||||
await MessageUtils.build_message(f"{s}群白名单成功!").send(reply_to=True)
|
||||
logger.info(f"{s}群白名单", arparma.header_result, session=session, target=gid)
|
||||
|
||||
|
||||
@ -181,7 +181,7 @@ async def _(session: EventSession, arparma: Arparma, state: T_State):
|
||||
group_id=gid, defaults={"group_flag": 0 if arparma.find("del") else 1}
|
||||
)
|
||||
s = "删除" if arparma.find("del") else "添加"
|
||||
await Text(f"{s}群认证成功!").send(reply=True)
|
||||
await MessageUtils.build_message(f"{s}群认证成功!").send(reply_to=True)
|
||||
logger.info(f"{s}群白名单", arparma.header_result, session=session, target=gid)
|
||||
|
||||
|
||||
@ -191,17 +191,17 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma, group_id: int):
|
||||
group_list = [g["group_id"] for g in await bot.get_group_list()]
|
||||
if group_id not in group_list:
|
||||
logger.debug("群组不存在", "退群", session=session, target=group_id)
|
||||
await Text(f"{NICKNAME}未在该群组中...").finish()
|
||||
await MessageUtils.build_message(f"{NICKNAME}未在该群组中...").finish()
|
||||
try:
|
||||
await bot.set_group_leave(group_id=group_id)
|
||||
logger.info(
|
||||
f"{NICKNAME}退出群组成功", "退群", session=session, target=group_id
|
||||
)
|
||||
await Text(f"退出群组 {group_id} 成功!").send()
|
||||
await MessageUtils.build_message(f"退出群组 {group_id} 成功!").send()
|
||||
await GroupConsole.filter(group_id=group_id).delete()
|
||||
except Exception as e:
|
||||
logger.error(f"退出群组失败", "退群", session=session, target=group_id, e=e)
|
||||
await Text(f"退出群组 {group_id} 失败...").send()
|
||||
await MessageUtils.build_message(f"退出群组 {group_id} 失败...").send()
|
||||
else:
|
||||
# TODO: 其他平台的退群操作
|
||||
await Text(f"暂未支持退群操作...").send()
|
||||
await MessageUtils.build_message(f"暂未支持退群操作...").send()
|
||||
|
||||
@ -3,13 +3,13 @@ from nonebot.plugin import PluginMetadata
|
||||
from nonebot.rule import to_me
|
||||
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.configs.utils import PluginExtraData, RegisterConfig
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name="重载配置",
|
||||
@ -55,7 +55,7 @@ _matcher = on_alconna(
|
||||
async def _(session: EventSession, arparma: Arparma):
|
||||
Config.reload()
|
||||
logger.debug("自动重载配置文件", arparma.header_result, session=session)
|
||||
await Text("重载完成!").send(reply=True)
|
||||
await MessageUtils.build_message("重载完成!").send(reply_to=True)
|
||||
|
||||
|
||||
@scheduler.scheduled_job(
|
||||
|
||||
@ -9,13 +9,13 @@ from nonebot_plugin_alconna import (
|
||||
Subcommand,
|
||||
on_alconna,
|
||||
)
|
||||
from nonebot_plugin_saa import Mention, MessageFactory, Text
|
||||
from nonebot_plugin_session import EventSession, SessionLevel
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.models.level_user import LevelUser
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name="用户权限管理",
|
||||
@ -43,7 +43,9 @@ _matcher = on_alconna(
|
||||
Alconna(
|
||||
"权限设置",
|
||||
Subcommand(
|
||||
"add", Args["level", int]["uid", [str, At]]["gid?", str], help_text="添加权限"
|
||||
"add",
|
||||
Args["level", int]["uid", [str, At]]["gid?", str],
|
||||
help_text="添加权限",
|
||||
),
|
||||
Subcommand("delete", Args["uid", [str, At]]["gid?", str], help_text="删除权限"),
|
||||
),
|
||||
@ -72,13 +74,17 @@ async def _(
|
||||
f"修改权限: {old_level} -> {level}", arparma.header_result, session=session
|
||||
)
|
||||
if session.level in [SessionLevel.LEVEL2, SessionLevel.LEVEL3]:
|
||||
await MessageFactory(
|
||||
[Text("成功为 "), Mention(uid), Text(f" 设置权限:{old_level} -> {level}")]
|
||||
).finish(reply=True)
|
||||
await Text(
|
||||
await MessageUtils.build_message(
|
||||
[
|
||||
"成功为 ",
|
||||
At(flag="user", target=uid),
|
||||
f" 设置权限:{old_level} -> {level}",
|
||||
]
|
||||
).finish(reply_to=True)
|
||||
await MessageUtils.build_message(
|
||||
f"成功为 \n群组:{group_id}\n用户:{uid} \n设置权限!\n权限:{old_level} -> {level}"
|
||||
).finish()
|
||||
await Text(f"设置权限时群组不能为空...").finish()
|
||||
await MessageUtils.build_message(f"设置权限时群组不能为空...").finish()
|
||||
|
||||
|
||||
@_matcher.assign("delete")
|
||||
@ -95,11 +101,21 @@ async def _(
|
||||
if user := await LevelUser.get_or_none(user_id=uid, group_id=group_id):
|
||||
await user.delete()
|
||||
if session.level in [SessionLevel.LEVEL2, SessionLevel.LEVEL3]:
|
||||
await MessageFactory(
|
||||
[Text("成功删除 "), Mention(uid), Text(f" 的权限等级!")]
|
||||
).finish(reply=True)
|
||||
await Text(
|
||||
logger.info(
|
||||
f"删除权限: {user.user_level} -> 0",
|
||||
arparma.header_result,
|
||||
session=session,
|
||||
)
|
||||
await MessageUtils.build_message(
|
||||
["成功删除 ", At(flag="user", target=uid), f" 的权限等级!"]
|
||||
).finish(reply_to=True)
|
||||
logger.info(
|
||||
f"删除群组用户权限: {user.user_level} -> 0",
|
||||
arparma.header_result,
|
||||
session=session,
|
||||
)
|
||||
await MessageUtils.build_message(
|
||||
f"成功删除 \n群组:{group_id}\n用户:{uid} \n的权限等级!\n权限:{user.user_level} -> 0"
|
||||
).finish()
|
||||
await Text(f"对方目前暂无权限喔...").finish()
|
||||
await Text(f"设置权限时群组不能为空...").finish()
|
||||
await MessageUtils.build_message(f"对方目前暂无权限喔...").finish()
|
||||
await MessageUtils.build_message(f"设置权限时群组不能为空...").finish()
|
||||
|
||||
@ -3,12 +3,12 @@ from nonebot.permission import SUPERUSER
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot.rule import to_me
|
||||
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.platform import PlatformUtils
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
@ -60,12 +60,12 @@ async def _(
|
||||
arparma.header_result,
|
||||
session=session,
|
||||
)
|
||||
await Text(f"成功更新了 {num} 个群组的信息").send()
|
||||
await MessageUtils.build_message(f"成功更新了 {num} 个群组的信息").send()
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
"更新群组信息发生错误", arparma.header_result, session=session, e=e
|
||||
)
|
||||
await Text("其他未知错误...").send()
|
||||
await MessageUtils.build_message("其他未知错误...").send()
|
||||
|
||||
|
||||
@_friend_matcher.handle()
|
||||
@ -75,15 +75,15 @@ async def _(
|
||||
arparma: Arparma,
|
||||
):
|
||||
try:
|
||||
num = await PlatformUtils.update_friend(bot, session.platform)
|
||||
num = await PlatformUtils.update_friend(bot)
|
||||
logger.info(
|
||||
f"更新好友信息完成,共更新了 {num} 个好友的信息!",
|
||||
arparma.header_result,
|
||||
session=session,
|
||||
)
|
||||
await Text(f"成功更新了 {num} 个好友的信息").send()
|
||||
await MessageUtils.build_message(f"成功更新了 {num} 个好友的信息").send()
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
"更新好友信息发生错误", arparma.header_result, session=session, e=e
|
||||
)
|
||||
await Text("其他未知错误...").send()
|
||||
await MessageUtils.build_message("其他未知错误...").send()
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
from pathlib import Path
|
||||
|
||||
from nonebot import on_regex
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot.rule import to_me
|
||||
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name="识番",
|
||||
@ -38,5 +37,5 @@ async def _(session: EventSession, arparma: Arparma):
|
||||
项目地址:https://github.com/HibiKier/zhenxun_bot
|
||||
文档地址:https://hibikier.github.io/zhenxun_bot/
|
||||
""".strip()
|
||||
await Text(info).send()
|
||||
await MessageUtils.build_message(info).send()
|
||||
logger.info("查看关于", arparma.header_result, session=session)
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
from nonebot import on_regex
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from ._data_source import get_data
|
||||
|
||||
@ -43,11 +43,13 @@ _matcher.shortcut(
|
||||
async def _(session: EventSession, arparma: Arparma):
|
||||
data, code = await get_data(comments_163_url)
|
||||
if code != 200 and isinstance(data, str):
|
||||
await Text(data).finish(reply=True)
|
||||
await MessageUtils.build_message(data).finish(reply_to=True)
|
||||
data = data["data"] # type: ignore
|
||||
comment = data["comment_content"] # type: ignore
|
||||
song_name = data["title"] # type: ignore
|
||||
await Text(f"{comment}\n\t——《{song_name}》").send(reply=True)
|
||||
await MessageUtils.build_message(f"{comment}\n\t——《{song_name}》").send(
|
||||
reply_to=True
|
||||
)
|
||||
logger.info(
|
||||
f" 发送网易云热评: {comment} \n\t\t————{song_name}",
|
||||
arparma.header_result,
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from ._data_source import get_data
|
||||
|
||||
@ -36,13 +36,13 @@ async def _(session: EventSession, arparma: Arparma):
|
||||
try:
|
||||
data, code = await get_data(url)
|
||||
if code != 200 and isinstance(data, str):
|
||||
await Text(data).finish(reply=True)
|
||||
await Text(data["data"]["content"]).send(reply=True) # type: ignore
|
||||
await MessageUtils.build_message(data).finish(reply_to=True)
|
||||
await MessageUtils.build_message(data["data"]["content"]).send(reply_to=True) # type: ignore
|
||||
logger.info(
|
||||
f" 发送鸡汤:" + data["data"]["content"], # type:ignore
|
||||
arparma.header_result,
|
||||
session=session,
|
||||
)
|
||||
except Exception as e:
|
||||
await Text("鸡汤煮坏掉了...").send()
|
||||
await MessageUtils.build_message("鸡汤煮坏掉了...").send()
|
||||
logger.error(f"鸡汤煮坏掉了", e=e)
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from ._data_source import get_data
|
||||
|
||||
@ -42,12 +42,14 @@ poetry_url = "https://v2.alapi.cn/api/shici"
|
||||
async def _(session: EventSession, arparma: Arparma):
|
||||
data, code = await get_data(poetry_url)
|
||||
if code != 200 and isinstance(data, str):
|
||||
await Text(data).finish(reply=True)
|
||||
await MessageUtils.build_message(data).finish(reply_to=True)
|
||||
data = data["data"] # type: ignore
|
||||
content = data["content"] # type: ignore
|
||||
title = data["origin"] # type: ignore
|
||||
author = data["author"] # type: ignore
|
||||
await Text(f"{content}\n\t——{author}《{title}》").send(reply=True)
|
||||
await MessageUtils.build_message(f"{content}\n\t——{author}《{title}》").send(
|
||||
reply_to=True
|
||||
)
|
||||
logger.info(
|
||||
f" 发送古诗: f'{content}\n\t--{author}《{title}》'",
|
||||
arparma.header_result,
|
||||
|
||||
@ -3,11 +3,11 @@ from asyncio.exceptions import TimeoutError
|
||||
from httpx import ConnectTimeout
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot_plugin_alconna import Alconna, Args, Arparma, Match, on_alconna
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData, RegisterConfig
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.rules import ensure_private
|
||||
|
||||
from .data_source import get_bt_info
|
||||
@ -58,7 +58,7 @@ async def _(
|
||||
async for title, type_, create_time, file_size, link in get_bt_info(
|
||||
keyword, page.result if page.available else 1
|
||||
):
|
||||
await Text(
|
||||
await MessageUtils.build_message(
|
||||
f"标题:{title}\n"
|
||||
f"类型:{type_}\n"
|
||||
f"创建时间:{create_time}\n"
|
||||
@ -67,12 +67,12 @@ async def _(
|
||||
).send()
|
||||
send_flag = True
|
||||
except (TimeoutError, ConnectTimeout):
|
||||
await Text(f"搜索 {keyword} 超时...").finish()
|
||||
await MessageUtils.build_message(f"搜索 {keyword} 超时...").finish()
|
||||
except Exception as e:
|
||||
logger.error(f"bt 错误", arparma.header_result, session=session, e=e)
|
||||
await Text(f"bt 其他未知错误..").finish()
|
||||
await MessageUtils.build_message(f"bt 其他未知错误..").finish()
|
||||
if not send_flag:
|
||||
await Text(f"{keyword} 未搜索到...").send()
|
||||
await MessageUtils.build_message(f"{keyword} 未搜索到...").send()
|
||||
logger.info(
|
||||
f"BT搜索 {keyword} 第 {page} 页", arparma.header_result, session=session
|
||||
)
|
||||
|
||||
@ -2,7 +2,6 @@ from nonebot.permission import SUPERUSER
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot.rule import to_me
|
||||
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
|
||||
from nonebot_plugin_saa import Image
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
|
||||
@ -7,13 +7,13 @@ from nonebot_plugin_alconna import At as alcAt
|
||||
from nonebot_plugin_alconna import Target
|
||||
from nonebot_plugin_alconna import Text as alcText
|
||||
from nonebot_plugin_alconna import UniMsg
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
from nonebot_plugin_userinfo import EventUserInfo, UserInfo
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.models.group_console import GroupConsole
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.platform import PlatformUtils
|
||||
|
||||
from ._data_source import DialogueManage
|
||||
@ -69,9 +69,9 @@ async def _(
|
||||
if platform == "discord":
|
||||
superuser_id = config.platform_superusers["discord"][0]
|
||||
except IndexError:
|
||||
await Text("管理员失联啦...").finish()
|
||||
await MessageUtils.build_message("管理员失联啦...").finish()
|
||||
if not superuser_id:
|
||||
await Text("管理员失联啦...").finish()
|
||||
await MessageUtils.build_message("管理员失联啦...").finish()
|
||||
uname = user_info.user_displayname or user_info.user_name
|
||||
group_name = ""
|
||||
gid = session.id3 or session.id2
|
||||
@ -89,9 +89,9 @@ async def _(
|
||||
message.insert(0, alcText("*****一份交流报告*****\n"))
|
||||
DialogueManage.add(uname, session.id1, gid, group_name, message, platform)
|
||||
await message.send(bot=bot, target=Target(superuser_id, private=True))
|
||||
await Text("已成功发送给管理员啦!").send(reply=True)
|
||||
await MessageUtils.build_message("已成功发送给管理员啦!").send(reply_to=True)
|
||||
else:
|
||||
await Text("用户id为空...").send()
|
||||
await MessageUtils.build_message("用户id为空...").send()
|
||||
|
||||
|
||||
@_reply_matcher.handle()
|
||||
@ -99,7 +99,6 @@ async def _(
|
||||
bot: Bot,
|
||||
message: UniMsg,
|
||||
session: EventSession,
|
||||
user_info: UserInfo = EventUserInfo(),
|
||||
):
|
||||
message[0] = alcText(str(message[0]).replace("/t", "", 1).strip())
|
||||
if session.id1:
|
||||
@ -108,7 +107,7 @@ async def _(
|
||||
platform = PlatformUtils.get_platform(bot)
|
||||
data = DialogueManage._data
|
||||
if not data:
|
||||
await Text("暂无待回复消息...").finish()
|
||||
await MessageUtils.build_message("暂无待回复消息...").finish()
|
||||
if platform:
|
||||
data = [data[d] for d in data if data[d].platform == platform]
|
||||
for d in data:
|
||||
@ -127,7 +126,7 @@ async def _(
|
||||
user_id = model.user_id
|
||||
group_id = model.group_id
|
||||
else:
|
||||
return Text("未获取此id数据").finish()
|
||||
return MessageUtils.build_message("未获取此id数据").finish()
|
||||
message[0] = alcText(" ".join(str(message[0]).split(" ")[1:]))
|
||||
else:
|
||||
user_id = 0
|
||||
@ -137,7 +136,9 @@ async def _(
|
||||
" ".join(str(message[0]).split(" ")[2:])
|
||||
)
|
||||
else:
|
||||
await Text("群组id错误...").finish(at_sender=True)
|
||||
await MessageUtils.build_message("群组id错误...").finish(
|
||||
at_sender=True
|
||||
)
|
||||
DialogueManage.remove(_id)
|
||||
else:
|
||||
user_id = msg[0]
|
||||
@ -148,17 +149,17 @@ async def _(
|
||||
group_id = 0
|
||||
message[0] = alcText(" ".join(str(message[0]).split(" ")[1:]))
|
||||
else:
|
||||
await Text("参数错误...").finish(at_sender=True)
|
||||
await MessageUtils.build_message("参数错误...").finish(at_sender=True)
|
||||
if group_id:
|
||||
if user_id:
|
||||
message.insert(0, alcAt("user", user_id))
|
||||
message.insert(1, "\n管理员回复\n=======\n")
|
||||
await message.send(Target(group_id), bot)
|
||||
await Text("消息发送成功!").finish(at_sender=True)
|
||||
await MessageUtils.build_message("消息发送成功!").finish(at_sender=True)
|
||||
elif user_id:
|
||||
await message.send(Target(user_id, private=True), bot)
|
||||
await Text("消息发送成功!").finish(at_sender=True)
|
||||
await MessageUtils.build_message("消息发送成功!").finish(at_sender=True)
|
||||
else:
|
||||
await Text("群组id与用户id为空...").send()
|
||||
await MessageUtils.build_message("群组id与用户id为空...").send()
|
||||
else:
|
||||
await Text("用户id为空...").send()
|
||||
await MessageUtils.build_message("用户id为空...").send()
|
||||
|
||||
@ -13,11 +13,11 @@ from nonebot.permission import SUPERUSER
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot.typing import T_Handler
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from .handles.azur_handle import AzurHandle
|
||||
from .handles.ba_handle import BaHandle
|
||||
@ -165,13 +165,17 @@ def create_matchers():
|
||||
try:
|
||||
num = int(cn2an(num, mode="smart"))
|
||||
except ValueError:
|
||||
await Text("必!须!是!数!字!").finish(reply=True)
|
||||
await MessageUtils.build_message("必!须!是!数!字!").finish(
|
||||
reply_to=True
|
||||
)
|
||||
if unit == "井":
|
||||
num *= game.max_count
|
||||
if num < 1:
|
||||
await Text("虚空抽卡???").finish(reply=True)
|
||||
await MessageUtils.build_message("虚空抽卡???").finish(reply_to=True)
|
||||
elif num > game.max_count:
|
||||
await Text("一井都满不足不了你嘛!快爬开!").finish(reply=True)
|
||||
await MessageUtils.build_message(
|
||||
"一井都满不足不了你嘛!快爬开!"
|
||||
).finish(reply_to=True)
|
||||
pool_name = (
|
||||
pool_name.replace("池", "")
|
||||
.replace("武器", "arms")
|
||||
@ -192,7 +196,7 @@ def create_matchers():
|
||||
)
|
||||
except:
|
||||
logger.warning(traceback.format_exc())
|
||||
await Text("出错了...").finish(reply=True)
|
||||
await MessageUtils.build_message("出错了...").finish(reply_to=True)
|
||||
await res.send()
|
||||
|
||||
return handler
|
||||
@ -215,9 +219,9 @@ def create_matchers():
|
||||
def reset_handler(game: Game) -> T_Handler:
|
||||
async def handler(matcher: Matcher, session: EventSession):
|
||||
if not session.id1:
|
||||
await Text("获取用户id失败...").finish()
|
||||
await MessageUtils.build_message("获取用户id失败...").finish()
|
||||
if game.handle.reset_count(session.id1):
|
||||
await Text("重置成功!").send()
|
||||
await MessageUtils.build_message("重置成功!").send()
|
||||
|
||||
return handler
|
||||
|
||||
|
||||
@ -4,12 +4,13 @@ from urllib.parse import unquote
|
||||
import dateparser
|
||||
import ujson as json
|
||||
from lxml import etree
|
||||
from nonebot_plugin_saa import Image, MessageFactory, Text
|
||||
from nonebot_plugin_alconna import UniMessage
|
||||
from PIL import ImageDraw
|
||||
from pydantic import ValidationError
|
||||
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.image_utils import BuildImage
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from ..config import draw_config
|
||||
from ..util import cn2py, load_font, remove_prohibited_str
|
||||
@ -97,13 +98,13 @@ class AzurHandle(BaseHandle[AzurChar]):
|
||||
)
|
||||
return acquire_char
|
||||
|
||||
async def draw(self, count: int, **kwargs) -> MessageFactory:
|
||||
async def draw(self, count: int, **kwargs) -> UniMessage:
|
||||
index2card = self.get_cards(count, **kwargs)
|
||||
cards = [card[0] for card in index2card]
|
||||
up_list = [x.name for x in self.UP_EVENT.up_char] if self.UP_EVENT else []
|
||||
result = self.format_result(index2card, **{**kwargs, "up_list": up_list})
|
||||
gen_img = await self.generate_img(cards)
|
||||
return MessageFactory([Image(gen_img.pic2bytes()), Text(result)])
|
||||
return MessageUtils.build_message([gen_img.pic2bytes(), result])
|
||||
|
||||
async def generate_card_img(self, card: AzurChar) -> BuildImage:
|
||||
sep_w = 5
|
||||
@ -298,10 +299,10 @@ class AzurHandle(BaseHandle[AzurChar]):
|
||||
except Exception as e:
|
||||
logger.warning(f"{self.game_name_cn}UP更新出错", e=e)
|
||||
|
||||
async def _reload_pool(self) -> MessageFactory | None:
|
||||
async def _reload_pool(self) -> UniMessage | None:
|
||||
await self.update_up_char()
|
||||
self.load_up_char()
|
||||
if self.UP_EVENT:
|
||||
return MessageFactory(
|
||||
[Text(f"重载成功!\n当前活动:{self.UP_EVENT.title}")]
|
||||
return MessageUtils.build_message(
|
||||
f"重载成功!\n当前活动:{self.UP_EVENT.title}"
|
||||
)
|
||||
|
||||
@ -61,8 +61,10 @@ class BaHandle(BaseHandle[BaChar]):
|
||||
bar_h = 20
|
||||
bar_w = 90
|
||||
bg = BuildImage(img_w + sep_w * 2, img_h + font_h + sep_h * 2, color="#EFF2F5")
|
||||
img_path = str(self.img_path / f"{cn2py(card.name)}.png")
|
||||
img = BuildImage(img_w, img_h, background=img_path)
|
||||
img_path = self.img_path / f"{cn2py(card.name)}.png"
|
||||
img = BuildImage(
|
||||
img_w, img_h, background=img_path if img_path.exists() else None
|
||||
)
|
||||
bar = BuildImage(bar_w, bar_h, color="#6495ED")
|
||||
await bg.paste(img, (sep_w, sep_h))
|
||||
await bg.paste(bar, (sep_w, img_h - bar_h + sep_h))
|
||||
|
||||
@ -7,14 +7,14 @@ from typing import Generic, TypeVar
|
||||
import aiohttp
|
||||
import anyio
|
||||
import ujson as json
|
||||
from nonebot_plugin_saa import Image as SaaImage
|
||||
from nonebot_plugin_saa import MessageFactory, Text
|
||||
from nonebot_plugin_alconna import UniMessage
|
||||
from PIL import Image
|
||||
from pydantic import BaseModel, Extra
|
||||
|
||||
from zhenxun.configs.path_config import DATA_PATH
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.image_utils import BuildImage
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from ..config import DRAW_PATH, draw_config
|
||||
from ..util import circled_number, cn2py
|
||||
@ -64,12 +64,12 @@ class BaseHandle(Generic[TC]):
|
||||
self.up_path.mkdir(parents=True, exist_ok=True)
|
||||
self.data_files: list[str] = [f"{self.game_name}.json"]
|
||||
|
||||
async def draw(self, count: int, **kwargs) -> MessageFactory:
|
||||
async def draw(self, count: int, **kwargs) -> UniMessage:
|
||||
index2card = self.get_cards(count, **kwargs)
|
||||
cards = [card[0] for card in index2card]
|
||||
result = self.format_result(index2card)
|
||||
gen_img = await self.generate_img(cards)
|
||||
return MessageFactory([SaaImage(gen_img.pic2bytes()), Text(result)])
|
||||
return MessageUtils.build_message([gen_img, result])
|
||||
|
||||
# 抽取卡池
|
||||
def get_card(self, **kwargs) -> TC:
|
||||
@ -280,10 +280,10 @@ class BaseHandle(Generic[TC]):
|
||||
)
|
||||
return False
|
||||
|
||||
async def _reload_pool(self) -> MessageFactory | None:
|
||||
async def _reload_pool(self) -> UniMessage | None:
|
||||
return None
|
||||
|
||||
async def reload_pool(self) -> MessageFactory | None:
|
||||
async def reload_pool(self) -> UniMessage | None:
|
||||
try:
|
||||
async with self.client() as session:
|
||||
self.session = session
|
||||
|
||||
@ -5,13 +5,13 @@ from urllib.parse import unquote
|
||||
import dateparser
|
||||
import ujson as json
|
||||
from lxml import etree
|
||||
from nonebot_plugin_saa import Image as SaaImage
|
||||
from nonebot_plugin_saa import MessageFactory, Text
|
||||
from nonebot_plugin_alconna import UniMessage
|
||||
from PIL import Image, ImageDraw
|
||||
from pydantic import ValidationError
|
||||
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.image_utils import BuildImage
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from ..config import draw_config
|
||||
from ..count_manager import GenshinCountManager
|
||||
@ -218,7 +218,7 @@ class GenshinHandle(BaseHandle[GenshinData]):
|
||||
|
||||
async def draw(
|
||||
self, count: int, user_id: int, pool_name: str = "", **kwargs
|
||||
) -> Text | MessageFactory:
|
||||
) -> UniMessage:
|
||||
card_index = 0
|
||||
if "1" in pool_name:
|
||||
card_index = 1
|
||||
@ -228,7 +228,7 @@ class GenshinHandle(BaseHandle[GenshinData]):
|
||||
up_event = None
|
||||
if pool_name == "char":
|
||||
if card_index == 1 and len(self.UP_CHAR_LIST) == 1:
|
||||
return Text("当前没有第二个角色UP池")
|
||||
return MessageUtils.build_message("当前没有第二个角色UP池")
|
||||
up_event = self.UP_CHAR_LIST[card_index]
|
||||
elif pool_name == "arms":
|
||||
up_event = self.UP_ARMS
|
||||
@ -249,7 +249,7 @@ class GenshinHandle(BaseHandle[GenshinData]):
|
||||
(0, img.height + 10),
|
||||
"【五星:0.6%,四星:5.1%,第72抽开始五星概率每抽加0.585%】",
|
||||
)
|
||||
return MessageFactory([Text(pool_info), SaaImage(bk.pic2bytes()), Text(result)])
|
||||
return MessageUtils.build_message([pool_info, bk, result])
|
||||
|
||||
def _init_data(self):
|
||||
self.ALL_CHAR = [
|
||||
@ -439,27 +439,23 @@ class GenshinHandle(BaseHandle[GenshinData]):
|
||||
self.count_manager.reset(user_id)
|
||||
return True
|
||||
|
||||
async def _reload_pool(self) -> MessageFactory | None:
|
||||
async def _reload_pool(self) -> UniMessage | None:
|
||||
await self.update_up_char()
|
||||
self.load_up_char()
|
||||
if self.UP_CHAR_LIST and self.UP_ARMS:
|
||||
if len(self.UP_CHAR_LIST) > 1:
|
||||
return MessageFactory(
|
||||
return MessageUtils.build_message(
|
||||
[
|
||||
Text(
|
||||
f"重载成功!\n当前UP池子:{self.UP_CHAR_LIST[0].title} & {self.UP_CHAR_LIST[1].title} & {self.UP_ARMS.title}"
|
||||
),
|
||||
Image(self.UP_CHAR_LIST[0].pool_img),
|
||||
Image(self.UP_CHAR_LIST[1].pool_img),
|
||||
Image(self.UP_ARMS.pool_img),
|
||||
f"重载成功!\n当前UP池子:{self.UP_CHAR_LIST[0].title} & {self.UP_CHAR_LIST[1].title} & {self.UP_ARMS.title}",
|
||||
self.UP_CHAR_LIST[0].pool_img,
|
||||
self.UP_CHAR_LIST[1].pool_img,
|
||||
self.UP_ARMS.pool_img,
|
||||
]
|
||||
)
|
||||
return MessageFactory(
|
||||
return UniMessage(
|
||||
[
|
||||
Text(
|
||||
f"重载成功!\n当前UP池子:{char_title} & {self.UP_ARMS.title}"
|
||||
),
|
||||
Image(self.UP_CHAR_LIST[0].pool_img),
|
||||
Image(self.UP_ARMS.pool_img),
|
||||
f"重载成功!\n当前UP池子:{char_title} & {self.UP_ARMS.title}",
|
||||
self.UP_CHAR_LIST[0].pool_img,
|
||||
self.UP_ARMS.pool_img,
|
||||
]
|
||||
)
|
||||
|
||||
@ -6,12 +6,13 @@ from urllib.parse import unquote
|
||||
import dateparser
|
||||
import ujson as json
|
||||
from lxml import etree
|
||||
from nonebot_plugin_saa import Image, MessageFactory, Text
|
||||
from nonebot_plugin_alconna import UniMessage
|
||||
from PIL import ImageDraw
|
||||
from pydantic import ValidationError
|
||||
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.image_utils import BuildImage
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from ..config import draw_config
|
||||
from ..util import cn2py, load_font, remove_prohibited_str
|
||||
@ -132,7 +133,7 @@ class GuardianHandle(BaseHandle[GuardianData]):
|
||||
info = f"当前up池:{up_event.title}\n{info}"
|
||||
return info.strip()
|
||||
|
||||
async def draw(self, count: int, pool_name: str, **kwargs) -> MessageFactory:
|
||||
async def draw(self, count: int, pool_name: str, **kwargs) -> UniMessage:
|
||||
index2card = self.get_cards(count, pool_name)
|
||||
cards = [card[0] for card in index2card]
|
||||
up_event = self.UP_CHAR if pool_name == "char" else self.UP_ARMS
|
||||
@ -140,7 +141,7 @@ class GuardianHandle(BaseHandle[GuardianData]):
|
||||
result = self.format_result(index2card, up_list=up_list)
|
||||
pool_info = self.format_pool_info(pool_name)
|
||||
img = await self.generate_img(cards)
|
||||
return MessageFactory([Text(pool_info), Image(img.pic2bytes()), Text(result)])
|
||||
return MessageUtils.build_message([pool_info, img, result])
|
||||
|
||||
async def generate_card_img(self, card: GuardianData) -> BuildImage:
|
||||
sep_w = 1
|
||||
@ -390,10 +391,10 @@ class GuardianHandle(BaseHandle[GuardianData]):
|
||||
except Exception as e:
|
||||
logger.warning(f"{self.game_name_cn}UP更新出错 {type(e)}:{e}")
|
||||
|
||||
async def _reload_pool(self) -> MessageFactory | None:
|
||||
async def _reload_pool(self) -> UniMessage | None:
|
||||
await self.update_up_char()
|
||||
self.load_up_char()
|
||||
if self.UP_CHAR and self.UP_ARMS:
|
||||
return MessageFactory(
|
||||
[Text(f"重载成功!\n当前UP池子:{self.UP_CHAR.title}")]
|
||||
return MessageUtils.build_message(
|
||||
f"重载成功!\n当前UP池子:{self.UP_CHAR.title}"
|
||||
)
|
||||
|
||||
@ -7,12 +7,13 @@ import dateparser
|
||||
import ujson as json
|
||||
from bs4 import BeautifulSoup
|
||||
from lxml import etree
|
||||
from nonebot_plugin_saa import Image, MessageFactory, Text
|
||||
from nonebot_plugin_alconna import UniMessage
|
||||
from PIL import ImageDraw
|
||||
from pydantic import ValidationError
|
||||
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.image_utils import BuildImage
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from ..config import draw_config
|
||||
from ..util import cn2py, load_font, remove_prohibited_str
|
||||
@ -125,7 +126,7 @@ class PrettyHandle(BaseHandle[PrettyData]):
|
||||
info = f"当前up池:{up_event.title}\n{info}"
|
||||
return info.strip()
|
||||
|
||||
async def draw(self, count: int, pool_name: str, **kwargs) -> MessageFactory:
|
||||
async def draw(self, count: int, pool_name: str, **kwargs) -> UniMessage:
|
||||
pool_name = "char" if not pool_name else pool_name
|
||||
index2card = self.get_cards(count, pool_name)
|
||||
cards = [card[0] for card in index2card]
|
||||
@ -134,7 +135,7 @@ class PrettyHandle(BaseHandle[PrettyData]):
|
||||
result = self.format_result(index2card, up_list=up_list)
|
||||
pool_info = self.format_pool_info(pool_name)
|
||||
img = await self.generate_img(cards)
|
||||
return MessageFactory([Text(pool_info), Image(img.pic2bytes()), Text(result)])
|
||||
return MessageUtils.build_message([pool_info, img, result])
|
||||
|
||||
async def generate_card_img(self, card: PrettyData) -> BuildImage:
|
||||
if isinstance(card, PrettyChar):
|
||||
@ -409,14 +410,14 @@ class PrettyHandle(BaseHandle[PrettyData]):
|
||||
except Exception as e:
|
||||
logger.warning(f"{self.game_name_cn}UP更新出错", e=e)
|
||||
|
||||
async def _reload_pool(self) -> MessageFactory | None:
|
||||
async def _reload_pool(self) -> UniMessage | None:
|
||||
await self.update_up_char()
|
||||
self.load_up_char()
|
||||
if self.UP_CHAR and self.UP_CARD:
|
||||
return MessageFactory(
|
||||
return MessageUtils.build_message(
|
||||
[
|
||||
Text(f"重载成功!\n当前UP池子:{self.UP_CHAR.title}"),
|
||||
Image(self.UP_CHAR.pool_img),
|
||||
Image(self.UP_CARD.pool_img),
|
||||
f"重载成功!\n当前UP池子:{self.UP_CHAR.title}",
|
||||
self.UP_CHAR.pool_img,
|
||||
self.UP_CARD.pool_img,
|
||||
]
|
||||
)
|
||||
|
||||
@ -7,12 +7,13 @@ import dateparser
|
||||
import ujson as json
|
||||
from lxml import etree
|
||||
from lxml.etree import _Element
|
||||
from nonebot_plugin_saa import Image, MessageFactory, Text
|
||||
from nonebot_plugin_alconna import UniMessage
|
||||
from PIL import ImageDraw
|
||||
from pydantic import ValidationError
|
||||
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.image_utils import BuildImage
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from ..config import draw_config
|
||||
from ..util import cn2py, load_font, remove_prohibited_str
|
||||
@ -102,7 +103,7 @@ class PrtsHandle(BaseHandle[Operator]):
|
||||
info = f"当前up池: {self.UP_EVENT.title}\n{info}"
|
||||
return info.strip()
|
||||
|
||||
async def draw(self, count: int, **kwargs) -> MessageFactory:
|
||||
async def draw(self, count: int, **kwargs) -> UniMessage:
|
||||
index2card = self.get_cards(count)
|
||||
"""这里cards修复了抽卡图文不符的bug"""
|
||||
cards = [card[0] for card in index2card]
|
||||
@ -110,7 +111,7 @@ class PrtsHandle(BaseHandle[Operator]):
|
||||
result = self.format_result(index2card, up_list=up_list)
|
||||
pool_info = self.format_pool_info()
|
||||
img = await self.generate_img(cards)
|
||||
return MessageFactory([Text(pool_info), Image(img.pic2bytes()), Text(result)])
|
||||
return MessageUtils.build_message([pool_info, img, result])
|
||||
|
||||
async def generate_card_img(self, card: Operator) -> BuildImage:
|
||||
sep_w = 5
|
||||
@ -331,13 +332,13 @@ class PrtsHandle(BaseHandle[Operator]):
|
||||
)
|
||||
break
|
||||
|
||||
async def _reload_pool(self) -> MessageFactory | None:
|
||||
async def _reload_pool(self) -> UniMessage | None:
|
||||
await self.update_up_char()
|
||||
self.load_up_char()
|
||||
if self.UP_EVENT:
|
||||
return MessageFactory(
|
||||
return MessageUtils.build_message(
|
||||
[
|
||||
Text(f"重载成功!\n当前UP池子:{self.UP_EVENT.title}"),
|
||||
Image(self.UP_EVENT.pool_img),
|
||||
f"重载成功!\n当前UP池子:{self.UP_EVENT.title}",
|
||||
self.UP_EVENT.pool_img,
|
||||
]
|
||||
)
|
||||
|
||||
@ -2,13 +2,12 @@ from nonebot.adapters import Bot
|
||||
from nonebot.adapters.onebot.v11 import Bot as v11Bot
|
||||
from nonebot.adapters.onebot.v12 import Bot as v12Bot
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot_plugin_saa import MessageFactory, Text
|
||||
from nonebot_plugin_alconna import Alconna, Arparma, UniMessage, on_alconna
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from .data_source import get_epic_free
|
||||
|
||||
@ -33,9 +32,9 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma):
|
||||
type_ = "Group" if gid else "Private"
|
||||
msg_list, code = await get_epic_free(bot, type_)
|
||||
if code == 404 and isinstance(msg_list, str):
|
||||
await Text(msg_list).finish()
|
||||
await MessageUtils.build_message(msg_list).finish()
|
||||
elif isinstance(bot, (v11Bot, v12Bot)) and isinstance(msg_list, list):
|
||||
await bot.send_group_forward_msg(group_id=gid, messages=msg_list)
|
||||
elif isinstance(msg_list, MessageFactory):
|
||||
elif isinstance(msg_list, UniMessage):
|
||||
await msg_list.send()
|
||||
logger.info(f"获取epic免费游戏", arparma.header_result, session=session)
|
||||
|
||||
@ -113,7 +113,7 @@ async def _(message: UniMsg, event: Event, session: EventSession):
|
||||
if not plain_text and not image_list:
|
||||
return
|
||||
if plain_text and plain_text.startswith(f"@可爱的{NICKNAME}"):
|
||||
await MessageUtils.build_message("复制粘贴的虚空艾特?").send(reply=True)
|
||||
await MessageUtils.build_message("复制粘贴的虚空艾特?").send(reply_to=True)
|
||||
if image_list:
|
||||
img_hash = await get_download_image_hash(image_list[0], group_id)
|
||||
else:
|
||||
|
||||
@ -10,7 +10,6 @@ from nonebot.plugin import PluginMetadata
|
||||
from nonebot.rule import to_me
|
||||
from nonebot_plugin_alconna import Alconna, Args, Arparma, At, Match, Option, on_alconna
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot_plugin_saa import Image, MessageFactory, Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import NICKNAME
|
||||
@ -219,7 +218,7 @@ async def _(
|
||||
if send_msg
|
||||
else MessageUtils.build_message("没有红包给你开!")
|
||||
)
|
||||
await send_msg.send(reply=True)
|
||||
await send_msg.send(reply_to=True)
|
||||
if settlement_list:
|
||||
for red_bag in settlement_list:
|
||||
result_image = await red_bag.build_amount_rank(
|
||||
@ -263,7 +262,7 @@ async def _(
|
||||
f"已成功退还了 " f"{data[0]} 金币\n",
|
||||
image_result,
|
||||
]
|
||||
).finish(reply=True)
|
||||
).finish(reply_to=True)
|
||||
await MessageUtils.build_message("目前没有红包可以退回...").finish(reply_to=True)
|
||||
|
||||
|
||||
@ -297,16 +296,14 @@ async def _(
|
||||
FestiveRedBagManage.remove(festive_red_bag.uuid)
|
||||
rank_image = await festive_red_bag.build_amount_rank(10, platform)
|
||||
try:
|
||||
await MessageFactory(
|
||||
await MessageUtils.build_message(
|
||||
[
|
||||
Text(
|
||||
f"{NICKNAME}的节日红包过时了,一共开启了 "
|
||||
f"{len(festive_red_bag.open_user)}"
|
||||
f" 个红包,共 {sum(festive_red_bag.open_user.values())} 金币\n"
|
||||
),
|
||||
Image(rank_image.pic2bytes()),
|
||||
f"{NICKNAME}的节日红包过时了,一共开启了 "
|
||||
f"{len(festive_red_bag.open_user)}"
|
||||
f" 个红包,共 {sum(festive_red_bag.open_user.values())} 金币\n",
|
||||
rank_image,
|
||||
]
|
||||
).send_to(target=target, bot=bot)
|
||||
).send(target=target, bot=bot)
|
||||
except ActionFailed:
|
||||
pass
|
||||
try:
|
||||
@ -336,14 +333,12 @@ async def _(
|
||||
image_result = await RedBagManager.random_red_bag_background(
|
||||
bot.self_id, greetings, session.platform
|
||||
)
|
||||
await MessageFactory(
|
||||
await MessageUtils.build_message(
|
||||
[
|
||||
Text(
|
||||
f"{NICKNAME}发起了节日金币红包\n金额: {amount}\n数量: {num}\n"
|
||||
),
|
||||
Image(image_result.pic2bytes()),
|
||||
f"{NICKNAME}发起了节日金币红包\n金额: {amount}\n数量: {num}\n",
|
||||
image_result,
|
||||
]
|
||||
).send_to(target=target, bot=bot)
|
||||
).send(target=target, bot=bot)
|
||||
_suc_cnt += 1
|
||||
logger.debug("节日红包图片信息发送成功...", "节日红包", group_id=g)
|
||||
except ActionFailed:
|
||||
|
||||
@ -6,16 +6,16 @@ from typing import Dict
|
||||
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.exception import ActionFailed
|
||||
from nonebot_plugin_saa import Image, MessageFactory, Text
|
||||
from nonebot_plugin_alconna import UniMessage
|
||||
|
||||
from zhenxun.configs.config import NICKNAME, Config
|
||||
from zhenxun.configs.path_config import IMAGE_PATH
|
||||
from zhenxun.models.user_console import UserConsole
|
||||
from zhenxun.utils.image_utils import BuildImage
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.platform import PlatformUtils
|
||||
from zhenxun.utils.utils import get_user_avatar
|
||||
|
||||
from .config import FESTIVE_KEY, FestiveRedBagManage, GroupRedBag, RedBag
|
||||
from .config import FestiveRedBagManage, GroupRedBag, RedBag
|
||||
|
||||
|
||||
class RedBagManager:
|
||||
@ -56,16 +56,14 @@ class RedBagManager:
|
||||
FestiveRedBagManage.remove(red_bag.uuid)
|
||||
await asyncio.sleep(random.randint(1, 5))
|
||||
try:
|
||||
await MessageFactory(
|
||||
await MessageUtils.build_message(
|
||||
[
|
||||
Text(
|
||||
f"{NICKNAME}的节日红包过时了,一共开启了 "
|
||||
f"{len(red_bag.open_user)}"
|
||||
f" 个红包,共 {sum(red_bag.open_user.values())} 金币\n"
|
||||
),
|
||||
Image(rank_image.pic2bytes()),
|
||||
f"{NICKNAME}的节日红包过时了,一共开启了 "
|
||||
f"{len(red_bag.open_user)}"
|
||||
f" 个红包,共 {sum(red_bag.open_user.values())} 金币\n",
|
||||
rank_image,
|
||||
]
|
||||
).send_to(target=target, bot=bot)
|
||||
).send(target=target, bot=bot)
|
||||
except ActionFailed:
|
||||
pass
|
||||
|
||||
@ -76,7 +74,7 @@ class RedBagManager:
|
||||
user_id: str | None = None,
|
||||
is_festive: bool = False,
|
||||
platform: str = "",
|
||||
) -> MessageFactory | None:
|
||||
) -> UniMessage | None:
|
||||
"""结算红包
|
||||
|
||||
参数:
|
||||
@ -92,14 +90,12 @@ class RedBagManager:
|
||||
if is_festive:
|
||||
if festive_red_bag := group_red_bag.festive_red_bag_expire():
|
||||
rank_image = await festive_red_bag.build_amount_rank(rank_num, platform)
|
||||
return MessageFactory(
|
||||
return MessageUtils.build_message(
|
||||
[
|
||||
Text(
|
||||
f"{NICKNAME}的节日红包过时了,一共开启了 "
|
||||
f"{len(festive_red_bag.open_user)}"
|
||||
f" 个红包,共 {sum(festive_red_bag.open_user.values())} 金币\n"
|
||||
),
|
||||
Image(rank_image.pic2bytes()),
|
||||
f"{NICKNAME}的节日红包过时了,一共开启了 "
|
||||
f"{len(festive_red_bag.open_user)}"
|
||||
f" 个红包,共 {sum(festive_red_bag.open_user.values())} 金币\n",
|
||||
rank_image,
|
||||
]
|
||||
)
|
||||
else:
|
||||
@ -108,10 +104,10 @@ class RedBagManager:
|
||||
return_gold, red_bag = await group_red_bag.settlement(user_id, platform)
|
||||
if red_bag:
|
||||
rank_image = await red_bag.build_amount_rank(rank_num, platform)
|
||||
return MessageFactory(
|
||||
return MessageUtils.build_message(
|
||||
[
|
||||
Text(f"已成功退还了 " f"{return_gold} 金币\n"),
|
||||
Image(rank_image.pic2bytes()),
|
||||
f"已成功退还了 " f"{return_gold} 金币\n",
|
||||
rank_image.pic2bytes(),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.typing import T_State
|
||||
from nonebot_plugin_alconna import Alconna, Args, Arparma, Match, UniMessage, on_alconna
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from ._data_source import ImageManagementManage
|
||||
|
||||
@ -43,16 +42,13 @@ _matcher = on_alconna(
|
||||
|
||||
@_matcher.handle()
|
||||
async def _(
|
||||
bot: Bot,
|
||||
session: EventSession,
|
||||
arparma: Arparma,
|
||||
name: Match[str],
|
||||
index: Match[str],
|
||||
state: T_State,
|
||||
):
|
||||
image_dir_list = base_config.get("IMAGE_DIR_LIST")
|
||||
if not image_dir_list:
|
||||
await Text("未发现任何图库").finish()
|
||||
await MessageUtils.build_message("未发现任何图库").finish()
|
||||
_text = ""
|
||||
for i, dir in enumerate(image_dir_list):
|
||||
_text += f"{i}. {dir}\n"
|
||||
@ -71,7 +67,7 @@ async def _(
|
||||
)
|
||||
async def _(name: str):
|
||||
if name in ["取消", "算了"]:
|
||||
await Text("已取消操作...").finish()
|
||||
await MessageUtils.build_message("已取消操作...").finish()
|
||||
image_dir_list = base_config.get("IMAGE_DIR_LIST")
|
||||
if name.isdigit():
|
||||
index = int(name)
|
||||
@ -89,14 +85,14 @@ async def _(
|
||||
index: str,
|
||||
):
|
||||
if index in ["取消", "算了"]:
|
||||
await Text("已取消操作...").finish()
|
||||
await MessageUtils.build_message("已取消操作...").finish()
|
||||
if not index.isdigit():
|
||||
await _matcher.reject_path("index", "图片id需要输入数字...")
|
||||
name = _matcher.get_path_arg("name", None)
|
||||
if not name:
|
||||
await Text("图库名称为空...").finish()
|
||||
await MessageUtils.build_message("图库名称为空...").finish()
|
||||
if not session.id1:
|
||||
await Text("用户id为空...").finish()
|
||||
await MessageUtils.build_message("用户id为空...").finish()
|
||||
if file_name := await ImageManagementManage.delete_image(
|
||||
name, int(index), session.id1, session.platform
|
||||
):
|
||||
@ -105,5 +101,7 @@ async def _(
|
||||
arparma.header_result,
|
||||
session=session,
|
||||
)
|
||||
await Text(f"删除图片成功!\n图库: {name}\n名称: {index}.jpg").finish()
|
||||
await Text("图片删除失败...").finish()
|
||||
await MessageUtils.build_message(
|
||||
f"删除图片成功!\n图库: {name}\n名称: {index}.jpg"
|
||||
).finish()
|
||||
await MessageUtils.build_message("图片删除失败...").finish()
|
||||
|
||||
@ -3,13 +3,13 @@ from nonebot.plugin import PluginMetadata
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.typing import T_State
|
||||
from nonebot_plugin_alconna import Alconna, Args, Arparma, Match, UniMessage, on_alconna
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from ._data_source import ImageManagementManage
|
||||
|
||||
@ -53,7 +53,7 @@ async def _(
|
||||
):
|
||||
image_dir_list = base_config.get("IMAGE_DIR_LIST")
|
||||
if not image_dir_list:
|
||||
await Text("未发现任何图库").finish()
|
||||
await MessageUtils.build_message("未发现任何图库").finish()
|
||||
_text = ""
|
||||
for i, dir in enumerate(image_dir_list):
|
||||
_text += f"{i}. {dir}\n"
|
||||
@ -74,7 +74,7 @@ async def _(
|
||||
)
|
||||
async def _(source: str):
|
||||
if source in ["取消", "算了"]:
|
||||
await Text("已取消操作...").finish()
|
||||
await MessageUtils.build_message("已取消操作...").finish()
|
||||
image_dir_list = base_config.get("IMAGE_DIR_LIST")
|
||||
if source.isdigit():
|
||||
index = int(source)
|
||||
@ -93,8 +93,9 @@ async def _(source: str):
|
||||
)
|
||||
async def _(destination: str):
|
||||
if destination in ["取消", "算了"]:
|
||||
await Text("已取消操作...").finish()
|
||||
await MessageUtils.build_message("已取消操作...").finish()
|
||||
image_dir_list = base_config.get("IMAGE_DIR_LIST")
|
||||
name = None
|
||||
if destination.isdigit():
|
||||
index = int(destination)
|
||||
if index <= len(image_dir_list) - 1:
|
||||
@ -111,17 +112,17 @@ async def _(
|
||||
index: str,
|
||||
):
|
||||
if index in ["取消", "算了"]:
|
||||
await Text("已取消操作...").finish()
|
||||
await MessageUtils.build_message("已取消操作...").finish()
|
||||
if not index.isdigit():
|
||||
await _matcher.reject_path("index", "图片id需要输入数字...")
|
||||
source = _matcher.get_path_arg("source", None)
|
||||
destination = _matcher.get_path_arg("destination", None)
|
||||
if not source:
|
||||
await Text("图库名称为空...").finish()
|
||||
await MessageUtils.build_message("转出图库名称为空...").finish()
|
||||
if not destination:
|
||||
await Text("图库名称为空...").finish()
|
||||
await MessageUtils.build_message("转入图库名称为空...").finish()
|
||||
if not session.id1:
|
||||
await Text("用户id为空...").finish()
|
||||
await MessageUtils.build_message("用户id为空...").finish()
|
||||
if file_name := await ImageManagementManage.move_image(
|
||||
source, destination, int(index), session.id1, session.platform
|
||||
):
|
||||
@ -130,5 +131,7 @@ async def _(
|
||||
arparma.header_result,
|
||||
session=session,
|
||||
)
|
||||
await Text(f"移动图片成功!\n图库: {source} -> {destination}").finish()
|
||||
await Text("图片删除失败...").finish()
|
||||
await MessageUtils.build_message(
|
||||
f"移动图片成功!\n图库: {source} -> {destination}"
|
||||
).finish()
|
||||
await MessageUtils.build_message("图片删除失败...").finish()
|
||||
|
||||
@ -1,14 +1,10 @@
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.params import Arg, ArgStr, CommandArg
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.utils import P
|
||||
from nonebot_plugin_alconna import Alconna, Args, Arparma
|
||||
from nonebot_plugin_alconna import Image as alcImage
|
||||
from nonebot_plugin_alconna import Match, UniMessage, UniMsg, image_fetch, on_alconna
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import Config
|
||||
@ -16,6 +12,7 @@ from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.http_utils import AsyncHttpx
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from ._data_source import ImageManagementManage
|
||||
|
||||
@ -60,11 +57,11 @@ _show_matcher = on_alconna(Alconna("查看公开图库"), priority=1, block=True
|
||||
async def _():
|
||||
image_dir_list = base_config.get("IMAGE_DIR_LIST")
|
||||
if not image_dir_list:
|
||||
await Text("未发现任何图库").finish()
|
||||
await MessageUtils.build_message("未发现任何图库").finish()
|
||||
text = "公开图库列表:\n"
|
||||
for i, e in enumerate(image_dir_list):
|
||||
text += f"\t{i+1}.{e}\n"
|
||||
await Text(text[:-1]).send()
|
||||
await MessageUtils.build_message(text[:-1]).send()
|
||||
|
||||
|
||||
@_upload_matcher.handle()
|
||||
@ -78,7 +75,7 @@ async def _(
|
||||
):
|
||||
image_dir_list = base_config.get("IMAGE_DIR_LIST")
|
||||
if not image_dir_list:
|
||||
await Text("未发现任何图库").finish()
|
||||
await MessageUtils.build_message("未发现任何图库").finish()
|
||||
_text = ""
|
||||
for i, dir in enumerate(image_dir_list):
|
||||
_text += f"{i}. {dir}\n"
|
||||
@ -94,7 +91,7 @@ async def _(
|
||||
async def _(bot: Bot, state: T_State, name: Match[str]):
|
||||
image_dir_list = base_config.get("IMAGE_DIR_LIST")
|
||||
if not image_dir_list:
|
||||
await Text("未发现任何图库").finish()
|
||||
await MessageUtils.build_message("未发现任何图库").finish()
|
||||
_text = ""
|
||||
for i, dir in enumerate(image_dir_list):
|
||||
_text += f"{i}. {dir}\n"
|
||||
@ -117,7 +114,7 @@ async def _(bot: Bot, state: T_State, name: Match[str]):
|
||||
)
|
||||
async def _(name: str, state: T_State):
|
||||
if name in ["取消", "算了"]:
|
||||
await Text("已取消操作...").finish()
|
||||
await MessageUtils.build_message("已取消操作...").finish()
|
||||
image_dir_list = base_config.get("IMAGE_DIR_LIST")
|
||||
if name.isdigit():
|
||||
index = int(name)
|
||||
@ -137,9 +134,9 @@ async def _(
|
||||
):
|
||||
name = _upload_matcher.get_path_arg("name", None)
|
||||
if not name:
|
||||
await Text("图库名称为空...").finish()
|
||||
await MessageUtils.build_message("图库名称为空...").finish()
|
||||
if not session.id1:
|
||||
await Text("用户id为空...").finish()
|
||||
await MessageUtils.build_message("用户id为空...").finish()
|
||||
if file_name := await ImageManagementManage.upload_image(
|
||||
img, name, session.id1, session.platform
|
||||
):
|
||||
@ -148,8 +145,10 @@ async def _(
|
||||
arparma.header_result,
|
||||
session=session,
|
||||
)
|
||||
await Text(f"上传图片成功!\n图库: {name}\n名称: {file_name}").finish()
|
||||
await Text("图片上传失败...").finish()
|
||||
await MessageUtils.build_message(
|
||||
f"上传图片成功!\n图库: {name}\n名称: {file_name}"
|
||||
).finish()
|
||||
await MessageUtils.build_message("图片上传失败...").finish()
|
||||
|
||||
|
||||
@_continuous_upload_matcher.got(
|
||||
@ -164,21 +163,21 @@ async def _(
|
||||
):
|
||||
name = _continuous_upload_matcher.get_path_arg("name", None)
|
||||
if not name:
|
||||
await Text("图库名称为空...").finish()
|
||||
await MessageUtils.build_message("图库名称为空...").finish()
|
||||
if not session.id1:
|
||||
await Text("用户id为空...").finish()
|
||||
await MessageUtils.build_message("用户id为空...").finish()
|
||||
if not state.get("img_list"):
|
||||
state["img_list"] = []
|
||||
msg = message.extract_plain_text().strip().replace(arparma.header_result, "", 1)
|
||||
if msg in ["取消", "算了"]:
|
||||
await Text("已取消操作...").finish()
|
||||
await MessageUtils.build_message("已取消操作...").finish()
|
||||
if msg != "stop":
|
||||
for msg in message:
|
||||
if isinstance(msg, alcImage):
|
||||
state["img_list"].append(msg.url)
|
||||
await _continuous_upload_matcher.reject("图再来!!【发送‘stop’为停止】")
|
||||
if state["img_list"]:
|
||||
await Text("正在下载, 请稍后...").send()
|
||||
await MessageUtils.build_message("正在下载, 请稍后...").send()
|
||||
file_list = []
|
||||
for img in state["img_list"]:
|
||||
if file_name := await ImageManagementManage.upload_image(
|
||||
@ -190,7 +189,7 @@ async def _(
|
||||
"上传图片",
|
||||
session=session,
|
||||
)
|
||||
await Text(
|
||||
await MessageUtils.build_message(
|
||||
f"上传图片成功!共上传了{len(file_list)}张图片\n图库: {name}\n名称: {', '.join(file_list)}"
|
||||
).finish()
|
||||
await Text("图片上传失败...").finish()
|
||||
await MessageUtils.build_message("图片上传失败...").finish()
|
||||
|
||||
@ -3,7 +3,6 @@ from nonebot.adapters import Bot
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot_plugin_alconna import Image as alcImage
|
||||
from nonebot_plugin_alconna import UniMsg
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import NICKNAME
|
||||
@ -11,6 +10,7 @@ from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.image_utils import get_download_image_hash
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.platform import PlatformUtils
|
||||
|
||||
from ._data_source import mute_manage
|
||||
@ -44,9 +44,9 @@ async def _(bot: Bot, session: EventSession, message: UniMsg):
|
||||
if duration := mute_manage.add_message(session.id1, group_id, _message):
|
||||
try:
|
||||
await PlatformUtils.ban_user(bot, session.id1, group_id, duration)
|
||||
await Text(f"检测到恶意刷屏,{NICKNAME}要把你关进小黑屋!").send(
|
||||
at_sender=True
|
||||
)
|
||||
await MessageUtils.build_message(
|
||||
f"检测到恶意刷屏,{NICKNAME}要把你关进小黑屋!"
|
||||
).send(at_sender=True)
|
||||
mute_manage.reset(session.id1, group_id)
|
||||
logger.info(f"检测刷屏 被禁言 {duration} 分钟", "禁言检查", session=session)
|
||||
except Exception as e:
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot_plugin_alconna import Alconna, Args, Arparma, Match, Option, on_alconna
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import NICKNAME
|
||||
from zhenxun.configs.utils import PluginExtraData, RegisterConfig
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.rules import ensure_group
|
||||
|
||||
from ._data_source import base_config, mute_manage
|
||||
@ -96,19 +96,19 @@ async def _(
|
||||
_duration = duration.result if duration.available else None
|
||||
group_data = mute_manage.get_group_data(group_id)
|
||||
if _time is None and _count is None and _duration is None:
|
||||
await Text(
|
||||
await MessageUtils.build_message(
|
||||
f"最大次数:{group_data.count} 次\n"
|
||||
f"规定时间:{group_data.time} 秒\n"
|
||||
f"禁言时长:{group_data.duration:.2f} 分钟\n"
|
||||
f"【在规定时间内发送相同消息超过最大次数则禁言\n当禁言时长为0时关闭此功能】"
|
||||
).finish(reply=True)
|
||||
).finish(reply_to=True)
|
||||
if _time is not None:
|
||||
group_data.time = _time
|
||||
if _count is not None:
|
||||
group_data.count = _count
|
||||
if _duration is not None:
|
||||
group_data.duration = _duration
|
||||
await Text("设置成功!").send(reply=True)
|
||||
await MessageUtils.build_message("设置成功!").send(reply_to=True)
|
||||
logger.info(
|
||||
f"设置禁言配置 time: {_time}, count: {_count}, duration: {_duration}",
|
||||
arparma.header_result,
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import ujson as json
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot_plugin_alconna import Alconna, Args, Arparma, on_alconna
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.http_utils import AsyncHttpx
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name="能不能好好说话",
|
||||
@ -16,6 +16,8 @@ __plugin_meta__ = PluginMetadata(
|
||||
指令:
|
||||
nbnhhsh [文本]
|
||||
能不能好好说话 [文本]
|
||||
示例:
|
||||
nbnhhsh xsx
|
||||
""".strip(),
|
||||
extra=PluginExtraData(author="HibiKier", version="0.1", aliases={"nbnhhsh"}).dict(),
|
||||
)
|
||||
@ -55,6 +57,6 @@ async def _(session: EventSession, arparma: Arparma, text: str):
|
||||
arparma.header_result,
|
||||
session=session,
|
||||
)
|
||||
await Text(f"{tmp}={result}").send(reply=True)
|
||||
await MessageUtils.build_message(f"{tmp}={result}").send(reply_to=True)
|
||||
except (IndexError, KeyError):
|
||||
await Text("没有找到对应的翻译....").send()
|
||||
await MessageUtils.build_message("没有找到对应的翻译....").send()
|
||||
|
||||
@ -8,11 +8,11 @@ from nonebot_plugin_alconna import (
|
||||
on_alconna,
|
||||
store_true,
|
||||
)
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from ._data_source import uid_pid_exists
|
||||
from ._model.pixiv import Pixiv
|
||||
@ -65,12 +65,12 @@ async def _(bot: Bot, session: EventSession, keyword: str, arparma: Arparma):
|
||||
text = f"已成功添加pixiv搜图关键词:{keyword}"
|
||||
if session.id1 not in bot.config.superusers:
|
||||
text += ",请等待管理员通过该关键词!"
|
||||
await Text(text).send(reply=True)
|
||||
await MessageUtils.build_message(text).send(reply_to=True)
|
||||
logger.info(
|
||||
f"添加了pixiv搜图关键词: {keyword}", arparma.header_result, session=session
|
||||
)
|
||||
else:
|
||||
await Text(f"该关键词 {keyword} 已存在...").send()
|
||||
await MessageUtils.build_message(f"该关键词 {keyword} 已存在...").send()
|
||||
|
||||
|
||||
@_uid_matcher.handle()
|
||||
@ -85,9 +85,13 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma, add_type: str, id
|
||||
else:
|
||||
word = f"pid:{id}"
|
||||
if await Pixiv.get_or_none(pid=int(id), img_p="p0"):
|
||||
await Text(f"该PID:{id}已存在...").finish(reply=True)
|
||||
await MessageUtils.build_message(f"该PID:{id}已存在...").finish(
|
||||
reply_to=True
|
||||
)
|
||||
if not await uid_pid_exists(word) and exists_flag:
|
||||
await Text("画师或作品不存在或搜索正在CD,请稍等...").finish(reply=True)
|
||||
await MessageUtils.build_message(
|
||||
"画师或作品不存在或搜索正在CD,请稍等..."
|
||||
).finish(reply_to=True)
|
||||
if not await PixivKeywordUser.exists(keyword=word):
|
||||
await PixivKeywordUser.create(
|
||||
user_id=session.id1,
|
||||
@ -98,9 +102,9 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma, add_type: str, id
|
||||
text = f"已成功添加pixiv搜图UID/PID:{id}"
|
||||
if session.id1 not in bot.config.superusers:
|
||||
text += ",请等待管理员通过该关键词!"
|
||||
await Text(text).send(reply=True)
|
||||
await MessageUtils.build_message(text).send(reply_to=True)
|
||||
else:
|
||||
await Text(f"该UID/PID:{id} 已存在...").send()
|
||||
await MessageUtils.build_message(f"该UID/PID:{id} 已存在...").send()
|
||||
|
||||
|
||||
@_black_matcher.handle()
|
||||
@ -111,7 +115,7 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma, pid: str):
|
||||
pid = pid.replace("_", "")
|
||||
pid = pid[: pid.find("p")]
|
||||
if not pid.isdigit:
|
||||
await Text("PID必须全部是数字!").finish(reply=True)
|
||||
await MessageUtils.build_message("PID必须全部是数字!").finish(reply_to=True)
|
||||
if not await PixivKeywordUser.exists(
|
||||
keyword=f"black:{pid}{f'_p{img_p}' if img_p else ''}"
|
||||
):
|
||||
@ -121,9 +125,11 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma, pid: str):
|
||||
keyword=f"black:{pid}{f'_p{img_p}' if img_p else ''}",
|
||||
is_pass=session.id1 in bot.config.superusers,
|
||||
)
|
||||
await Text(f"已添加PID:{pid} 至黑名单中...").send()
|
||||
await MessageUtils.build_message(f"已添加PID:{pid} 至黑名单中...").send()
|
||||
logger.info(
|
||||
f" 添加了pixiv搜图黑名单 PID:{pid}", arparma.header_result, session=session
|
||||
)
|
||||
else:
|
||||
await Text(f"PID:{pid} 已添加黑名单中,添加失败...").send()
|
||||
await MessageUtils.build_message(
|
||||
f"PID:{pid} 已添加黑名单中,添加失败..."
|
||||
).send()
|
||||
|
||||
@ -5,17 +5,18 @@ from nonebot_plugin_alconna import (
|
||||
Alconna,
|
||||
Args,
|
||||
Arparma,
|
||||
At,
|
||||
Match,
|
||||
Option,
|
||||
on_alconna,
|
||||
store_true,
|
||||
)
|
||||
from nonebot_plugin_saa import Mention, MessageFactory, Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.platform import PlatformUtils
|
||||
|
||||
from ._data_source import remove_image
|
||||
@ -89,7 +90,9 @@ async def _(
|
||||
else:
|
||||
keyword = f"pid:{keyword}"
|
||||
if not keyword[4:].isdigit():
|
||||
await Text(f"{keyword} 非全数字...").finish(reply=True)
|
||||
await MessageUtils.build_message(f"{keyword} 非全数字...").finish(
|
||||
reply_to=True
|
||||
)
|
||||
data = await PixivKeywordUser.get_or_none(keyword=keyword)
|
||||
user_id = 0
|
||||
group_id = 0
|
||||
@ -98,9 +101,9 @@ async def _(
|
||||
await data.save(update_fields=["is_pass"])
|
||||
user_id, group_id = data.user_id, data.group_id
|
||||
if not user_id:
|
||||
await Text(f"未找到关键词/UID:{keyword},请检查关键词/UID是否存在...").finish(
|
||||
reply=True
|
||||
)
|
||||
await MessageUtils.build_message(
|
||||
f"未找到关键词/UID:{keyword},请检查关键词/UID是否存在..."
|
||||
).finish(reply_to=True)
|
||||
if flag:
|
||||
if group_id == -1:
|
||||
if not tmp["private"].get(user_id):
|
||||
@ -114,7 +117,9 @@ async def _(
|
||||
tmp["group"][group_id][user_id] = {"keyword": [keyword]}
|
||||
else:
|
||||
tmp["group"][group_id][user_id]["keyword"].append(keyword)
|
||||
await Text(f"已成功{'通过' if flag else '拒绝'}搜图关键词:{keyword}...").send()
|
||||
await MessageUtils.build_message(
|
||||
f"已成功{'通过' if flag else '拒绝'}搜图关键词:{keyword}..."
|
||||
).send()
|
||||
for user in tmp["private"]:
|
||||
text = ",".join(tmp["private"][user]["keyword"])
|
||||
await PlatformUtils.send_message(
|
||||
@ -134,21 +139,13 @@ async def _(
|
||||
bot,
|
||||
None,
|
||||
group_id=group,
|
||||
message=MessageFactory(
|
||||
message=MessageUtils.build_message(
|
||||
[
|
||||
Mention(user_id=user),
|
||||
Text(
|
||||
"你的关键词/UID/PID {x} 已被管理员通过,将在下一次进行更新..."
|
||||
),
|
||||
At(flag="user", target=user),
|
||||
"你的关键词/UID/PID {x} 已被管理员通过,将在下一次进行更新...",
|
||||
]
|
||||
),
|
||||
)
|
||||
# await bot.send_group_msg(
|
||||
# group_id=group,
|
||||
# message=Message(
|
||||
# f"{at(user)}你的关键词/UID/PID {x} 已被管理员通过,将在下一次进行更新..."
|
||||
# ),
|
||||
# )
|
||||
logger.info(
|
||||
f" 通过了pixiv搜图关键词/UID: {keyword}", arparma.header_result, session=session
|
||||
)
|
||||
@ -160,12 +157,16 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma, type: str, keywor
|
||||
keyword = f"{type}:{keyword}"
|
||||
if data := await PixivKeywordUser.get_or_none(keyword=keyword):
|
||||
await data.delete()
|
||||
await Text(f"删除搜图关键词/UID:{keyword} 成功...").send()
|
||||
await MessageUtils.build_message(
|
||||
f"删除搜图关键词/UID:{keyword} 成功..."
|
||||
).send()
|
||||
logger.info(
|
||||
f" 删除了pixiv搜图关键词: {keyword}", arparma.header_result, session=session
|
||||
)
|
||||
else:
|
||||
await Text(f"未查询到搜索关键词/UID/PID:{keyword},删除失败!").send()
|
||||
await MessageUtils.build_message(
|
||||
f"未查询到搜索关键词/UID/PID:{keyword},删除失败!"
|
||||
).send()
|
||||
|
||||
|
||||
@_del_pic_matcher.handle()
|
||||
@ -202,16 +203,16 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma, keyword: str):
|
||||
arparma.header_result,
|
||||
session=session,
|
||||
)
|
||||
# else:
|
||||
# await del_pic.send(
|
||||
# f"PIX:删除pid:{pid}{f'_p{img_p}' if img_p else ''} 失败.."
|
||||
# )
|
||||
else:
|
||||
await Text(
|
||||
await MessageUtils.build_message(
|
||||
f"PIX:图片pix:{keyword}{f'_p{img_p}' if img_p else ''} 不存在...无法删除.."
|
||||
).send()
|
||||
else:
|
||||
await Text(f"PID必须为数字!pid:{keyword}").send(reply=True)
|
||||
await Text(f"PIX:成功删除图片:{msg[:-1]}").send()
|
||||
await MessageUtils.build_message(f"PID必须为数字!pid:{keyword}").send(
|
||||
reply_to=True
|
||||
)
|
||||
await MessageUtils.build_message(f"PIX:成功删除图片:{msg[:-1]}").send()
|
||||
if flag:
|
||||
await Text(f"成功图片PID加入黑名单:{black_pid[:-1]}").send()
|
||||
await MessageUtils.build_message(
|
||||
f"成功图片PID加入黑名单:{black_pid[:-1]}"
|
||||
).send()
|
||||
|
||||
@ -16,12 +16,12 @@ from nonebot_plugin_alconna import (
|
||||
on_alconna,
|
||||
store_true,
|
||||
)
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from ._data_source import start_update_image_url
|
||||
from ._model.omega_pixiv_illusts import OmegaPixivIllusts
|
||||
@ -106,10 +106,12 @@ async def _(arparma: Arparma, session: EventSession, type: str, num: Match[int])
|
||||
else:
|
||||
update_lst = [f"uid:{_num}"]
|
||||
info = f"开始更新Pixiv搜图UID:\nuid:{_num}"
|
||||
await Text(info).send()
|
||||
await MessageUtils.build_message(info).send()
|
||||
start_time = time.time()
|
||||
pid_count, pic_count = await start_update_image_url(update_lst[:_num], black_pid, type == 'pid')
|
||||
await Text(
|
||||
pid_count, pic_count = await start_update_image_url(
|
||||
update_lst[:_num], black_pid, type == "pid"
|
||||
)
|
||||
await MessageUtils.build_message(
|
||||
f"Pixiv搜图关键词搜图更新完成...\n"
|
||||
f"累计更新PID {pid_count} 个\n"
|
||||
f"累计更新图片 {pic_count} 张"
|
||||
@ -131,7 +133,7 @@ async def _(bot: Bot, arparma: Arparma, session: EventSession):
|
||||
x_pid.append(img.pid)
|
||||
if img.uid not in x_uid:
|
||||
x_uid.append(img.uid)
|
||||
await Text(
|
||||
await MessageUtils.build_message(
|
||||
"从未更新过的UID:"
|
||||
+ ",".join([f"uid:{x}" for x in _uid if x not in x_uid])
|
||||
+ "\n"
|
||||
@ -139,12 +141,14 @@ async def _(bot: Bot, arparma: Arparma, session: EventSession):
|
||||
+ ",".join([f"pid:{x}" for x in _pid if x not in x_pid])
|
||||
).send()
|
||||
if arparma.find("update"):
|
||||
await Text("开始自动自动更新PID....").send()
|
||||
await MessageUtils.build_message("开始自动自动更新PID....").send()
|
||||
update_lst = [f"pid:{x}" for x in _uid if x not in x_uid]
|
||||
black_pid = await PixivKeywordUser.get_black_pid()
|
||||
start_time = time.time()
|
||||
pid_count, pic_count = await start_update_image_url(update_lst, black_pid, False)
|
||||
await Text(
|
||||
pid_count, pic_count = await start_update_image_url(
|
||||
update_lst, black_pid, False
|
||||
)
|
||||
await MessageUtils.build_message(
|
||||
f"Pixiv搜图关键词搜图更新完成...\n"
|
||||
f"累计更新PID {pid_count} 个\n"
|
||||
f"累计更新图片 {pic_count} 张"
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
from asyncio.exceptions import TimeoutError
|
||||
from pathlib import Path
|
||||
|
||||
from nonebot_plugin_saa import Image, MessageFactory
|
||||
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.configs.path_config import TEMP_PATH
|
||||
from zhenxun.services.log import logger
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.http_utils import AsyncHttpx
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name="一言二次元语录",
|
||||
@ -28,5 +28,5 @@ _matcher = on_alconna(Alconna("语录"), aliases={"二次元"}, priority=5, bloc
|
||||
async def _(session: EventSession, arparma: Arparma):
|
||||
data = (await AsyncHttpx.get(URL, timeout=5)).json()
|
||||
result = f'{data["hitokoto"]}\t——{data["from"]}'
|
||||
await Text(result).send()
|
||||
await MessageUtils.build_message(result).send()
|
||||
logger.info(f" 发送语录:" + result, arparma.header_result, session=session)
|
||||
|
||||
@ -4,14 +4,13 @@ import random
|
||||
from nonebot import on_command
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot_plugin_alconna import UniMsg
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
from nonebot_plugin_userinfo import EventUserInfo, UserInfo
|
||||
|
||||
from zhenxun.configs.config import NICKNAME
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.depends import UserName
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name="roll",
|
||||
@ -39,8 +38,10 @@ async def _(
|
||||
):
|
||||
text = message.extract_plain_text().strip().replace("roll", "", 1).split()
|
||||
if not text:
|
||||
await Text(f"roll: {random.randint(0, 100)}").finish(reply=True)
|
||||
await Text(
|
||||
await MessageUtils.build_message(f"roll: {random.randint(0, 100)}").finish(
|
||||
reply_to=True
|
||||
)
|
||||
await MessageUtils.build_message(
|
||||
random.choice(
|
||||
[
|
||||
"转动命运的齿轮,拨开眼前迷雾...",
|
||||
@ -52,7 +53,7 @@ async def _(
|
||||
).send()
|
||||
await asyncio.sleep(1)
|
||||
random_text = random.choice(text)
|
||||
await Text(
|
||||
await MessageUtils.build_message(
|
||||
random.choice(
|
||||
[
|
||||
f"让{NICKNAME}看看是什么结果!答案是:‘{random_text}’",
|
||||
@ -61,5 +62,5 @@ async def _(
|
||||
f"结束了,{user_name},命运之轮停在了 ‘{random_text}’!",
|
||||
]
|
||||
)
|
||||
).send(reply=True)
|
||||
).send(reply_to=True)
|
||||
logger.info(f"发送roll:{text}", "roll", session=session)
|
||||
|
||||
@ -4,8 +4,8 @@ from datetime import datetime, timedelta
|
||||
|
||||
from apscheduler.jobstores.base import JobLookupError
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot_plugin_alconna import At, UniMessage
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot_plugin_saa import Image, Mention, MessageFactory, Text
|
||||
from pydantic import BaseModel
|
||||
|
||||
from zhenxun.configs.config import NICKNAME, Config
|
||||
@ -14,6 +14,7 @@ from zhenxun.models.user_console import UserConsole
|
||||
from zhenxun.utils.enum import GoldHandle
|
||||
from zhenxun.utils.exception import InsufficientGold
|
||||
from zhenxun.utils.image_utils import BuildImage, BuildMat, MatType, text2image
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.platform import PlatformUtils
|
||||
|
||||
from .model import RussianUser
|
||||
@ -123,9 +124,7 @@ class RussianManage:
|
||||
if result:
|
||||
await PlatformUtils.send_message(bot, None, group_id, result)
|
||||
|
||||
async def add_russian(
|
||||
self, bot: Bot, group_id: str, rus: Russian
|
||||
) -> Text | MessageFactory:
|
||||
async def add_russian(self, bot: Bot, group_id: str, rus: Russian) -> UniMessage:
|
||||
"""添加决斗
|
||||
|
||||
参数:
|
||||
@ -134,59 +133,56 @@ class RussianManage:
|
||||
rus: Russian
|
||||
|
||||
返回:
|
||||
Text | MessageFactory: 返回消息
|
||||
UniMessage: 返回消息
|
||||
"""
|
||||
russian = self._data.get(group_id)
|
||||
if russian:
|
||||
if russian.time + 30 < time.time():
|
||||
if not russian.player2:
|
||||
return Text(
|
||||
return MessageUtils.build_message(
|
||||
f"现在是 {russian.player1[1]} 发起的对决, 请接受对决或等待决斗超时..."
|
||||
)
|
||||
else:
|
||||
return Text(
|
||||
return MessageUtils.build_message(
|
||||
f"{russian.player1[1]} 和 {russian.player2[1]}的对决还未结束!"
|
||||
)
|
||||
return Text(
|
||||
return MessageUtils.build_message(
|
||||
f"现在是 {russian.player1[1]} 发起的对决\n请等待比赛结束后再开始下一轮..."
|
||||
)
|
||||
max_money = base_config.get("MAX_RUSSIAN_BET_GOLD")
|
||||
if rus.money > max_money:
|
||||
return Text(f"太多了!单次金额不能超过{max_money}!")
|
||||
return MessageUtils.build_message(f"太多了!单次金额不能超过{max_money}!")
|
||||
user = await UserConsole.get_user(rus.player1[0])
|
||||
if user.gold < rus.money:
|
||||
return Text("你没有足够的钱支撑起这场挑战")
|
||||
return MessageUtils.build_message("你没有足够的钱支撑起这场挑战")
|
||||
rus.bullet_arr = self.__random_bullet(rus.bullet_num)
|
||||
self._data[group_id] = rus
|
||||
message_list = []
|
||||
message_list: list[str | At] = []
|
||||
if rus.at_user:
|
||||
user = await GroupInfoUser.get_or_none(
|
||||
user_id=rus.at_user, group_id=group_id
|
||||
)
|
||||
message_list = [
|
||||
Text(f"{rus.player1[1]} 向"),
|
||||
Mention(rus.at_user),
|
||||
Text(
|
||||
f"发起了决斗!请 {user.user_name if user else rus.at_user} 在30秒内回复‘接受对决’ or ‘拒绝对决’,超时此次决斗作废!"
|
||||
),
|
||||
f"{rus.player1[1]} 向",
|
||||
At(flag="user", target=rus.at_user),
|
||||
f"发起了决斗!请 {user.user_name if user else rus.at_user} 在30秒内回复‘接受对决’ or ‘拒绝对决’,超时此次决斗作废!",
|
||||
]
|
||||
else:
|
||||
message_list = [
|
||||
Text(
|
||||
"若30秒内无人接受挑战则此次对决作废【首次游玩请at我发送 ’帮助俄罗斯轮盘‘ 来查看命令】"
|
||||
)
|
||||
"若30秒内无人接受挑战则此次对决作废【首次游玩请at我发送 ’帮助俄罗斯轮盘‘ 来查看命令】"
|
||||
]
|
||||
result = Text(
|
||||
result = (
|
||||
"咔 " * rus.bullet_num
|
||||
+ f"装填完毕\n挑战金额:{rus.money}\n第一枪的概率为:{float(rus.bullet_num) / 7.0 * 100:.2f}%\n"
|
||||
)
|
||||
|
||||
message_list.insert(0, result)
|
||||
self.__build_job(bot, group_id, True)
|
||||
return MessageFactory(message_list)
|
||||
return MessageUtils.build_message(message_list) # type: ignore
|
||||
|
||||
async def accept(
|
||||
self, bot: Bot, group_id: str, user_id: str, uname: str
|
||||
) -> Text | MessageFactory:
|
||||
) -> UniMessage:
|
||||
"""接受对决
|
||||
|
||||
参数:
|
||||
@ -200,27 +196,31 @@ class RussianManage:
|
||||
"""
|
||||
if russian := self._data.get(group_id):
|
||||
if russian.at_user and russian.at_user != user_id:
|
||||
return Text("又不是找你决斗,你接受什么啊!气!")
|
||||
return MessageUtils.build_message("又不是找你决斗,你接受什么啊!气!")
|
||||
if russian.player2:
|
||||
return Text("当前决斗已被其他玩家接受!请等待下局对决!")
|
||||
return MessageUtils.build_message(
|
||||
"当前决斗已被其他玩家接受!请等待下局对决!"
|
||||
)
|
||||
if russian.player1[0] == user_id:
|
||||
return Text("你发起的对决,你接受什么啊!气!")
|
||||
return MessageUtils.build_message("你发起的对决,你接受什么啊!气!")
|
||||
user = await UserConsole.get_user(user_id)
|
||||
if user.gold < russian.money:
|
||||
return Text("你没有足够的钱来接受这场挑战...")
|
||||
return MessageUtils.build_message("你没有足够的钱来接受这场挑战...")
|
||||
russian.player2 = (user_id, uname)
|
||||
russian.next_user = russian.player1[0]
|
||||
self.__build_job(bot, group_id, True)
|
||||
return MessageFactory(
|
||||
return MessageUtils.build_message(
|
||||
[
|
||||
Text("决斗已经开始!请"),
|
||||
Mention(russian.player1[0]),
|
||||
Text("先开枪!"),
|
||||
"决斗已经开始!请",
|
||||
At(flag="user", target=russian.player1[0]),
|
||||
"先开枪!",
|
||||
]
|
||||
)
|
||||
return Text("目前没有进行的决斗,请发送 装弹 开启决斗吧!")
|
||||
return MessageUtils.build_message(
|
||||
"目前没有进行的决斗,请发送 装弹 开启决斗吧!"
|
||||
)
|
||||
|
||||
def refuse(self, group_id: str, user_id: str, uname: str) -> Text | MessageFactory:
|
||||
def refuse(self, group_id: str, user_id: str, uname: str) -> UniMessage:
|
||||
"""拒绝决斗
|
||||
|
||||
参数:
|
||||
@ -234,18 +234,25 @@ class RussianManage:
|
||||
if russian := self._data.get(group_id):
|
||||
if russian.at_user:
|
||||
if russian.at_user != user_id:
|
||||
return Text("又不是找你决斗,你拒绝什么啊!气!")
|
||||
return MessageUtils.build_message(
|
||||
"又不是找你决斗,你拒绝什么啊!气!"
|
||||
)
|
||||
del self._data[group_id]
|
||||
self.__remove_job(group_id)
|
||||
return MessageFactory(
|
||||
[Mention(russian.player1[0]), Text(f"{uname}拒绝了你的对决!")]
|
||||
return MessageUtils.build_message(
|
||||
[
|
||||
At(flag="user", target=russian.player1[0]),
|
||||
f"{uname}拒绝了你的对决!",
|
||||
]
|
||||
)
|
||||
return Text("当前决斗并没有指定对手,无法拒绝哦!")
|
||||
return Text("目前没有进行的决斗,请发送 装弹 开启决斗吧!")
|
||||
return MessageUtils.build_message("当前决斗并没有指定对手,无法拒绝哦!")
|
||||
return MessageUtils.build_message(
|
||||
"目前没有进行的决斗,请发送 装弹 开启决斗吧!"
|
||||
)
|
||||
|
||||
async def shoot(
|
||||
self, bot: Bot, group_id: str, user_id: str, uname: str, platform: str
|
||||
) -> tuple[Text | MessageFactory, Text | MessageFactory | None]:
|
||||
) -> tuple[UniMessage, UniMessage | None]:
|
||||
"""开枪
|
||||
|
||||
参数:
|
||||
@ -260,11 +267,14 @@ class RussianManage:
|
||||
"""
|
||||
if russian := self._data.get(group_id):
|
||||
if not russian.player2:
|
||||
return Text("当前还没有玩家接受对决,无法开枪..."), None
|
||||
return (
|
||||
MessageUtils.build_message("当前还没有玩家接受对决,无法开枪..."),
|
||||
None,
|
||||
)
|
||||
if user_id not in [russian.player1[0], russian.player2[0]]:
|
||||
"""非玩家1和玩家2发送开枪"""
|
||||
return (
|
||||
Text(
|
||||
MessageUtils.build_message(
|
||||
random.choice(
|
||||
[
|
||||
f"不要打扰 {russian.player1[1]} 和 {russian.player2[1]} 的决斗啊!",
|
||||
@ -278,12 +288,14 @@ class RussianManage:
|
||||
if user_id != russian.next_user:
|
||||
"""相同玩家连续开枪"""
|
||||
return (
|
||||
Text(f"你的左轮不是连发的!该 {russian.player2[1]} 开枪了!"),
|
||||
MessageUtils.build_message(
|
||||
f"你的左轮不是连发的!该 {russian.player2[1]} 开枪了!"
|
||||
),
|
||||
None,
|
||||
)
|
||||
if russian.bullet_arr[russian.bullet_index] == 1:
|
||||
"""去世"""
|
||||
result = Text(
|
||||
result = MessageUtils.build_message(
|
||||
random.choice(
|
||||
[
|
||||
'"嘭!",你直接去世了',
|
||||
@ -320,14 +332,19 @@ class RussianManage:
|
||||
russian.bullet_index += 1
|
||||
self.__build_job(bot, group_id, True)
|
||||
return (
|
||||
MessageFactory([Text(result), Mention(next_user), Text(" 了!")]),
|
||||
MessageUtils.build_message(
|
||||
[result, At(flag="user", target=next_user), " 了!"]
|
||||
),
|
||||
None,
|
||||
)
|
||||
return Text("目前没有进行的决斗,请发送 装弹 开启决斗吧!"), None
|
||||
return (
|
||||
MessageUtils.build_message("目前没有进行的决斗,请发送 装弹 开启决斗吧!"),
|
||||
None,
|
||||
)
|
||||
|
||||
async def settlement(
|
||||
self, group_id: str, user_id: str | None, platform: str | None = None
|
||||
) -> Text | MessageFactory:
|
||||
) -> UniMessage:
|
||||
"""结算
|
||||
|
||||
参数:
|
||||
@ -342,12 +359,14 @@ class RussianManage:
|
||||
if not russian.player2:
|
||||
if self.__check_is_timeout(group_id):
|
||||
del self._data[group_id]
|
||||
return Text("规定时间内还未有人接受决斗,当前决斗过期...")
|
||||
return Text("决斗还未开始,,无法结算哦...")
|
||||
return MessageUtils.build_message(
|
||||
"规定时间内还未有人接受决斗,当前决斗过期..."
|
||||
)
|
||||
return MessageUtils.build_message("决斗还未开始,,无法结算哦...")
|
||||
if user_id and user_id not in [russian.player1[0], russian.player2[0]]:
|
||||
return Text(f"吃瓜群众不要捣乱!黄牌警告!")
|
||||
return MessageUtils.build_message(f"吃瓜群众不要捣乱!黄牌警告!")
|
||||
if not self.__check_is_timeout(group_id):
|
||||
return Text(
|
||||
return MessageUtils.build_message(
|
||||
f"{russian.player1[1]} 和 {russian.player2[1]} 比赛并未超时,请继续比赛..."
|
||||
)
|
||||
win_user = None
|
||||
@ -393,7 +412,11 @@ class RussianManage:
|
||||
if u := await UserConsole.get_user(lose_user[0]):
|
||||
u.gold = 0
|
||||
await u.save(update_fields=["gold"])
|
||||
result = [Text("这场决斗是 "), Mention(win_user[0]), Text(" 胜利了!")]
|
||||
result = [
|
||||
"这场决斗是 ",
|
||||
At(flag="user", target=win_user[0]),
|
||||
" 胜利了!",
|
||||
]
|
||||
image = await text2image(
|
||||
f"结算:\n"
|
||||
f"\t胜者:{win_user[1]}\n"
|
||||
@ -412,11 +435,11 @@ class RussianManage:
|
||||
color="#f9f6f2",
|
||||
)
|
||||
self.__remove_job(group_id)
|
||||
result.append(Image(image.pic2bytes()))
|
||||
result.append(image)
|
||||
del self._data[group_id]
|
||||
return MessageFactory(result)
|
||||
return Text("赢家和输家获取错误...")
|
||||
return Text("比赛并没有开始...无法结算...")
|
||||
return MessageUtils.build_message(result)
|
||||
return MessageUtils.build_message("赢家和输家获取错误...")
|
||||
return MessageUtils.build_message("比赛并没有开始...无法结算...")
|
||||
|
||||
async def __get_x_index(self, users: list[RussianUser], group_id: str):
|
||||
uid_list = [u.user_id for u in users]
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot_plugin_alconna import Alconna, Args, Arparma, Match, on_alconna
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.configs.utils import BaseBlock, PluginExtraData, RegisterConfig
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from .data_source import from_anime_get_info
|
||||
|
||||
@ -47,15 +47,15 @@ async def _(name: Match[str]):
|
||||
@_matcher.got_path("name", prompt="是不是少了番名?")
|
||||
async def _(session: EventSession, arparma: Arparma, name: str):
|
||||
gid = session.id3 or session.id2
|
||||
await Text(f"开始搜番 {name}...").send()
|
||||
await MessageUtils.build_message(f"开始搜番 {name}...").send()
|
||||
anime_report = await from_anime_get_info(
|
||||
name,
|
||||
Config.get_config("search_anime", "SEARCH_ANIME_MAX_INFO"),
|
||||
)
|
||||
if anime_report:
|
||||
if isinstance(anime_report, str):
|
||||
await Text(anime_report).finish()
|
||||
await Text("\n\n".join(anime_report)).send()
|
||||
await MessageUtils.build_message(anime_report).finish()
|
||||
await MessageUtils.build_message("\n\n".join(anime_report)).send()
|
||||
logger.info(
|
||||
f"搜索番剧 {name} 成功: {anime_report}",
|
||||
arparma.header_result,
|
||||
@ -63,4 +63,6 @@ async def _(session: EventSession, arparma: Arparma, name: str):
|
||||
)
|
||||
else:
|
||||
logger.info(f"未找到番剧 {name}...")
|
||||
await Text(f"未找到番剧 {name}(也有可能是超时,再尝试一下?)").send()
|
||||
await MessageUtils.build_message(
|
||||
f"未找到番剧 {name}(也有可能是超时,再尝试一下?)"
|
||||
).send()
|
||||
|
||||
@ -2,12 +2,12 @@ from nonebot.permission import SUPERUSER
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot.rule import to_me
|
||||
from nonebot_plugin_alconna import Alconna, Args, Arparma, Match, on_alconna
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import NICKNAME
|
||||
from zhenxun.configs.utils import BaseBlock, PluginExtraData, RegisterConfig
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from .data_source import get_price, update_buff_cookie
|
||||
|
||||
@ -73,29 +73,32 @@ async def arg_handle(
|
||||
skin: str,
|
||||
):
|
||||
if name in ["算了", "取消"] or skin in ["算了", "取消"]:
|
||||
await Text("已取消操作...").finish()
|
||||
await MessageUtils.build_message("已取消操作...").finish()
|
||||
result = ""
|
||||
if name in ["ak", "ak47"]:
|
||||
name = "ak-47"
|
||||
name = name + " | " + skin
|
||||
status_code = -1
|
||||
try:
|
||||
result, status_code = await get_price(name)
|
||||
except FileNotFoundError:
|
||||
await Text(f'请先对{NICKNAME}说"设置cookie"来设置cookie!').send(at_sender=True)
|
||||
await MessageUtils.build_message(
|
||||
f'请先对{NICKNAME}说"设置cookie"来设置cookie!'
|
||||
).send(at_sender=True)
|
||||
if status_code in [996, 997, 998]:
|
||||
await Text(result).finish()
|
||||
await MessageUtils.build_message(result).finish()
|
||||
if result:
|
||||
logger.info(f"查询皮肤: {name}", arparma.header_result, session=session)
|
||||
await Text(result).finish()
|
||||
await MessageUtils.build_message(result).finish()
|
||||
else:
|
||||
logger.info(
|
||||
f" 查询皮肤:{name} 没有查询到", arparma.header_result, session=session
|
||||
)
|
||||
await Text("没有查询到哦,请检查格式吧").send()
|
||||
await MessageUtils.build_message("没有查询到哦,请检查格式吧").send()
|
||||
|
||||
|
||||
@_cookie_matcher.handle()
|
||||
async def _(session: EventSession, arparma: Arparma, cookie: str):
|
||||
result = update_buff_cookie(cookie)
|
||||
await Text(result).send(at_sender=True)
|
||||
await MessageUtils.build_message(result).send(at_sender=True)
|
||||
logger.info("更新BUFF COOKIE", arparma.header_result, session=session)
|
||||
|
||||
@ -14,7 +14,6 @@ from nonebot_plugin_alconna import (
|
||||
on_alconna,
|
||||
store_true,
|
||||
)
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import NICKNAME
|
||||
@ -175,11 +174,11 @@ async def _(
|
||||
):
|
||||
_tags = tags.result.split("#") if tags.available else None
|
||||
if _tags and NICKNAME in _tags:
|
||||
await Text(
|
||||
await MessageUtils.build_message(
|
||||
"咳咳咳,虽然我很可爱,但是我木有自己的色图~~~有的话记得发我一份呀"
|
||||
).finish()
|
||||
if not session.id1:
|
||||
await Text("用户id为空...").finish()
|
||||
await MessageUtils.build_message("用户id为空...").finish()
|
||||
gid = session.id3 or session.id2
|
||||
user_console = await UserConsole.get_user(session.id1, session.platform)
|
||||
user, _ = await SignUser.get_or_create(
|
||||
@ -208,11 +207,11 @@ async def _(
|
||||
"""指定id"""
|
||||
result = await SetuManage.get_setu(local_id=local_id.result)
|
||||
if isinstance(result, str):
|
||||
await MessageUtils.build_message(result).finish(reply=True)
|
||||
await MessageUtils.build_message(result).finish(reply_to=True)
|
||||
await result[0].finish()
|
||||
result_list = await SetuManage.get_setu(tags=_tags, num=_num, is_r18=is_r18)
|
||||
if isinstance(result_list, str):
|
||||
await MessageUtils.build_message(result_list).finish(reply=True)
|
||||
await MessageUtils.build_message(result_list).finish(reply_to=True)
|
||||
max_once_num2forward = base_config.get("MAX_ONCE_NUM2FORWARD")
|
||||
platform = PlatformUtils.get_platform(bot)
|
||||
if (
|
||||
|
||||
@ -3,13 +3,13 @@ from nonebot.plugin import PluginMetadata
|
||||
from nonebot.rule import to_me
|
||||
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.configs.utils import BaseBlock, PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from .data_source import update_setu_img
|
||||
|
||||
@ -37,13 +37,13 @@ _matcher = on_alconna(
|
||||
@_matcher.handle()
|
||||
async def _(session: EventSession, arparma: Arparma):
|
||||
if Config.get_config("send_setu", "DOWNLOAD_SETU"):
|
||||
await Text("开始更新色图...").send(reply=True)
|
||||
await MessageUtils.build_message("开始更新色图...").send(reply_to=True)
|
||||
result = await update_setu_img(True)
|
||||
if result:
|
||||
await Text(result).send()
|
||||
await MessageUtils.build_message(result).send()
|
||||
logger.info("更新色图", arparma.header_result, session=session)
|
||||
else:
|
||||
await Text("更新色图配置未开启...").send()
|
||||
await MessageUtils.build_message("更新色图配置未开启...").send()
|
||||
|
||||
|
||||
# 更新色图
|
||||
|
||||
@ -8,7 +8,6 @@ from nonebot_plugin_alconna import (
|
||||
on_alconna,
|
||||
store_true,
|
||||
)
|
||||
from nonebot_plugin_saa import Image, Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
@ -160,4 +159,4 @@ async def _(
|
||||
else:
|
||||
await MessageUtils.build_message(result).send()
|
||||
else:
|
||||
await Text("获取数据失败...").send()
|
||||
await MessageUtils.build_message("获取数据失败...").send()
|
||||
|
||||
@ -83,7 +83,7 @@ async def _(
|
||||
if to not in values and to not in keys:
|
||||
await MessageUtils.build_message("目标语种不支持...").finish()
|
||||
result = await translate_message(text, source, to)
|
||||
await MessageUtils.build_message(result).send(reply=True)
|
||||
await MessageUtils.build_message(result).send(reply_to=True)
|
||||
logger.info(
|
||||
f"source: {source}, to: {to}, 翻译: {text}",
|
||||
arparma.header_result,
|
||||
|
||||
@ -33,7 +33,7 @@ _matcher = on_alconna(Alconna("微博热搜", Args["idx?", int]), priority=5, bl
|
||||
async def _(session: EventSession, arparma: Arparma, idx: Match[int]):
|
||||
result, data_list = await get_hot_image()
|
||||
if isinstance(result, str):
|
||||
await MessageUtils.build_message(result).finish(reply=True)
|
||||
await MessageUtils.build_message(result).finish(reply_to=True)
|
||||
if idx.available:
|
||||
_idx = idx.result
|
||||
url = data_list[_idx - 1]["url"]
|
||||
|
||||
@ -2,11 +2,11 @@ from nonebot.plugin import PluginMetadata
|
||||
from nonebot_plugin_alconna import Alconna, Args, Arparma
|
||||
from nonebot_plugin_alconna import Image as alcImg
|
||||
from nonebot_plugin_alconna import Match, on_alconna
|
||||
from nonebot_plugin_saa import Image, Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from .data_source import get_anime
|
||||
|
||||
@ -41,11 +41,11 @@ async def _(
|
||||
image: alcImg,
|
||||
):
|
||||
if not image.url:
|
||||
await Text("图片url为空...").finish()
|
||||
await Text("开始识别...").send()
|
||||
await MessageUtils.build_message("图片url为空...").finish()
|
||||
await MessageUtils.build_message("开始识别...").send()
|
||||
anime_data_report = await get_anime(image.url)
|
||||
if anime_data_report:
|
||||
await Text(anime_data_report).send(reply=True)
|
||||
await MessageUtils.build_message(anime_data_report).send(reply_to=True)
|
||||
logger.info(
|
||||
f" 识番 {image.url} --> {anime_data_report}",
|
||||
arparma.header_result,
|
||||
@ -55,4 +55,6 @@ async def _(
|
||||
logger.info(
|
||||
f"识番 {image.url} 未找到...", arparma.header_result, session=session
|
||||
)
|
||||
await Text(f"没有寻找到该番剧,果咩..").send(reply=True)
|
||||
await MessageUtils.build_message(f"没有寻找到该番剧,果咩..").send(
|
||||
reply_to=True
|
||||
)
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user