🔀 Merge pull request #546

Feature: Add support for mirai adapter NudgeEvent
This commit is contained in:
Ju4tCode 2021-10-02 15:10:32 +08:00 committed by GitHub
commit f3abd2f1a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 18 deletions

View File

@ -1044,14 +1044,14 @@ mirai-api-http 协议事件,字段与 mirai-api-http 一致。各事件字段
用户权限枚举类
>
> * `OWNER`: 群主
* `OWNER`: 群主
> * `ADMINISTRATOR`: 群管理
* `ADMINISTRATOR`: 群管理
> * `MEMBER`: 普通群成员
* `MEMBER`: 普通群成员
@ -1433,14 +1433,31 @@ Bot被邀请入群申请
用户权限枚举类
>
> * `OWNER`: 群主
* `OWNER`: 群主
> * `ADMINISTRATOR`: 群管理
* `ADMINISTRATOR`: 群管理
> * `MEMBER`: 普通群成员
* `MEMBER`: 普通群成员
## _class_ `NudgeSubjectKind`
基类:`str`, `enum.Enum`
* **说明**
戳一戳类型枚举类
* `Group`: 群
* `Friend`: 好友
@ -1718,6 +1735,13 @@ Bot在群里的权限被改变
成员权限改变的事件该成员不是Bot
## _class_ `NudgeEvent`
基类:`nonebot.adapters.mirai.event.notice.NoticeEvent`
戳一戳触发事件
# NoneBot.adapters.mirai.event.request 模块

View File

@ -1,15 +1,15 @@
import json
from enum import Enum
from typing import Any, Dict, Optional, Type
from pydantic import BaseModel, Field, ValidationError
from typing_extensions import Literal
from typing import Any, Dict, Type, Optional
from pydantic import Field, BaseModel, ValidationError
from nonebot.adapters import Event as BaseEvent
from nonebot.adapters import Message as BaseMessage
from nonebot.log import logger
from nonebot.typing import overrides
from nonebot.utils import escape_tag
from nonebot.adapters import Event as BaseEvent
from nonebot.adapters import Message as BaseMessage
class UserPermission(str, Enum):
@ -18,15 +18,28 @@ class UserPermission(str, Enum):
用户权限枚举类
* ``OWNER``: 群主
* ``ADMINISTRATOR``: 群管理
* ``MEMBER``: 普通群成员
* ``OWNER``: 群主
* ``ADMINISTRATOR``: 群管理
* ``MEMBER``: 普通群成员
"""
OWNER = 'OWNER'
ADMINISTRATOR = 'ADMINISTRATOR'
MEMBER = 'MEMBER'
class NudgeSubjectKind(str, Enum):
"""
:说明:
戳一戳类型枚举类
* ``Group``:
* ``Friend``: 好友
"""
Group = 'Group'
Friend = 'Friend'
class GroupInfo(BaseModel):
id: int
name: str
@ -46,6 +59,11 @@ class PrivateChatInfo(BaseModel):
remark: str
class NudgeSubject(BaseModel):
id: int
kind: NudgeSubjectKind
class Event(BaseEvent):
"""
mirai-api-http 协议事件字段与 mirai-api-http 一致各事件字段参考 `mirai-api-http 事件类型`_
@ -89,7 +107,7 @@ class Event(BaseEvent):
@overrides(BaseEvent)
def get_type(self) -> Literal["message", "notice", "request", "meta_event"]:
from . import message, meta, notice, request
from . import meta, notice, message, request
if isinstance(self, message.MessageEvent):
return 'message'
elif isinstance(self, notice.NoticeEvent):

View File

@ -2,7 +2,7 @@ from typing import Any, Optional
from pydantic import Field
from .base import Event, GroupChatInfo, GroupInfo, UserPermission
from .base import Event, GroupChatInfo, GroupInfo, NudgeSubject, UserPermission
class NoticeEvent(Event):
@ -154,3 +154,12 @@ class MemberPermissionChangeEvent(MemberStateChangeEvent):
"""成员权限改变的事件该成员不是Bot"""
origin: UserPermission
current: UserPermission
class NudgeEvent(NoticeEvent):
"""戳一戳触发事件"""
from_id: int = Field(alias='fromId')
target: int
subject: NudgeSubject
action: str
suffix: str