This repository was archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfriend.py
126 lines (96 loc) · 4.08 KB
/
friend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
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
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
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
"""Application Friend APIs.
:Copyright: Copyright (C) 2021-2021 cscs181
:License: AGPL-3.0 or later. See `LICENSE`_ for detail.
.. _LICENSE:
https://github.com/cscs181/CAI/blob/master/LICENSE
"""
from typing import List, Optional, Tuple
from cai.client import FriendGroup
from cai.client import Friend as friend_t
from .base import BaseAPI
from .error import BotException
from ..client.pkg_builder import build_recall_private_msg_pkg
from ..pb.msf.msg.svc import PbMsgWithDrawResp
class Friend(BaseAPI):
async def get_friend(
self, friend_uin: int, cache: bool = True
) -> Optional[friend_t]:
"""Get account friend.
This function wraps the :meth:`~cai.session.session.Session.get_friend`
method of the session.
Args:
friend_uin (int): Friend account uin.
cache (bool, optional): Use cached friend list. Defaults to True.
Returns:
Friend: Friend object.
None: Friend not exists.
Raises:
RuntimeError: Error response type got. This should not happen.
ApiResponseError: Get friend list failed.
FriendListException: Get friend list returned non-zero ret code.
"""
return await self.session.get_friend(friend_uin, cache)
async def get_friend_list(self, cache: bool = True) -> List[friend_t]:
"""Get account friend list.
This function wraps the :meth:`~cai.session.session.Session.get_friend_list`
method of the session.
Args:
cache (bool, optional): Use cached friend list. Defaults to True.
Returns:
List of :obj:`~cai.session.models.Friend`
Raises:
RuntimeError: Error response type got. This should not happen.
ApiResponseError: Get friend list failed.
FriendListException: Get friend list returned non-zero ret code.
"""
return await self._executor("get_friend_list", cache)
async def get_friend_group(
self, group_id: int, cache: bool = True
) -> Optional[FriendGroup]:
"""Get Friend Group.
This function wraps the :meth:`~cai.session.session.Session.get_friend_group`
method of the session.
Args:
group_id (int): Friend group id.
cache (bool, optional): Use cached friend group list. Defaults to True.
Returns:
FriendGroup: Friend group object.
None: Friend group not exists.
Raises:
RuntimeError: Error response type got. This should not happen.
ApiResponseError: Get friend list failed.
FriendListException: Get friend list returned non-zero ret code.
"""
return await self._executor("get_friend_group", group_id, cache)
async def get_friend_group_list(
self, cache: bool = True
) -> List[FriendGroup]:
"""Get account friend group list.
This function wraps the :meth:`~cai.session.session.Session.get_friend_group_list`
method of the session.
Args:
cache (bool, optional): Use cached friend group list. Defaults to True.
Returns:
List[FriendGroup]: Friend group list.
Raises:
RuntimeError: Error response type got. This should not happen.
ApiResponseError: Get friend group list failed.
FriendListException: Get friend group list returned non-zero ret code.
"""
return await self._executor("get_friend_group_list", cache)
async def recall_friend_msg(self, uin: int, msg: Tuple[int, int, int]):
ret = PbMsgWithDrawResp.FromString(
(
await self.session.send_unipkg_and_wait(
"PbMessageSvc.PbMsgWithDraw",
build_recall_private_msg_pkg(
self.session.uin,
uin,
msg_list=[msg]
).SerializeToString()
)
).data
).c2c_with_draw[0]
if ret.result not in (2, 3):
raise BotException(ret.result, ret.errmsg)
__all__ = ["Friend"]