From 3b1a399d5fb58365cecbc467a7beb46bb40df83e Mon Sep 17 00:00:00 2001 From: HibiKier <45528451+HibiKier@users.noreply.github.com> Date: Sat, 23 Nov 2024 21:37:00 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=B7=BB=E5=8A=A0=E5=B0=8F?= =?UTF-8?q?=E7=9C=9F=E5=AF=BB=E7=9A=84=E5=8F=A3=E7=99=96=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=20(#1738)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zhenxun/builtin_plugins/catchphrase.py | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 zhenxun/builtin_plugins/catchphrase.py diff --git a/zhenxun/builtin_plugins/catchphrase.py b/zhenxun/builtin_plugins/catchphrase.py new file mode 100644 index 00000000..3cea8fa8 --- /dev/null +++ b/zhenxun/builtin_plugins/catchphrase.py @@ -0,0 +1,28 @@ +from typing import Any + +from nonebot.adapters import Bot + +from zhenxun.services.log import logger +from zhenxun.configs.config import Config + +Config.add_plugin_config( + "catchphrase", + "CATCHPHRASE", + "", + help="小真寻的口癖,在文本末尾添加指定文字~", + default_value="", +) + + +@Bot.on_calling_api +async def handle_api_call(bot: Bot, api: str, data: dict[str, Any]): + if api == "send_msg": + catchphrase = Config.get_config("catchphrase", "CATCHPHRASE") + if catchphrase and (message := data.get("message")): + for i in range(len(message) - 1, -1, -1): + if message[i].type == "text": + message[i].data["text"] += catchphrase + logger.debug( + f"文本: {message[i].data['text']} 添加口癖: {catchphrase}" + ) + break