跳转至

model

Ariadne 各种 model 存放的位置

Announcement 🔗

Bases: AriadneBaseModel

群公告

Source code in src/graia/ariadne/model/__init__.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
@internal_cls()
class Announcement(AriadneBaseModel):
    """群公告"""

    group: Group
    """公告所在的群"""

    senderId: int
    """发送者QQ号"""

    fid: str
    """公告唯一标识ID"""

    all_confirmed: bool = Field(..., alias="allConfirmed")
    """群成员是否已全部确认"""

    confirmed_members_count: int = Field(..., alias="confirmedMembersCount")
    """已确认群成员人数"""

    publication_time: datetime = Field(..., alias="publicationTime")
    """公告发布时间"""

all_confirmed class-attribute instance-attribute 🔗

all_confirmed: bool = Field(..., alias='allConfirmed')

群成员是否已全部确认

confirmed_members_count class-attribute instance-attribute 🔗

confirmed_members_count: int = Field(..., alias='confirmedMembersCount')

已确认群成员人数

fid instance-attribute 🔗

fid: str

公告唯一标识ID

group instance-attribute 🔗

group: Group

公告所在的群

publication_time class-attribute instance-attribute 🔗

publication_time: datetime = Field(..., alias='publicationTime')

公告发布时间

senderId instance-attribute 🔗

senderId: int

发送者QQ号

AriadneBaseModel 🔗

Bases: BaseModel

Ariadne 一切数据模型的基类.

Source code in src/graia/ariadne/model/util.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class AriadneBaseModel(BaseModel):
    """Ariadne 一切数据模型的基类."""

    def __init__(self, **data: Any) -> None:
        """初始化模型. 直接向 pydantic 转发."""
        super().__init__(**data)

    def dict(
        self,
        *,
        include: Union[None, "AbstractSetIntStr", "MappingIntStrAny"] = None,
        exclude: Union[None, "AbstractSetIntStr", "MappingIntStrAny"] = None,
        by_alias: bool = False,
        skip_defaults: bool = False,
        exclude_unset: bool = False,
        exclude_defaults: bool = False,
        exclude_none: bool = False,
        to_camel: bool = False,
    ) -> "DictStrAny":
        """转化为字典, 直接向 pydantic 转发."""
        _, *_ = by_alias, exclude_none, skip_defaults
        data = super().dict(
            include=include,  # type: ignore
            exclude=exclude,  # type: ignore
            by_alias=True,
            exclude_unset=exclude_unset,
            exclude_defaults=exclude_defaults,
            exclude_none=True,
        )
        if to_camel:
            data = {snake_to_camel(k): v for k, v in data.items()}
        return data

    class Config(BaseConfig):
        """Ariadne BaseModel 设置"""

        extra = Extra.allow
        arbitrary_types_allowed = True
        copy_on_model_validation = "none"
        json_encoders = {
            datetime: lambda dt: int(dt.timestamp()),
        }

Config 🔗

Bases: BaseConfig

Ariadne BaseModel 设置

Source code in src/graia/ariadne/model/util.py
47
48
49
50
51
52
53
54
55
class Config(BaseConfig):
    """Ariadne BaseModel 设置"""

    extra = Extra.allow
    arbitrary_types_allowed = True
    copy_on_model_validation = "none"
    json_encoders = {
        datetime: lambda dt: int(dt.timestamp()),
    }

__init__ 🔗

__init__(**data: Any) -> None

初始化模型. 直接向 pydantic 转发.

Source code in src/graia/ariadne/model/util.py
17
18
19
def __init__(self, **data: Any) -> None:
    """初始化模型. 直接向 pydantic 转发."""
    super().__init__(**data)

dict 🔗

dict(
    *,
    include: Union[None, AbstractSetIntStr, MappingIntStrAny] = None,
    exclude: Union[None, AbstractSetIntStr, MappingIntStrAny] = None,
    by_alias: bool = False,
    skip_defaults: bool = False,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False,
    to_camel: bool = False
) -> DictStrAny

转化为字典, 直接向 pydantic 转发.

Source code in src/graia/ariadne/model/util.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def dict(
    self,
    *,
    include: Union[None, "AbstractSetIntStr", "MappingIntStrAny"] = None,
    exclude: Union[None, "AbstractSetIntStr", "MappingIntStrAny"] = None,
    by_alias: bool = False,
    skip_defaults: bool = False,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False,
    to_camel: bool = False,
) -> "DictStrAny":
    """转化为字典, 直接向 pydantic 转发."""
    _, *_ = by_alias, exclude_none, skip_defaults
    data = super().dict(
        include=include,  # type: ignore
        exclude=exclude,  # type: ignore
        by_alias=True,
        exclude_unset=exclude_unset,
        exclude_defaults=exclude_defaults,
        exclude_none=True,
    )
    if to_camel:
        data = {snake_to_camel(k): v for k, v in data.items()}
    return data

Client 🔗

Bases: AriadneBaseModel

指示其他客户端

Source code in src/graia/ariadne/model/relationship.py
327
328
329
330
331
332
333
334
335
336
337
338
class Client(AriadneBaseModel):
    """
    指示其他客户端
    """

    id: int
    """客户端 ID"""

    platform: str
    """平台字符串表示"""

    __kind: Optional[Literal["OtherClient"]] = Field(None, alias="kind")

id instance-attribute 🔗

id: int

客户端 ID

platform instance-attribute 🔗

platform: str

平台字符串表示

DownloadInfo 🔗

Bases: AriadneBaseModel

描述一个文件的下载信息.

Source code in src/graia/ariadne/model/__init__.py
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
@internal_cls()
class DownloadInfo(AriadneBaseModel):
    """描述一个文件的下载信息."""

    sha: str = ""
    """文件 SHA256"""

    md5: str = ""
    """文件 MD5"""

    download_times: int = Field(..., alias="downloadTimes")
    """下载次数"""

    uploader_id: int = Field(..., alias="uploaderId")
    """上传者 QQ 号"""

    upload_time: datetime = Field(..., alias="uploadTime")
    """上传时间"""

    last_modify_time: datetime = Field(..., alias="lastModifyTime")
    """最后修改时间"""

    url: Optional[str] = None
    """下载 url"""

download_times class-attribute instance-attribute 🔗

download_times: int = Field(..., alias='downloadTimes')

下载次数

last_modify_time class-attribute instance-attribute 🔗

last_modify_time: datetime = Field(..., alias='lastModifyTime')

最后修改时间

md5 class-attribute instance-attribute 🔗

md5: str = ''

文件 MD5

sha class-attribute instance-attribute 🔗

sha: str = ''

文件 SHA256

upload_time class-attribute instance-attribute 🔗

upload_time: datetime = Field(..., alias='uploadTime')

上传时间

uploader_id class-attribute instance-attribute 🔗

uploader_id: int = Field(..., alias='uploaderId')

上传者 QQ 号

url class-attribute instance-attribute 🔗

url: Optional[str] = None

下载 url

FileInfo 🔗

Bases: AriadneBaseModel

群组文件详细信息

Source code in src/graia/ariadne/model/__init__.py
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
@internal_cls()
class FileInfo(AriadneBaseModel):
    """群组文件详细信息"""

    name: str = ""
    """文件名"""

    path: str = ""
    """文件路径的字符串表示"""

    id: Optional[str] = ""
    """文件 ID"""

    parent: Optional["FileInfo"] = None
    """父文件夹的 FileInfo 对象, 没有则表示存在于根目录"""

    contact: Optional[Union[Group, Friend]] = None
    """文件所在位置 (群组)"""

    is_file: bool = Field(..., alias="isFile")
    """是否为文件"""

    is_directory: bool = Field(..., alias="isDirectory")
    """是否为目录"""

    download_info: Optional[DownloadInfo] = Field(None, alias="downloadInfo")
    """下载信息"""

    @validator("contact", pre=True, allow_reuse=True)
    def _(cls, val: Optional[dict]):
        if not val:
            return None
        return Friend.parse_obj(val) if "remark" in val else Group.parse_obj(val)

contact class-attribute instance-attribute 🔗

contact: Optional[Union[Group, Friend]] = None

文件所在位置 (群组)

download_info class-attribute instance-attribute 🔗

download_info: Optional[DownloadInfo] = Field(None, alias='downloadInfo')

下载信息

id class-attribute instance-attribute 🔗

id: Optional[str] = ''

文件 ID

is_directory class-attribute instance-attribute 🔗

is_directory: bool = Field(..., alias='isDirectory')

是否为目录

is_file class-attribute instance-attribute 🔗

is_file: bool = Field(..., alias='isFile')

是否为文件

name class-attribute instance-attribute 🔗

name: str = ''

文件名

parent class-attribute instance-attribute 🔗

parent: Optional[FileInfo] = None

父文件夹的 FileInfo 对象, 没有则表示存在于根目录

path class-attribute instance-attribute 🔗

path: str = ''

文件路径的字符串表示

Friend 🔗

Bases: AriadneBaseModel

描述 Tencent QQ 中的好友.

Source code in src/graia/ariadne/model/relationship.py
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
class Friend(AriadneBaseModel):
    """描述 Tencent QQ 中的好友."""

    id: int
    """QQ 号"""

    nickname: str
    """昵称"""

    remark: str
    """自行设置的代称"""

    __kind: Optional[Literal["Friend"]] = Field(None, alias="kind")

    def __int__(self):
        return self.id

    def __str__(self) -> str:
        return f"{self.remark}({self.id})"

    def __eq__(self, other: Any) -> bool:
        return isinstance(other, (Friend, Member, Stranger)) and self.id == other.id

    async def get_profile(self) -> "Profile":
        """获取该好友的 Profile

        Returns:
            Profile: 该好友的 Profile 对象
        """
        from ..app import Ariadne

        return await Ariadne.current().get_friend_profile(self)

    async def get_avatar(self, size: Literal[640, 140] = 640) -> bytes:
        """获取该好友的头像

        Args:
            size (Literal[640, 140]): 头像尺寸

        Returns:
            bytes: 好友头像的二进制内容.
        """
        from ..app import Ariadne

        async with Ariadne.service.client_session.get(
            f"https://q2.qlogo.cn/headimg_dl?dst_uin={self.id}&spec={size}"
        ) as resp:
            return await resp.read()

id instance-attribute 🔗

id: int

QQ 号

nickname instance-attribute 🔗

nickname: str

昵称

remark instance-attribute 🔗

remark: str

自行设置的代称

get_avatar async 🔗

get_avatar(size: Literal[640, 140] = 640) -> bytes

获取该好友的头像

Parameters:

  • size (Literal[640, 140]) –

    头像尺寸

Returns:

  • bytes( bytes ) –

    好友头像的二进制内容.

Source code in src/graia/ariadne/model/relationship.py
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
async def get_avatar(self, size: Literal[640, 140] = 640) -> bytes:
    """获取该好友的头像

    Args:
        size (Literal[640, 140]): 头像尺寸

    Returns:
        bytes: 好友头像的二进制内容.
    """
    from ..app import Ariadne

    async with Ariadne.service.client_session.get(
        f"https://q2.qlogo.cn/headimg_dl?dst_uin={self.id}&spec={size}"
    ) as resp:
        return await resp.read()

get_profile async 🔗

get_profile() -> Profile

获取该好友的 Profile

Returns:

  • Profile( Profile ) –

    该好友的 Profile 对象

Source code in src/graia/ariadne/model/relationship.py
225
226
227
228
229
230
231
232
233
async def get_profile(self) -> "Profile":
    """获取该好友的 Profile

    Returns:
        Profile: 该好友的 Profile 对象
    """
    from ..app import Ariadne

    return await Ariadne.current().get_friend_profile(self)

Group 🔗

Bases: AriadneBaseModel

描述 Tencent QQ 中的群组.

Source code in src/graia/ariadne/model/relationship.py
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 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
 98
 99
100
class Group(AriadneBaseModel):
    """描述 Tencent QQ 中的群组."""

    id: int
    """群号"""

    name: str
    """群名"""

    account_perm: MemberPerm = Field(..., alias="permission")
    """你在群中的权限"""

    __kind: Optional[Literal["Group"]] = Field(None, alias="kind")

    def __int__(self):
        return self.id

    def __str__(self) -> str:
        return f"{self.name}({self.id})"

    def __eq__(self, other: Any) -> bool:
        return isinstance(other, Group) and self.id == other.id

    async def get_config(self) -> "GroupConfig":
        """获取该群组的 Config

        Returns:
            Config: 该群组的设置对象.
        """
        from ..app import Ariadne

        return await Ariadne.current().get_group_config(self)

    async def modify_config(self, config: "GroupConfig") -> None:
        """修改该群组的 Config

        Args:
            config (GroupConfig): 经过修改后的群设置对象.
        """
        from ..app import Ariadne

        return await Ariadne.current().modify_group_config(self, config)

    async def get_avatar(self, cover: Optional[int] = None) -> bytes:
        """获取该群组的头像
        Args:
            cover (Optional[int]): 群封面标号 (若为 None 则获取该群头像, 否则获取该群封面)

        Returns:
            bytes: 群头像的二进制内容.
        """
        from ..app import Ariadne

        cover = (cover or 0) + 1
        rider = await Ariadne.service.http_interface.request(
            "GET", f"http://p.qlogo.cn/gh/{self.id}/{self.id}_{cover}/"
        )
        return await rider.io().read()

account_perm class-attribute instance-attribute 🔗

account_perm: MemberPerm = Field(..., alias='permission')

你在群中的权限

id instance-attribute 🔗

id: int

群号

name instance-attribute 🔗

name: str

群名

get_avatar async 🔗

get_avatar(cover: Optional[int] = None) -> bytes

获取该群组的头像

Parameters:

  • cover (Optional[int]) –

    群封面标号 (若为 None 则获取该群头像, 否则获取该群封面)

Returns:

  • bytes( bytes ) –

    群头像的二进制内容.

Source code in src/graia/ariadne/model/relationship.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
async def get_avatar(self, cover: Optional[int] = None) -> bytes:
    """获取该群组的头像
    Args:
        cover (Optional[int]): 群封面标号 (若为 None 则获取该群头像, 否则获取该群封面)

    Returns:
        bytes: 群头像的二进制内容.
    """
    from ..app import Ariadne

    cover = (cover or 0) + 1
    rider = await Ariadne.service.http_interface.request(
        "GET", f"http://p.qlogo.cn/gh/{self.id}/{self.id}_{cover}/"
    )
    return await rider.io().read()

get_config async 🔗

get_config() -> GroupConfig

获取该群组的 Config

Returns:

Source code in src/graia/ariadne/model/relationship.py
66
67
68
69
70
71
72
73
74
async def get_config(self) -> "GroupConfig":
    """获取该群组的 Config

    Returns:
        Config: 该群组的设置对象.
    """
    from ..app import Ariadne

    return await Ariadne.current().get_group_config(self)

modify_config async 🔗

modify_config(config: GroupConfig) -> None

修改该群组的 Config

Parameters:

  • config (GroupConfig) –

    经过修改后的群设置对象.

Source code in src/graia/ariadne/model/relationship.py
76
77
78
79
80
81
82
83
84
async def modify_config(self, config: "GroupConfig") -> None:
    """修改该群组的 Config

    Args:
        config (GroupConfig): 经过修改后的群设置对象.
    """
    from ..app import Ariadne

    return await Ariadne.current().modify_group_config(self, config)

GroupConfig 🔗

Bases: AriadneBaseModel

描述群组各项功能的设置.

Source code in src/graia/ariadne/model/relationship.py
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
class GroupConfig(AriadneBaseModel):
    """描述群组各项功能的设置."""

    name: str = ""
    """群名"""

    announcement: str = ""
    """群公告"""

    confess_talk: bool = False
    """开启坦白说"""

    allow_member_invite: bool = False
    """允许群成员直接邀请入群"""

    auto_approve: bool = False
    """自动通过加群申请"""

    anonymous_chat: bool = False
    """允许匿名聊天"""

    mute_all: bool = Field(False, exclude=True)
    """是否在全员禁言"""

allow_member_invite class-attribute instance-attribute 🔗

allow_member_invite: bool = False

允许群成员直接邀请入群

announcement class-attribute instance-attribute 🔗

announcement: str = ''

群公告

anonymous_chat class-attribute instance-attribute 🔗

anonymous_chat: bool = False

允许匿名聊天

auto_approve class-attribute instance-attribute 🔗

auto_approve: bool = False

自动通过加群申请

confess_talk class-attribute instance-attribute 🔗

confess_talk: bool = False

开启坦白说

mute_all class-attribute instance-attribute 🔗

mute_all: bool = Field(False, exclude=True)

是否在全员禁言

name class-attribute instance-attribute 🔗

name: str = ''

群名

LogConfig 🔗

Bases: Dict[Type['MiraiEvent'], Optional[str]]

Source code in src/graia/ariadne/model/__init__.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class LogConfig(Dict[Type["MiraiEvent"], Optional[str]]):
    def __init__(
        self,
        log_level: Union[str, Callable[["MiraiEvent"], Optional[str]]] = "INFO",
        extra: Optional[Dict[Union[Type["MiraiEvent"], str], Optional[str]]] = None,
    ):
        """
        Args:
            log_level (Union[str, Callable[["MiraiEvent"], str]]): 日志级别, \
            可以是字符串或者一个函数, 函数的参数是 MiraiEvent 对象, 返回字符串
            extra (Optional[Dict[Type["MiraiEvent"], str], Optional[str]]]): \
            额外的事件日志格式, 键为事件类型或事件名, 值为日志格式, None 则禁用该事件日志
        """
        from ..event import MiraiEvent
        from ..event.message import (
            ActiveMessage,
            FriendMessage,
            GroupMessage,
            OtherClientMessage,
            StrangerMessage,
            TempMessage,
        )

        extra = extra or {}

        self.log_level: Callable[[MiraiEvent], Optional[str]] = (
            log_level if callable(log_level) else lambda _: log_level
        )

        account_seg = "{ariadne.account}"
        msg_chain_seg = "{event.message_chain.safe_display}"
        sender_seg = "{event.sender.name}({event.sender.id})"
        user_seg = "{event.sender.nickname}({event.sender.id})"
        group_seg = "{event.sender.group.name}({event.sender.group.id})"
        client_seg = "{event.sender.platform}({event.sender.id})"
        self.update(
            {
                GroupMessage: f"{account_seg}: [RECV][{group_seg}] {sender_seg} -> {msg_chain_seg}",
                TempMessage: f"{account_seg}: [RECV][{group_seg}:{sender_seg}] -> {msg_chain_seg}",
                FriendMessage: f"{account_seg}: [RECV][{user_seg}] -> {msg_chain_seg}",
                StrangerMessage: f"{account_seg}: [RECV][{user_seg}] -> {msg_chain_seg}",
                OtherClientMessage: f"{account_seg}: [RECV][{client_seg}] -> {msg_chain_seg}",
            }
        )
        for active_msg_cls in gen_subclass(ActiveMessage):
            label: str = "[SYNC] " if active_msg_cls.__fields__["sync"].default else "[SEND]"
            self[active_msg_cls] = f"{account_seg}: {label}[{{event.subject}}] <- {msg_chain_seg}"
        self.update({sub: extra[sub.__name__] for sub in gen_subclass(MiraiEvent) if sub.__name__ in extra})

    def event_hook(self, app: "Ariadne") -> Callable[["MiraiEvent"], Awaitable[None]]:
        return functools.partial(self.log, app)

    async def log(self, app: "Ariadne", event: "MiraiEvent") -> None:
        log_level: Optional[str] = self.log_level(event)
        fmt: Optional[str] = self.get(type(event))
        if log_level and fmt:
            logger.log(log_level, fmt.format(event=event, ariadne=app))

__init__ 🔗

__init__(
    log_level: Union[str, Callable[[MiraiEvent], Optional[str]]] = "INFO",
    extra: Optional[Dict[Union[Type[MiraiEvent], str], Optional[str]]] = None,
)

Parameters:

  • log_level (Union[str, Callable[[MiraiEvent], str]]) –

    日志级别, 可以是字符串或者一个函数, 函数的参数是 MiraiEvent 对象, 返回字符串

  • extra (Optional[Dict[Type["MiraiEvent"], str], Optional[str]]]) –

    额外的事件日志格式, 键为事件类型或事件名, 值为日志格式, None 则禁用该事件日志

Source code in src/graia/ariadne/model/__init__.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def __init__(
    self,
    log_level: Union[str, Callable[["MiraiEvent"], Optional[str]]] = "INFO",
    extra: Optional[Dict[Union[Type["MiraiEvent"], str], Optional[str]]] = None,
):
    """
    Args:
        log_level (Union[str, Callable[["MiraiEvent"], str]]): 日志级别, \
        可以是字符串或者一个函数, 函数的参数是 MiraiEvent 对象, 返回字符串
        extra (Optional[Dict[Type["MiraiEvent"], str], Optional[str]]]): \
        额外的事件日志格式, 键为事件类型或事件名, 值为日志格式, None 则禁用该事件日志
    """
    from ..event import MiraiEvent
    from ..event.message import (
        ActiveMessage,
        FriendMessage,
        GroupMessage,
        OtherClientMessage,
        StrangerMessage,
        TempMessage,
    )

    extra = extra or {}

    self.log_level: Callable[[MiraiEvent], Optional[str]] = (
        log_level if callable(log_level) else lambda _: log_level
    )

    account_seg = "{ariadne.account}"
    msg_chain_seg = "{event.message_chain.safe_display}"
    sender_seg = "{event.sender.name}({event.sender.id})"
    user_seg = "{event.sender.nickname}({event.sender.id})"
    group_seg = "{event.sender.group.name}({event.sender.group.id})"
    client_seg = "{event.sender.platform}({event.sender.id})"
    self.update(
        {
            GroupMessage: f"{account_seg}: [RECV][{group_seg}] {sender_seg} -> {msg_chain_seg}",
            TempMessage: f"{account_seg}: [RECV][{group_seg}:{sender_seg}] -> {msg_chain_seg}",
            FriendMessage: f"{account_seg}: [RECV][{user_seg}] -> {msg_chain_seg}",
            StrangerMessage: f"{account_seg}: [RECV][{user_seg}] -> {msg_chain_seg}",
            OtherClientMessage: f"{account_seg}: [RECV][{client_seg}] -> {msg_chain_seg}",
        }
    )
    for active_msg_cls in gen_subclass(ActiveMessage):
        label: str = "[SYNC] " if active_msg_cls.__fields__["sync"].default else "[SEND]"
        self[active_msg_cls] = f"{account_seg}: {label}[{{event.subject}}] <- {msg_chain_seg}"
    self.update({sub: extra[sub.__name__] for sub in gen_subclass(MiraiEvent) if sub.__name__ in extra})

Member 🔗

Bases: AriadneBaseModel

描述用户在群组中所具备的有关状态, 包括所在群组, 群中昵称, 所具备的权限, 唯一ID.

Source code in src/graia/ariadne/model/relationship.py
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
class Member(AriadneBaseModel):
    """描述用户在群组中所具备的有关状态, 包括所在群组, 群中昵称, 所具备的权限, 唯一ID."""

    id: int
    """QQ 号"""

    name: str = Field(..., alias="memberName")
    """显示名称"""

    permission: MemberPerm
    """群权限"""

    special_title: Optional[str] = Field(None, alias="specialTitle")
    """特殊头衔"""

    join_timestamp: Optional[int] = Field(None, alias="joinTimestamp")
    """加入的时间"""

    last_speak_timestamp: Optional[int] = Field(None, alias="lastSpeakTimestamp")
    """最后发言时间"""

    mute_time: Optional[int] = Field(None, alias="mutetimeRemaining")
    """禁言剩余时间"""

    group: Group
    """所在群组"""

    def __str__(self) -> str:
        return f"{self.name}({self.id} @ {self.group})"

    def __int__(self):
        return self.id

    def __eq__(self, other: Any) -> bool:
        return isinstance(other, (Friend, Member, Stranger)) and self.id == other.id

    async def get_profile(self) -> "Profile":
        """获取该群成员的 Profile

        Returns:
            Profile: 该群成员的 Profile 对象
        """
        from ..app import Ariadne

        return await Ariadne.current().get_member_profile(self)

    async def get_info(self) -> "MemberInfo":
        """获取该成员的可修改状态

        Returns:
            MemberInfo: 群组成员的可修改状态
        """
        return MemberInfo(name=self.name, specialTitle=self.special_title)

    async def modify_info(self, info: "MemberInfo") -> None:
        """
        修改群组成员的可修改状态; 需要具有相应权限(管理员/群主).

        Args:
            info (MemberInfo): 已修改的指定群组成员的可修改状态

        Returns:
            None: 没有返回.
        """
        from ..app import Ariadne

        return await Ariadne.current().modify_member_info(self, info)

    async def modify_admin(self, assign: bool) -> None:
        """
        修改一位群组成员管理员权限; 需要有相应权限(群主)

        Args:
            assign (bool): 是否设置群成员为管理员.

        Returns:
            None: 没有返回.
        """
        from ..app import Ariadne

        return await Ariadne.current().modify_member_admin(assign, self)

    async def get_avatar(self, size: Literal[640, 140] = 640) -> bytes:
        """获取该群成员的头像

        Args:
            size (Literal[640, 140]): 头像尺寸

        Returns:
            bytes: 群成员头像的二进制内容.
        """
        from ..app import Ariadne

        async with Ariadne.service.client_session.get(
            f"https://q2.qlogo.cn/headimg_dl?dst_uin={self.id}&spec={size}"
        ) as resp:
            return await resp.read()

group instance-attribute 🔗

group: Group

所在群组

id instance-attribute 🔗

id: int

QQ 号

join_timestamp class-attribute instance-attribute 🔗

join_timestamp: Optional[int] = Field(None, alias='joinTimestamp')

加入的时间

last_speak_timestamp class-attribute instance-attribute 🔗

last_speak_timestamp: Optional[int] = Field(None, alias='lastSpeakTimestamp')

最后发言时间

mute_time class-attribute instance-attribute 🔗

mute_time: Optional[int] = Field(None, alias='mutetimeRemaining')

禁言剩余时间

name class-attribute instance-attribute 🔗

name: str = Field(..., alias='memberName')

显示名称

permission instance-attribute 🔗

permission: MemberPerm

群权限

special_title class-attribute instance-attribute 🔗

special_title: Optional[str] = Field(None, alias='specialTitle')

特殊头衔

get_avatar async 🔗

get_avatar(size: Literal[640, 140] = 640) -> bytes

获取该群成员的头像

Parameters:

  • size (Literal[640, 140]) –

    头像尺寸

Returns:

  • bytes( bytes ) –

    群成员头像的二进制内容.

Source code in src/graia/ariadne/model/relationship.py
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
async def get_avatar(self, size: Literal[640, 140] = 640) -> bytes:
    """获取该群成员的头像

    Args:
        size (Literal[640, 140]): 头像尺寸

    Returns:
        bytes: 群成员头像的二进制内容.
    """
    from ..app import Ariadne

    async with Ariadne.service.client_session.get(
        f"https://q2.qlogo.cn/headimg_dl?dst_uin={self.id}&spec={size}"
    ) as resp:
        return await resp.read()

get_info async 🔗

get_info() -> MemberInfo

获取该成员的可修改状态

Returns:

  • MemberInfo( MemberInfo ) –

    群组成员的可修改状态

Source code in src/graia/ariadne/model/relationship.py
149
150
151
152
153
154
155
async def get_info(self) -> "MemberInfo":
    """获取该成员的可修改状态

    Returns:
        MemberInfo: 群组成员的可修改状态
    """
    return MemberInfo(name=self.name, specialTitle=self.special_title)

get_profile async 🔗

get_profile() -> Profile

获取该群成员的 Profile

Returns:

  • Profile( Profile ) –

    该群成员的 Profile 对象

Source code in src/graia/ariadne/model/relationship.py
139
140
141
142
143
144
145
146
147
async def get_profile(self) -> "Profile":
    """获取该群成员的 Profile

    Returns:
        Profile: 该群成员的 Profile 对象
    """
    from ..app import Ariadne

    return await Ariadne.current().get_member_profile(self)

modify_admin async 🔗

modify_admin(assign: bool) -> None

修改一位群组成员管理员权限; 需要有相应权限(群主)

Parameters:

  • assign (bool) –

    是否设置群成员为管理员.

Returns:

  • None( None ) –

    没有返回.

Source code in src/graia/ariadne/model/relationship.py
171
172
173
174
175
176
177
178
179
180
181
182
183
async def modify_admin(self, assign: bool) -> None:
    """
    修改一位群组成员管理员权限; 需要有相应权限(群主)

    Args:
        assign (bool): 是否设置群成员为管理员.

    Returns:
        None: 没有返回.
    """
    from ..app import Ariadne

    return await Ariadne.current().modify_member_admin(assign, self)

modify_info async 🔗

modify_info(info: MemberInfo) -> None

修改群组成员的可修改状态; 需要具有相应权限(管理员/群主).

Parameters:

  • info (MemberInfo) –

    已修改的指定群组成员的可修改状态

Returns:

  • None( None ) –

    没有返回.

Source code in src/graia/ariadne/model/relationship.py
157
158
159
160
161
162
163
164
165
166
167
168
169
async def modify_info(self, info: "MemberInfo") -> None:
    """
    修改群组成员的可修改状态; 需要具有相应权限(管理员/群主).

    Args:
        info (MemberInfo): 已修改的指定群组成员的可修改状态

    Returns:
        None: 没有返回.
    """
    from ..app import Ariadne

    return await Ariadne.current().modify_member_info(self, info)

MemberInfo 🔗

Bases: AriadneBaseModel

描述群组成员的可修改状态, 修改需要管理员/群主权限.

Source code in src/graia/ariadne/model/relationship.py
317
318
319
320
321
322
323
324
class MemberInfo(AriadneBaseModel):
    """描述群组成员的可修改状态, 修改需要管理员/群主权限."""

    name: str = ""
    """昵称, 与 nickname不同"""

    special_title: Optional[str] = Field(default="", alias="specialTitle")
    """特殊头衔"""

name class-attribute instance-attribute 🔗

name: str = ''

昵称, 与 nickname不同

special_title class-attribute instance-attribute 🔗

special_title: Optional[str] = Field(default='', alias='specialTitle')

特殊头衔

MemberPerm 🔗

Bases: Enum

描述群成员在群组中所具备的权限

Source code in src/graia/ariadne/model/relationship.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@functools.total_ordering
class MemberPerm(Enum):
    """描述群成员在群组中所具备的权限"""

    Member = "MEMBER"  # 普通成员
    Administrator = "ADMINISTRATOR"  # 管理员
    Owner = "OWNER"  # 群主

    def __str__(self) -> str:
        return self.value

    def __lt__(self, other: "MemberPerm"):
        return _MEMBER_PERM_LV_MAP[self.value] < _MEMBER_PERM_LV_MAP[other.value]

    def __repr__(self) -> str:
        return _MEMBER_PERM_REPR_MAP[self.value]

Profile 🔗

Bases: AriadneBaseModel

指示某个用户的个人资料

Source code in src/graia/ariadne/model/__init__.py
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
@internal_cls()
class Profile(AriadneBaseModel):
    """指示某个用户的个人资料"""

    nickname: str
    """昵称"""

    email: Optional[str]
    """电子邮件地址"""

    age: Optional[int]
    """年龄"""

    level: int
    """QQ 等级"""

    sign: str
    """个性签名"""

    sex: Literal["UNKNOWN", "MALE", "FEMALE"]
    """性别"""

age instance-attribute 🔗

age: Optional[int]

年龄

email instance-attribute 🔗

email: Optional[str]

电子邮件地址

level instance-attribute 🔗

level: int

QQ 等级

nickname instance-attribute 🔗

nickname: str

昵称

sex instance-attribute 🔗

sex: Literal['UNKNOWN', 'MALE', 'FEMALE']

性别

sign instance-attribute 🔗

sign: str

个性签名

Stranger 🔗

Bases: AriadneBaseModel

描述 Tencent QQ 中的陌生人.

Source code in src/graia/ariadne/model/relationship.py
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
class Stranger(AriadneBaseModel):
    """描述 Tencent QQ 中的陌生人."""

    id: int
    """QQ 号"""

    nickname: str
    """昵称"""

    remark: str
    """自行设置的代称"""

    __kind: Optional[Literal["Stranger"]] = Field(None, alias="kind")

    def __int__(self):
        return self.id

    def __str__(self) -> str:
        return f"Stranger({self.id}, {self.nickname})"

    def __eq__(self, other: Any) -> bool:
        return isinstance(other, (Friend, Member, Stranger)) and self.id == other.id

    async def get_avatar(self, size: Literal[640, 140] = 640) -> bytes:
        """获取该陌生人的头像

        Args:
            size (Literal[640, 140]): 头像尺寸

        Returns:
            bytes: 陌生人头像的二进制内容.
        """
        from ..app import Ariadne

        async with Ariadne.service.client_session.get(
            f"https://q2.qlogo.cn/headimg_dl?dst_uin={self.id}&spec={size}"
        ) as resp:
            return await resp.read()

id instance-attribute 🔗

id: int

QQ 号

nickname instance-attribute 🔗

nickname: str

昵称

remark instance-attribute 🔗

remark: str

自行设置的代称

get_avatar async 🔗

get_avatar(size: Literal[640, 140] = 640) -> bytes

获取该陌生人的头像

Parameters:

  • size (Literal[640, 140]) –

    头像尺寸

Returns:

  • bytes( bytes ) –

    陌生人头像的二进制内容.

Source code in src/graia/ariadne/model/relationship.py
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
async def get_avatar(self, size: Literal[640, 140] = 640) -> bytes:
    """获取该陌生人的头像

    Args:
        size (Literal[640, 140]): 头像尺寸

    Returns:
        bytes: 陌生人头像的二进制内容.
    """
    from ..app import Ariadne

    async with Ariadne.service.client_session.get(
        f"https://q2.qlogo.cn/headimg_dl?dst_uin={self.id}&spec={size}"
    ) as resp:
        return await resp.read()