mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-12 06:56:41 +00:00
📝 update doc
This commit is contained in:
@ -11,6 +11,7 @@ CQHTTP (OneBot) v11 协议适配
|
||||
"""
|
||||
|
||||
from .event import *
|
||||
from .permission import *
|
||||
from .message import Message, MessageSegment
|
||||
from .utils import log, escape, unescape, _b2s
|
||||
from .bot import Bot, _check_at_me, _check_nickname, _check_reply, _handle_api_result
|
||||
|
@ -14,7 +14,7 @@ from .message import Message
|
||||
|
||||
class Event(BaseEvent):
|
||||
"""
|
||||
CQHTTP 协议事件。各事件字段未列出部分参考 `CQHTTP 文档`_
|
||||
CQHTTP 协议事件,字段与 CQHTTP 一致。各事件字段参考 `CQHTTP 文档`_
|
||||
|
||||
.. _CQHTTP 文档:
|
||||
https://github.com/howmanybots/onebot/blob/master/README.md
|
||||
|
86
nonebot/adapters/cqhttp/permission.py
Normal file
86
nonebot/adapters/cqhttp/permission.py
Normal file
@ -0,0 +1,86 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from nonebot.permission import Permission
|
||||
|
||||
from .event import PrivateMessageEvent, GroupMessageEvent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from nonebot.adapters import Bot, Event
|
||||
|
||||
|
||||
async def _private(bot: "Bot", event: "Event") -> bool:
|
||||
return isinstance(event, PrivateMessageEvent)
|
||||
|
||||
|
||||
async def _private_friend(bot: "Bot", event: "Event") -> bool:
|
||||
return isinstance(event, PrivateMessageEvent) and event.sub_type == "friend"
|
||||
|
||||
|
||||
async def _private_group(bot: "Bot", event: "Event") -> bool:
|
||||
return isinstance(event, PrivateMessageEvent) and event.sub_type == "group"
|
||||
|
||||
|
||||
async def _private_other(bot: "Bot", event: "Event") -> bool:
|
||||
return isinstance(event, PrivateMessageEvent) and event.sub_type == "other"
|
||||
|
||||
|
||||
PRIVATE = Permission(_private)
|
||||
"""
|
||||
- **说明**: 匹配任意私聊消息类型事件
|
||||
"""
|
||||
PRIVATE_FRIEND = Permission(_private_friend)
|
||||
"""
|
||||
- **说明**: 匹配任意好友私聊消息类型事件
|
||||
"""
|
||||
PRIVATE_GROUP = Permission(_private_group)
|
||||
"""
|
||||
- **说明**: 匹配任意群临时私聊消息类型事件
|
||||
"""
|
||||
PRIVATE_OTHER = Permission(_private_other)
|
||||
"""
|
||||
- **说明**: 匹配任意其他私聊消息类型事件
|
||||
"""
|
||||
|
||||
|
||||
async def _group(bot: "Bot", event: "Event") -> bool:
|
||||
return isinstance(event, GroupMessageEvent)
|
||||
|
||||
|
||||
async def _group_member(bot: "Bot", event: "Event") -> bool:
|
||||
return isinstance(event,
|
||||
GroupMessageEvent) and event.sender.role == "member"
|
||||
|
||||
|
||||
async def _group_admin(bot: "Bot", event: "Event") -> bool:
|
||||
return isinstance(event, GroupMessageEvent) and event.sender.role == "admin"
|
||||
|
||||
|
||||
async def _group_owner(bot: "Bot", event: "Event") -> bool:
|
||||
return isinstance(event, GroupMessageEvent) and event.sender.role == "owner"
|
||||
|
||||
|
||||
GROUP = Permission(_group)
|
||||
"""
|
||||
- **说明**: 匹配任意群聊消息类型事件
|
||||
"""
|
||||
GROUP_MEMBER = Permission(_group_member)
|
||||
"""
|
||||
- **说明**: 匹配任意群员群聊消息类型事件
|
||||
|
||||
\:\:\:warning 警告
|
||||
该权限通过 event.sender 进行判断且不包含管理员以及群主!
|
||||
\:\:\:
|
||||
"""
|
||||
GROUP_ADMIN = Permission(_group_admin)
|
||||
"""
|
||||
- **说明**: 匹配任意群管理员群聊消息类型事件
|
||||
"""
|
||||
GROUP_OWNER = Permission(_group_owner)
|
||||
"""
|
||||
- **说明**: 匹配任意群主群聊消息类型事件
|
||||
"""
|
||||
|
||||
__all__ = [
|
||||
"PRIVATE", "PRIVATE_FRIEND", "PRIVATE_GROUP", "PRIVATE_OTHER", "GROUP",
|
||||
"GROUP_MEMBER", "GROUP_ADMIN", "GROUP_OWNER"
|
||||
]
|
Reference in New Issue
Block a user