diff --git a/README.md b/README.md index 1ff61d19..0f6898a1 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ ### 1. 体验一下? -这是一个免费的,版本为 dev 的 zhenxun,你可以通过 napcat 或拉格朗日等直接连接用于体验与测试 +这是一个免费的,版本为 dev 的 zhenxun,你可以通过 [napcat](https://github.com/NapNeko/NapCatQQ) 或 [拉格朗日](https://github.com/LagrangeDev/Lagrange.Core) 以及 [matcha](https://github.com/A-kirami/matcha) 等直接连接用于体验与测试 (球球了测试君!) ``` @@ -95,6 +95,7 @@ AccessToken: PUBLIC_ZHENXUN_TEST
WebUI 后台示例图 +![x](https://raw.githubusercontent.com/HibiKier/zhenxun_bot/main/docs_image/webui0.png) ![x](https://raw.githubusercontent.com/HibiKier/zhenxun_bot/main/docs_image/webui1.png) ![x](https://raw.githubusercontent.com/HibiKier/zhenxun_bot/main/docs_image/webui2.png) ![x](https://raw.githubusercontent.com/HibiKier/zhenxun_bot/main/docs_image/webui3.png) @@ -319,7 +320,7 @@ python bot.py
爱发电 以及 感谢投喂 - + ### 感谢名单 @@ -369,6 +370,7 @@ python bot.py [哇](https://afdian.net/u/9b266244f23911eca19052540025c377) [yajiwa](https://github.com/yajiwa) [爆金币](https://afdian.net/u/0d78879ef23711ecb22452540025c377) +...
diff --git a/docs_image/afd.jpg b/docs_image/afd.jpg new file mode 100644 index 00000000..e7acf463 Binary files /dev/null and b/docs_image/afd.jpg differ diff --git a/docs_image/webui0.png b/docs_image/webui0.png new file mode 100644 index 00000000..71f7d368 Binary files /dev/null and b/docs_image/webui0.png differ diff --git a/docs_image/webui1.png b/docs_image/webui1.png index 2cfa5822..cd415685 100644 Binary files a/docs_image/webui1.png and b/docs_image/webui1.png differ diff --git a/docs_image/webui2.png b/docs_image/webui2.png index ff884972..0fcc4f05 100644 Binary files a/docs_image/webui2.png and b/docs_image/webui2.png differ diff --git a/docs_image/webui3.png b/docs_image/webui3.png index f328df2d..2e7426e3 100644 Binary files a/docs_image/webui3.png and b/docs_image/webui3.png differ diff --git a/docs_image/webui4.png b/docs_image/webui4.png index 8bf31231..5810f71b 100644 Binary files a/docs_image/webui4.png and b/docs_image/webui4.png differ diff --git a/docs_image/webui5.png b/docs_image/webui5.png index 6b8d350e..d5f5e304 100644 Binary files a/docs_image/webui5.png and b/docs_image/webui5.png differ diff --git a/docs_image/webui6.png b/docs_image/webui6.png index 157ad8a6..7541f679 100644 Binary files a/docs_image/webui6.png and b/docs_image/webui6.png differ diff --git a/docs_image/webui7.png b/docs_image/webui7.png index ac82ab02..1628ade7 100644 Binary files a/docs_image/webui7.png and b/docs_image/webui7.png differ diff --git a/zhenxun/builtin_plugins/hooks/call_hook.py b/zhenxun/builtin_plugins/hooks/call_hook.py new file mode 100644 index 00000000..2ff4d39c --- /dev/null +++ b/zhenxun/builtin_plugins/hooks/call_hook.py @@ -0,0 +1,23 @@ +from typing import Any + +from nonebot.adapters import Bot + +from zhenxun.services.log import logger +from zhenxun.utils.manager.message_manager import MessageManager + + +@Bot.on_called_api +async def handle_api_result( + bot: Bot, exception: Exception | None, api: str, data: dict[str, Any], result: Any +): + if not exception and api == "send_msg": + try: + if (uid := data.get("user_id")) and (msg_id := result.get("message_id")): + MessageManager.add(str(uid), str(msg_id)) + logger.debug( + f"收集消息id,user_id: {uid}, msg_id: {msg_id}", "msg_hook" + ) + except Exception as e: + logger.warning( + f"收集消息id发生错误...data: {data}, result: {result}", "msg_hook", e=e + ) diff --git a/zhenxun/builtin_plugins/withdraw.py b/zhenxun/builtin_plugins/withdraw.py new file mode 100644 index 00000000..8186cfbc --- /dev/null +++ b/zhenxun/builtin_plugins/withdraw.py @@ -0,0 +1,61 @@ +from nonebot.rule import Rule +from nonebot.adapters import Bot, Event +from nonebot_plugin_uninfo import Uninfo +from nonebot.plugin import PluginMetadata +from nonebot_plugin_alconna.uniseg.tools import reply_fetch +from nonebot_plugin_alconna import Alconna, Arparma, on_alconna + +from zhenxun.services.log import logger +from zhenxun.utils.message import MessageUtils +from zhenxun.utils.platform import PlatformUtils +from zhenxun.configs.utils import PluginExtraData +from zhenxun.utils.manager.message_manager import MessageManager + +__plugin_meta__ = PluginMetadata( + name="消息撤回", + description="撤回自己触发的消息撤回,不允许撤回其他人触发消息的撤回哦", + usage=""" + 引用消息 撤回 + """.strip(), + extra=PluginExtraData(author="HibiKier", version="0.1", menu_type="其他").dict(), +) + + +def reply_check() -> Rule: + """ + 检查是否存在回复消息 + + 返回: + Rule: Rule + """ + + async def _rule(bot: Bot, event: Event, session: Uninfo): + if event.get_type() == "message": + return ( + bool(await reply_fetch(event, bot)) + and PlatformUtils.get_platform(session) == "qq" + ) + return False + + return Rule(_rule) + + +_matcher = on_alconna(Alconna("撤回"), priority=5, block=True, rule=reply_check()) + + +@_matcher.handle() +async def _(bot: Bot, event: Event, session: Uninfo, arparma: Arparma): + if reply := await reply_fetch(event, bot): + if ( + MessageManager.check(session.user.id, reply.id) + or session.user.id in bot.config.superusers + ): + try: + await bot.delete_msg(message_id=reply.id) + logger.info("撤回消息", arparma.header_result, session=session) + except Exception: + await MessageUtils.build_message("撤回失败,可能消息已过期...").send() + else: + await MessageUtils.build_message( + "权限不足,不是你触发的消息不要胡乱撤回哦..." + ).send() diff --git a/zhenxun/utils/manager/message_manager.py b/zhenxun/utils/manager/message_manager.py new file mode 100644 index 00000000..e714c8d8 --- /dev/null +++ b/zhenxun/utils/manager/message_manager.py @@ -0,0 +1,27 @@ +from typing import ClassVar + + +class MessageManager: + data: ClassVar[dict[str, list[str]]] = {} + + @classmethod + def add(cls, uid: str, msg_id: str): + if uid not in cls.data: + cls.data[uid] = [] + cls.data[uid].append(msg_id) + cls.remove_check(uid) + + @classmethod + def check(cls, uid: str, msg_id: str) -> bool: + return msg_id in cls.data.get(uid, []) + + @classmethod + def remove_check(cls, uid: str): + if len(cls.data[uid]) > 200: + cls.data[uid] = cls.data[uid][100:] + + @classmethod + def get(cls, uid: str) -> list[str]: + if uid in cls.data: + return cls.data[uid] + return []