diff --git a/none/notice_request.py b/none/notice_request.py index 63937bdb..fcfcff65 100644 --- a/none/notice_request.py +++ b/none/notice_request.py @@ -1,6 +1,6 @@ from typing import Dict, Any, Optional, Callable, Union -from aiocqhttp import CQHttp +from aiocqhttp import CQHttp, Error as CQHttpError from aiocqhttp.bus import EventBus from .session import BaseSession @@ -44,7 +44,33 @@ class RequestSession(BaseSession): def __init__(self, bot: CQHttp, ctx: Dict[str, Any]): super().__init__(bot, ctx) - # TODO: 添加 approve、deny 等方法 + async def approve(self, remark: str = ''): + # TODO: should use ".handle_quick_operation" action in the future + try: + if self.ctx['request_type'] == 'friend': + await self.bot.set_friend_add_request(**self.ctx, + approve=True, + remark=remark) + elif self.ctx['request_type'] == 'group': + await self.bot.set_group_add_request(**self.ctx, + type=self.ctx['sub_type'], + approve=True) + except CQHttpError: + pass + + async def reject(self, reason: str = ''): + # TODO: should use ".handle_quick_operation" action in the future + try: + if self.ctx['request_type'] == 'friend': + await self.bot.set_friend_add_request(**self.ctx, + approve=False) + elif self.ctx['request_type'] == 'group': + await self.bot.set_group_add_request(**self.ctx, + type=self.ctx['sub_type'], + approve=False, + reason=reason) + except CQHttpError: + pass async def handle_notice_or_request(bot: CQHttp, ctx: Dict[str, Any]) -> None: diff --git a/none_demo/plugins/greeting.py b/none_demo/plugins/groupadmin.py similarity index 77% rename from none_demo/plugins/greeting.py rename to none_demo/plugins/groupadmin.py index e673e4f4..cfd42f11 100644 --- a/none_demo/plugins/greeting.py +++ b/none_demo/plugins/groupadmin.py @@ -1,6 +1,6 @@ from aiocqhttp import Error as CQHttpError -from none import on_notice, NoticeSession +from none import on_notice, NoticeSession, on_request, RequestSession GROUP_GREETING = ( '欢迎新同学 {name}[]![CQ:face,id=63][CQ:face,id=63][CQ:face,id=63]', @@ -21,3 +21,9 @@ async def _(session: NoticeSession): await session.send_expr(GROUP_GREETING, name=name, **session.ctx) except CQHttpError: pass + + +@on_request('group') +async def _(session: RequestSession): + if session.ctx['group_id'] == 672076603: + await session.approve()