From e2bb4d2e56457bc5ae14b9393f4320a5eb51ff10 Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Thu, 16 May 2024 00:29:52 +0800 Subject: [PATCH] =?UTF-8?q?feat=E2=9C=A8:=20=E9=B2=81=E8=BF=85=E8=AF=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zhenxun/plugins/luxun.py | 74 +++++++++++++++++++++++++++++++++++ zhenxun/utils/_build_image.py | 3 ++ 2 files changed, 77 insertions(+) create mode 100644 zhenxun/plugins/luxun.py diff --git a/zhenxun/plugins/luxun.py b/zhenxun/plugins/luxun.py new file mode 100644 index 00000000..e407cb3a --- /dev/null +++ b/zhenxun/plugins/luxun.py @@ -0,0 +1,74 @@ +from nonebot.plugin import PluginMetadata +from nonebot_plugin_alconna import Alconna, Args, Arparma, Match, on_alconna +from nonebot_plugin_saa import Image, Text +from nonebot_plugin_session import EventSession + +from zhenxun.configs.path_config import IMAGE_PATH +from zhenxun.configs.utils import BaseBlock, PluginExtraData +from zhenxun.services.log import logger +from zhenxun.utils.image_utils import BuildImage + +__plugin_meta__ = PluginMetadata( + name="鲁迅说", + description="鲁迅说了啥?", + usage=""" + 鲁迅说 [文本] + """.strip(), + extra=PluginExtraData( + author="HibiKier", + version="0.1", + limits=[BaseBlock(result="你的鲁迅正在说,等会")], + ).dict(), +) + +_matcher = on_alconna( + Alconna("luxun", Args["content", str]), + priority=5, + block=True, +) + +_matcher.shortcut( + "鲁迅说", + command="luxun", + arguments=["{%0}"], + prefix=True, +) + + +_sign = None + + +@_matcher.handle() +async def _(content: Match[str]): + if content.available: + _matcher.set_path_arg("content", content.result) + + +@_matcher.got_path("content", prompt="你让鲁迅说点啥?") +async def _(content: str, session: EventSession, arparma: Arparma): + global _sign + if content.startswith(",") or content.startswith(","): + content = content[1:] + A = BuildImage( + font_size=37, background=f"{IMAGE_PATH}/other/luxun.jpg", font="msyh.ttf" + ) + text = "" + if len(content) > 40: + await Text("太长了,鲁迅说不完...").finish() + while A.getsize(content)[0] > A.width - 50: + n = int(len(content) / 2) + text += content[:n] + "\n" + content = content[n:] + text += content + if len(text.split("\n")) > 2: + await Text("太长了,鲁迅说不完...").finish() + await A.text( + (int((480 - A.getsize(text.split("\n")[0])[0]) / 2), 300), text, (255, 255, 255) + ) + if not _sign: + _sign = await BuildImage.build_text_image( + "--鲁迅", "msyh.ttf", 30, (255, 255, 255) + ) + await A.paste(_sign, (320, 400)) + await Image(A.pic2bytes()).send() + logger.info(f"鲁迅说: {content}", arparma.header_result, session=session) diff --git a/zhenxun/utils/_build_image.py b/zhenxun/utils/_build_image.py index 5cf26e89..665d4a5b 100644 --- a/zhenxun/utils/_build_image.py +++ b/zhenxun/utils/_build_image.py @@ -60,6 +60,9 @@ class BuildImage: self.markImg = Image.open(background) if width and height: self.markImg = self.markImg.resize((width, height), Image.LANCZOS) + else: + self.width = self.markImg.width + self.height = self.markImg.height else: if not width or not height: raise ValueError("长度和宽度不能为空...")