zhenxun_bot/zhenxun/builtin_plugins/catchphrase.py
BalconyJH bc5a9c4fcc
Develop: 完全使用 ruff 替代 isort 与 black (#1757)
* 🚨 完全使用 ruff 替代 isort 与 black

* 🚨 ruff lint&format
2024-12-10 19:49:11 +08:00

29 lines
883 B
Python

from typing import Any
from nonebot.adapters import Bot
from zhenxun.configs.config import Config
from zhenxun.services.log import logger
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