| 
2 | 2 | from typing import List, Union  | 
3 | 3 | 
 
  | 
4 | 4 | from . import api  | 
 | 5 | +from ._types import MessageTypes, FriendTypes  | 
5 | 6 | from .gateway import Requestable, Gateway  | 
6 | 7 | from .interface import LazyLoadable  | 
7 | 8 | from .intimacy import Intimacy  | 
8 | 9 | from .role import Role  | 
9 |  | -from ._types import MessageTypes  | 
10 | 10 | 
 
  | 
11 | 11 | 
 
  | 
12 | 12 | class User(LazyLoadable, Requestable):  | 
@@ -85,6 +85,14 @@ async def update_intimacy(self, score: int = 0, social_info: str = None, img_id:  | 
85 | 85 |             params['img_id'] = img_id  | 
86 | 86 |         return await self.gate.exec_req(api.Intimacy.update(**params))  | 
87 | 87 | 
 
  | 
 | 88 | +    async def add_friend(self):  | 
 | 89 | +        """send friend request to the user"""  | 
 | 90 | +        await self.gate.exec_req(api.Friend.request(user_code=f'{self.username}#{self.identify_num}', _from=0))  | 
 | 91 | + | 
 | 92 | +    async def block(self):  | 
 | 93 | +        """block the user"""  | 
 | 94 | +        await self.gate.exec_req(api.Friend.block(user_id=self.id))  | 
 | 95 | + | 
88 | 96 | 
 
  | 
89 | 97 | class GuildUser(User):  | 
90 | 98 |     """a user in guild  | 
@@ -127,3 +135,69 @@ async def set_nickname(self, nickname: str):  | 
127 | 135 |         Set user's nickname  | 
128 | 136 |         """  | 
129 | 137 |         await self.gate.exec_req(api.Guild.nickname(guild_id=self.guild_id, nickname=nickname, user_id=self.id))  | 
 | 138 | + | 
 | 139 | +    async def add_friend(self):  | 
 | 140 | +        await self.gate.exec_req(  | 
 | 141 | +            api.Friend.request(user_code=f'{self.username}#{self.identify_num}', _from=2, guild_id=self.guild_id))  | 
 | 142 | + | 
 | 143 | + | 
 | 144 | +class Friend:  | 
 | 145 | +    """  | 
 | 146 | +    Friend with specific friend id and friend info  | 
 | 147 | +    """  | 
 | 148 | + | 
 | 149 | +    gate: Gateway  | 
 | 150 | + | 
 | 151 | +    id: int  | 
 | 152 | +    user_id: str  | 
 | 153 | + | 
 | 154 | +    _user: User  | 
 | 155 | +    _type: FriendTypes  | 
 | 156 | + | 
 | 157 | +    def __init__(self, _gate_: Gateway, **kwargs):  | 
 | 158 | +        self.gate = _gate_  | 
 | 159 | +        self.id = kwargs.get('id')  | 
 | 160 | +        self.user_id = kwargs.get('user_id')  | 
 | 161 | +        self._type = kwargs.get('type')  | 
 | 162 | + | 
 | 163 | +    async def fetch_user(self) -> User:  | 
 | 164 | +        """get user"""  | 
 | 165 | +        if self._user is None:  | 
 | 166 | +            self._user = User(_gate_=self.gate, **(await self.gate.exec_req(api.User.view(user_id=self.user_id))))  | 
 | 167 | +        return self._user  | 
 | 168 | + | 
 | 169 | +    async def delete(self):  | 
 | 170 | +        """delete the friend"""  | 
 | 171 | +        await self.gate.exec_req(api.Friend.delete(user_id=self.user_id))  | 
 | 172 | + | 
 | 173 | +    async def block(self):  | 
 | 174 | +        """block the user"""  | 
 | 175 | +        await self.gate.exec_req(api.Friend.block(user_id=self.user_id))  | 
 | 176 | + | 
 | 177 | +    async def unblock(self):  | 
 | 178 | +        """unblock the blocked user"""  | 
 | 179 | +        await self.gate.exec_req(api.Friend.unblock(user_id=self.user_id))  | 
 | 180 | + | 
 | 181 | +    @property  | 
 | 182 | +    def type(self) -> FriendTypes:  | 
 | 183 | +        """the type of the friend"""  | 
 | 184 | +        return self._type  | 
 | 185 | + | 
 | 186 | + | 
 | 187 | +class FriendRequest(Friend):  | 
 | 188 | +    """  | 
 | 189 | +    Friend request with specific id and user info  | 
 | 190 | +    """  | 
 | 191 | + | 
 | 192 | +    async def accept(self):  | 
 | 193 | +        """accept the friend request"""  | 
 | 194 | +        await self.gate.exec_req(api.Friend.handleRequest(id=self.id, accept=1))  | 
 | 195 | +        return Friend(_gate_=self.gate, user_id=self.user_id)  | 
 | 196 | + | 
 | 197 | +    async def deny(self):  | 
 | 198 | +        """deny the friend request"""  | 
 | 199 | +        await self.gate.exec_req(api.Friend.handleRequest(id=self.id, accept=0))  | 
 | 200 | + | 
 | 201 | +    @property  | 
 | 202 | +    def type(self) -> FriendTypes:  | 
 | 203 | +        return FriendTypes.REQUEST  | 
0 commit comments