Skip to content

Commit

Permalink
✨ version 0.8.0
Browse files Browse the repository at this point in the history
add permisson
resolve #35
  • Loading branch information
RF-Tar-Railt committed Jan 4, 2024
1 parent 1bcdcf7 commit 3e3e327
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
3 changes: 2 additions & 1 deletion nonebot/adapters/red/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .permission import *
from .bot import Bot as Bot
from .adapter import Adapter as Adapter
from .message import Message as Message
Expand All @@ -6,4 +7,4 @@
from .event import GroupMessageEvent as GroupMessageEvent
from .event import PrivateMessageEvent as PrivateMessageEvent

__version__ = "0.7.4"
__version__ = "0.8.0"
59 changes: 59 additions & 0 deletions nonebot/adapters/red/permission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from nonebot.permission import Permission

from .event import MessageEvent


async def _private(event: MessageEvent) -> bool:
return event.is_private


async def _private_friend(event: MessageEvent) -> bool:
return event.is_private and event.roleType == 0


async def _private_group(event: MessageEvent) -> bool:
return event.is_private and event.roleType == 1


PRIVATE = Permission(_private)
""" 匹配任意私聊消息类型事件"""
PRIVATE_FRIEND: Permission = Permission(_private_friend)
"""匹配任意好友私聊消息类型事件"""
PRIVATE_GROUP: Permission = Permission(_private_group)
"""匹配任意群临时私聊消息类型事件"""


async def _group(event: MessageEvent) -> bool:
return event.is_group


async def _group_member(event: MessageEvent) -> bool:
return event.is_group and event.roleType == 2


async def _group_admin(event: MessageEvent) -> bool:
return event.is_group and event.roleType == 3


async def _group_owner(event: MessageEvent) -> bool:
return event.is_group and event.roleType == 4


GROUP: Permission = Permission(_group)
"""匹配任意群聊消息类型事件"""
GROUP_MEMBER: Permission = Permission(_group_member)
"""匹配任意群员群聊消息类型事件"""
GROUP_ADMIN: Permission = Permission(_group_admin)
"""匹配任意群管理员群聊消息类型事件"""
GROUP_OWNER: Permission = Permission(_group_owner)
"""匹配任意群主群聊消息类型事件"""

__all__ = [
"PRIVATE",
"PRIVATE_FRIEND",
"PRIVATE_GROUP",
"GROUP",
"GROUP_MEMBER",
"GROUP_ADMIN",
"GROUP_OWNER",
]
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ ignore = ["C901", "T201", "E731"]

line-length = 88
target-version = "py38"

[tool.ruff.per-file-ignores]
"nonebot/adapters/red/__init__.py" = ["F403"]

0 comments on commit 3e3e327

Please sign in to comment.