From fbd53dae7ca49b82fea5416bed8aca341e3bb32b Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Tue, 17 Jan 2023 15:42:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E5=AE=A1=E6=89=B9?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin_examples/auto_approval/__init__.py | 0 tests/plugin_examples/auto_approval/main.py | 44 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tests/plugin_examples/auto_approval/__init__.py create mode 100644 tests/plugin_examples/auto_approval/main.py diff --git a/tests/plugin_examples/auto_approval/__init__.py b/tests/plugin_examples/auto_approval/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/plugin_examples/auto_approval/main.py b/tests/plugin_examples/auto_approval/main.py new file mode 100644 index 00000000..ba9e924e --- /dev/null +++ b/tests/plugin_examples/auto_approval/main.py @@ -0,0 +1,44 @@ +from mirai import Mirai + +import pkg.qqbot.manager +from pkg.plugin.models import * +from pkg.plugin.host import PluginHost + +from mirai.models import MemberJoinRequestEvent + +""" +加群自动审批 +""" + +__group_id__ = 1025599757 +__application_contains__ = ['github', 'gitee', 'Github', 'Gitee', 'GitHub'] + + +# 注册插件 +@register(name="加群审批", description="自动审批加群申请", version="0.1", author="RockChinQ") +class AutoApproval(Plugin): + + bot: Mirai = None + + # 插件加载时触发 + def __init__(self, plugin_host: PluginHost): + qqmgr = plugin_host.get_runtime_context().get_qqbot_manager() + assert isinstance(qqmgr, pkg.qqbot.manager.QQBotManager) + self.bot = qqmgr.bot + + # 向YiriMirai注册 加群申请 事件处理函数 + @qqmgr.bot.on(MemberJoinRequestEvent) + async def process(event: MemberJoinRequestEvent): + assert isinstance(qqmgr, pkg.qqbot.manager.QQBotManager) + if event.group_id == __group_id__: + if any([x in event.message for x in __application_contains__]): + logging.info("自动同意加群申请") + await qqmgr.bot.allow(event) + + self.process = process + + # 插件卸载时触发 + def __del__(self): + # 关闭时向YiriMirai注销 加群申请 事件处理函数 + if self.bot is not None: + self.bot.bus.unsubscribe(MemberJoinRequestEvent, self.process)