✨ 移除saa依赖

This commit is contained in:
HibiKier
2024-08-11 15:57:33 +08:00
parent 71f3b031d4
commit d0792e0a1c
68 changed files with 1722 additions and 1528 deletions
+2 -3
View File
@@ -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)
+5 -3
View File
@@ -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,
+4 -4
View File
@@ -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)
+5 -3
View File
@@ -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,
+5 -5
View File
@@ -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
)
-1
View File
@@ -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
+15 -14
View File
@@ -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()
+11 -7
View File
@@ -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,
]
)
+4 -5
View File
@@ -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)
+1 -1
View File
@@ -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:
+12 -17
View File
@@ -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:
+18 -22
View File
@@ -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()
+13 -10
View File
@@ -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()
+4 -4
View File
@@ -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:
+4 -4
View File
@@ -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,
+5 -3
View File
@@ -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()
+16 -10
View File
@@ -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()
+12 -8
View File
@@ -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
+2 -2
View File
@@ -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)
+7 -6
View File
@@ -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)
+77 -54
View File
@@ -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]
+7 -5
View File
@@ -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()
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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"]
+7 -5
View File
@@ -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
)