add request event approve reject

This commit is contained in:
yanyongyu 2021-01-16 11:47:48 +08:00
parent fcac6f8a0f
commit 7c3b2b514a
2 changed files with 24 additions and 1 deletions

View File

@ -1,6 +1,6 @@
import inspect
from typing_extensions import Literal
from typing import Type, List, Optional
from typing import Type, List, Optional, TYPE_CHECKING
from pydantic import BaseModel
from pygtrie import StringTrie
@ -11,6 +11,9 @@ from nonebot.adapters import Event as BaseEvent
from .message import Message
if TYPE_CHECKING:
from .bot import Bot
class Event(BaseEvent):
"""
@ -458,6 +461,14 @@ class FriendRequestEvent(RequestEvent):
def get_session_id(self) -> str:
return str(self.user_id)
async def approve(self, bot: "Bot", remark: str = ""):
return await bot.set_friend_add_request(flag=self.flag,
approve=True,
remark=remark)
async def reject(self, bot: "Bot"):
return await bot.set_friend_add_request(flag=self.flag, approve=False)
class GroupRequestEvent(RequestEvent):
"""加群请求/邀请事件"""
@ -477,6 +488,17 @@ class GroupRequestEvent(RequestEvent):
def get_session_id(self) -> str:
return str(self.user_id)
async def approve(self, bot: "Bot"):
return await bot.set_group_add_request(flag=self.flag,
sub_type=self.sub_type,
approve=True)
async def reject(self, bot: "Bot", reason: str = ""):
return await bot.set_group_add_request(flag=self.flag,
sub_type=self.sub_type,
approve=False,
reason=reason)
# Meta Events
class MetaEvent(Event):

View File

@ -9,6 +9,7 @@ sidebar: auto
- 修复 `Message` 消息为 `None` 时的处理错误
- 修复 `Message.extract_plain_text` 返回为转义字符串的问题
- 修复命令处理错误地删除了后续空格
- 增加好友添加和加群请求事件 `approve`, `reject` 方法
## v2.0.0a8