v11.utils

检查/验证

class melobot.protocols.onebot.v11.utils.LevelRole[源代码]

基类:int, Enum

用户权限等级枚举

OWNER = 16
SU = 8
WHITE = 4
NORMAL = 2
BLACK = 1
class melobot.protocols.onebot.v11.utils.GroupRole[源代码]

基类:int, Enum

群权限等级枚举

OWNER = 4
ADMIN = 2
MEMBER = 1
NOT_IN_GROUP = 0
melobot.protocols.onebot.v11.utils.get_level_role(checker: MsgChecker, event: MessageEvent) LevelRole[源代码]

获得消息事件对应的分级权限等级

参数:
返回:

分级权限等级

返回类型:

LevelRole

melobot.protocols.onebot.v11.utils.get_group_role(event: MessageEvent) GroupRole[源代码]

获得消息事件对应的群权限等级

参数:

event (MessageEvent) -- 消息事件

返回:

群权限等级

返回类型:

GroupRole

class melobot.protocols.onebot.v11.utils.MsgChecker[源代码]

基类:Checker[Event]

消息事件分级权限检查器

主要分 主人、超级用户、白名单用户、普通用户、黑名单用户 五级

__init__(role: LevelRole | GroupRole, owner: int | None = None, super_users: list[int] | None = None, white_users: list[int] | None = None, black_users: list[int] | None = None, fail_cb: SyncOrAsyncCallable[(), None] | None = None) None[源代码]

初始化一个消息事件分级权限检查器

参数:
  • role (LevelRole | GroupRole) -- 允许的等级(>= 此等级才能通过校验)

  • owner (int | None) -- 主人的 qq 号

  • super_users (list[int] | None) -- 超级用户 qq 号列表

  • white_users (list[int] | None) -- 白名单用户 qq 号列表

  • black_users (list[int] | None) -- 黑名单用户 qq 号列表

  • fail_cb (SyncOrAsyncCallable[(), None] | None) -- 检查不通过的回调

返回类型:

None

async check(event: Event) bool[源代码]

检查器检查方法

任何检查器应该实现此抽象方法。

参数:

event (Event) -- 给定的事件

返回:

检查是否通过

返回类型:

bool

class melobot.protocols.onebot.v11.utils.GroupMsgChecker[源代码]

基类:MsgChecker

群聊消息事件分级权限检查器

基本功能与 MsgChecker 一致。但增加了白名单机制, 不提供 white_groups 参数默认拒绝所有群聊消息事件。

对所有私聊消息事件校验不通过。

__init__(role: LevelRole | GroupRole, owner: int | None = None, super_users: list[int] | None = None, white_users: list[int] | None = None, black_users: list[int] | None = None, white_groups: list[int] | None = None, fail_cb: SyncOrAsyncCallable[(), None] | None = None) None[源代码]

初始化一个群聊消息事件分级权限检查器

参数:
  • role (LevelRole | GroupRole) -- 允许的等级(>= 此等级才能通过校验)

  • owner (int | None) -- 主人的 qq 号

  • super_users (list[int] | None) -- 超级用户 qq 号列表

  • white_users (list[int] | None) -- 白名单用户 qq 号列表

  • black_users (list[int] | None) -- 黑名单用户 qq 号列表

  • white_groups (list[int] | None) -- 白名单群号列表(不在其中的群不通过校验)

  • fail_cb (SyncOrAsyncCallable[(), None] | None) -- 检查不通过的回调

返回类型:

None

class melobot.protocols.onebot.v11.utils.PrivateMsgChecker[源代码]

基类:MsgChecker

私聊消息事件分级权限检查器

基本功能与 MsgChecker 一致。

对所有群聊消息事件校验不通过。

__init__(role: LevelRole, owner: int | None = None, super_users: list[int] | None = None, white_users: list[int] | None = None, black_users: list[int] | None = None, fail_cb: SyncOrAsyncCallable[(), None] | None = None) None[源代码]

初始化一个私聊消息事件分级权限检查器

参数:
  • role (LevelRole) -- 允许的等级(>= 此等级才能通过校验)

  • owner (int | None) -- 主人的 qq 号

  • super_users (list[int] | None) -- 超级用户 qq 号列表

  • white_users (list[int] | None) -- 白名单用户 qq 号列表

  • black_users (list[int] | None) -- 黑名单用户 qq 号列表

  • fail_cb (SyncOrAsyncCallable[(), None] | None) -- 检查不通过的回调

返回类型:

None

class melobot.protocols.onebot.v11.utils.MsgCheckerFactory[源代码]

基类:object

消息事件分级权限检查器的工厂

预先存储检查依据(各等级数据),指定检查等级后,可返回一个 MsgChecker 类的对象

__init__(owner: int | None = None, super_users: list[int] | None = None, white_users: list[int] | None = None, black_users: list[int] | None = None, white_groups: list[int] | None = None, fail_cb: SyncOrAsyncCallable[(), None] | None = None) None[源代码]

初始化一个消息事件分级权限检查器的工厂

参数:
  • owner (int | None) -- 主人的 qq 号

  • super_users (list[int] | None) -- 超级用户 qq 号列表

  • white_users (list[int] | None) -- 白名单用户 qq 号列表

  • black_users (list[int] | None) -- 黑名单用户 qq 号列表

  • white_groups (list[int] | None) -- 白名单群号列表(不在其中的群不通过校验)

  • fail_cb (SyncOrAsyncCallable[(), None] | None) -- 检查不通过的回调(这将自动附加到生成的检查器上)

返回类型:

None

get_base(role: LevelRole | GroupRole, fail_cb: SyncOrAsyncCallable[(), None] | None = None) MsgChecker[源代码]

根据内部依据和给定等级,生成一个 MsgChecker 对象

参数:
返回:

消息事件分级权限检查器

返回类型:

MsgChecker

get_group(role: LevelRole | GroupRole, fail_cb: SyncOrAsyncCallable[(), None] | None = None) GroupMsgChecker[源代码]

根据内部依据和给定等级,生成一个 GroupMsgChecker 对象

参数:
返回:

群聊消息事件分级权限检查器

返回类型:

GroupMsgChecker

get_private(role: LevelRole, fail_cb: SyncOrAsyncCallable[(), None] | None = None) PrivateMsgChecker[源代码]

根据内部依据和给定等级,生成一个 PrivateMsgChecker 对象

参数:
  • role (LevelRole) -- 允许的等级(>= 此等级才能通过校验)

  • fail_cb (SyncOrAsyncCallable[(), None] | None) -- 检查不通过的回调

返回:

私聊消息事件分级权限检查器

返回类型:

PrivateMsgChecker

class melobot.protocols.onebot.v11.utils.AtMsgChecker[源代码]

基类:Checker

艾特消息事件检查器

__init__(qid: int | Literal['all'] | None = None, fail_cb: SyncOrAsyncCallable[(), None] | None = None) None[源代码]

初始化一个艾特消息事件检查器

参数:
  • qid (int | Literal['all'] | None) -- 被艾特的 qq 号。为空则接受所有艾特消息事件;不为空则只接受指定 qid 被艾特的艾特消息事件

  • fail_cb (SyncOrAsyncCallable[(), None] | None) -- 检查不通过的回调

返回类型:

None

async check(event: Event) bool[源代码]

检查器检查方法

任何检查器应该实现此抽象方法。

参数:

event (Event) -- 给定的事件

返回:

检查是否通过

返回类型:

bool