跳转至

validator

CertainFriend 🔗

Bases: Certain

需要消息发送者/事件触发者是指定好友

Source code in src/graia/ariadne/util/validator.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class CertainFriend(Certain):
    """需要消息发送者/事件触发者是指定好友"""

    value: Set[int]

    def __init__(self, friend: SequenceOrInstance[Union[Friend, int]]):
        """
        Args:
            friend (SequenceOrInstance[Union[Friend, int]]): 一个好友/好友 QQ 号的列表/对象
        """
        friend = list(friend) if isinstance(friend, Sequence) else [friend]
        super().__init__({int(f) for f in friend}, Friend)

    def comp(self, value: Friend) -> bool:
        return value.id in self.value

__init__ 🔗

__init__(friend: SequenceOrInstance[Union[Friend, int]])

Parameters:

  • friend (SequenceOrInstance[Union[Friend, int]]) –

    一个好友/好友 QQ 号的列表/对象

Source code in src/graia/ariadne/util/validator.py
61
62
63
64
65
66
67
def __init__(self, friend: SequenceOrInstance[Union[Friend, int]]):
    """
    Args:
        friend (SequenceOrInstance[Union[Friend, int]]): 一个好友/好友 QQ 号的列表/对象
    """
    friend = list(friend) if isinstance(friend, Sequence) else [friend]
    super().__init__({int(f) for f in friend}, Friend)

CertainGroup 🔗

Bases: Certain

需要消息发送/事件触发在指定群组

Source code in src/graia/ariadne/util/validator.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class CertainGroup(Certain):
    """需要消息发送/事件触发在指定群组"""

    value: Set[int]

    def __init__(self, group: SequenceOrInstance[Union[Group, int]]):
        """
        Args:
            group (SequenceOrInstance[Union[Group, int]]): 一个群/群号的列表/对象
        """
        group = list(group) if isinstance(group, Sequence) else [group]
        super().__init__({int(g) for g in group}, Group)

    def comp(self, value: Group) -> bool:
        return value.id in self.value

__init__ 🔗

__init__(group: SequenceOrInstance[Union[Group, int]])

Parameters:

  • group (SequenceOrInstance[Union[Group, int]]) –

    一个群/群号的列表/对象

Source code in src/graia/ariadne/util/validator.py
44
45
46
47
48
49
50
def __init__(self, group: SequenceOrInstance[Union[Group, int]]):
    """
    Args:
        group (SequenceOrInstance[Union[Group, int]]): 一个群/群号的列表/对象
    """
    group = list(group) if isinstance(group, Sequence) else [group]
    super().__init__({int(g) for g in group}, Group)

CertainMember 🔗

Bases: Certain

需要发送者/事件触发者是指定群员

Source code in src/graia/ariadne/util/validator.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
class CertainMember(Certain):
    """需要发送者/事件触发者是指定群员"""

    value: Set[int]
    group: Optional[Set[int]]

    def __init__(
        self,
        member: SequenceOrInstance[Union[Member, int]],
        group: Optional[SequenceOrInstance[Union[Member, int]]] = None,
    ):
        """
        Args:
            member (SequenceOrInstance[Union[Member, int]]): 成员或成员QQ号的列表/对象
            group (SequenceOrInstance[Union[Group, int]], optional): 如果提供, 则要求群员在传入的群内
        """
        member = list(member) if isinstance(member, Sequence) else [member]
        super().__init__({int(m) for m in member}, Member)
        self.group = None
        if group:
            group = list(group) if isinstance(group, Sequence) else [group]
            self.group = {int(g) for g in group}

    def comp(self, value: Member) -> bool:
        return value.id in self.value and (not self.group or value.group.id in self.group)

__init__ 🔗

__init__(
    member: SequenceOrInstance[Union[Member, int]],
    group: Optional[SequenceOrInstance[Union[Member, int]]] = None,
)

Parameters:

  • member (SequenceOrInstance[Union[Member, int]]) –

    成员或成员QQ号的列表/对象

  • group (SequenceOrInstance[Union[Group, int]]) –

    如果提供, 则要求群员在传入的群内

Source code in src/graia/ariadne/util/validator.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def __init__(
    self,
    member: SequenceOrInstance[Union[Member, int]],
    group: Optional[SequenceOrInstance[Union[Member, int]]] = None,
):
    """
    Args:
        member (SequenceOrInstance[Union[Member, int]]): 成员或成员QQ号的列表/对象
        group (SequenceOrInstance[Union[Group, int]], optional): 如果提供, 则要求群员在传入的群内
    """
    member = list(member) if isinstance(member, Sequence) else [member]
    super().__init__({int(m) for m in member}, Member)
    self.group = None
    if group:
        group = list(group) if isinstance(group, Sequence) else [group]
        self.group = {int(g) for g in group}

Quoting 🔗

Bases: Decorator

需要回复指定的消息

Source code in src/graia/ariadne/util/validator.py
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
class Quoting(Decorator):
    """需要回复指定的消息"""

    pre = True

    msg_ids: Set[int]

    def __init__(self, message: SequenceOrInstance[Union[int, ActiveMessage, Source]]):
        """
        Args:
            message (SequenceOrInstance[Union[int, ActiveMessage, Source]]): 要回复的指定信息
        """
        if not isinstance(message, Sequence):
            message = [message]
        self.msg_ids = set()
        for msg in message:
            if isinstance(msg, (ActiveMessage, Source)):
                self.msg_ids.add(msg.id)
            else:
                self.msg_ids.add(msg)

    async def target(self, i: DecoratorInterface):
        try:
            quote: Union[Quote, None] = await i.dispatcher_interface.lookup_param(
                "__decorator_parameter_quote__", Union[Quote, None], None
            )
            if not quote or quote.id not in self.msg_ids:
                raise RequirementCrashed
        except RequirementCrashed as e:
            raise ExecutionStop from e
        return await i.dispatcher_interface.lookup_param("__decorator_parameter__", MessageChain, None)

__init__ 🔗

__init__(message: SequenceOrInstance[Union[int, ActiveMessage, Source]])

Parameters:

Source code in src/graia/ariadne/util/validator.py
107
108
109
110
111
112
113
114
115
116
117
118
119
def __init__(self, message: SequenceOrInstance[Union[int, ActiveMessage, Source]]):
    """
    Args:
        message (SequenceOrInstance[Union[int, ActiveMessage, Source]]): 要回复的指定信息
    """
    if not isinstance(message, Sequence):
        message = [message]
    self.msg_ids = set()
    for msg in message:
        if isinstance(msg, (ActiveMessage, Source)):
            self.msg_ids.add(msg.id)
        else:
            self.msg_ids.add(msg)