Skip to content

Commit d2d2e0c

Browse files
committed
feat: add premium members methods
1 parent 0185915 commit d2d2e0c

File tree

2 files changed

+116
-4
lines changed

2 files changed

+116
-4
lines changed

swibots/api/community/controllers/community_controller.py

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ async def get_community(self, community_id: str = "", username: str = ""):
3333
return self.client.build_object(Community, response.data.get("result"))
3434

3535
async def update_community(self, community: Community):
36-
response = await self.client.put(
37-
BASE_PATH, data=community.to_json_request()
38-
)
36+
response = await self.client.put(BASE_PATH, data=community.to_json_request())
3937
return self.client.build_object(Community, response.data.get("result"))
4038

4139
async def deduct_xp(
@@ -152,3 +150,54 @@ async def get_messaging_bots(
152150
return self.client.build_list(InstantMessaging, response.data.get("result"))
153151

154152
# endregion
153+
154+
async def add_premium_member(
155+
self,
156+
user_id: str,
157+
community_id: str,
158+
channel_id: str = None,
159+
group_id: str = None,
160+
):
161+
data = {"userId": user_id, "communityId": community_id}
162+
if channel_id:
163+
data["channelId"] = channel_id
164+
if group_id:
165+
data["groupId"] = group_id
166+
response = await self.client.post(
167+
f"{BASE_PATH}/premium/member?{urlencode(data)}"
168+
)
169+
return response.data.get("success")
170+
171+
async def delete_premium_member(
172+
self,
173+
user_id: str,
174+
community_id: str,
175+
channel_id: str = None,
176+
group_id: str = None,
177+
):
178+
data = {"userId": user_id, "communityId": community_id}
179+
if channel_id:
180+
data["channelId"] = channel_id
181+
if group_id:
182+
data["groupId"] = group_id
183+
response = await self.client.delete(
184+
f"{BASE_PATH}/premium/member?{urlencode(data)}"
185+
)
186+
return response.data.get("success")
187+
188+
async def get_premium_members(
189+
self,
190+
user_id: str,
191+
community_id: str,
192+
channel_id: str = None,
193+
group_id: str = None,
194+
):
195+
data = {"userId": user_id, "communityId": community_id}
196+
if channel_id:
197+
data["channelId"] = channel_id
198+
if group_id:
199+
data["groupId"] = group_id
200+
response = await self.client.get(
201+
f"{BASE_PATH}/premium/member?{urlencode(data)}"
202+
)
203+
return response.data

swibots/api/community/methods/community_methods.py

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,67 @@ async def update_community(self: "swibots.ApiClient", community: Community) -> C
198198
Returns:
199199
Community: new community response
200200
"""
201-
return await self.community_service.communities.update_community(community=community)
201+
return await self.community_service.communities.update_community(community=community)
202+
203+
async def add_premium_member(self: "swibots.ApiClient", user_id: int,
204+
community_id: str,
205+
channel_id: str = None,
206+
group_id: str = None):
207+
"""Add premium member to the community
208+
209+
Args:
210+
user_id (int): User id
211+
community_id (str): Community id
212+
channel_id (str, optional): Channel id
213+
group_id (str, optional): Group id
214+
215+
Returns:
216+
bool
217+
"""
218+
return await self.community_service.communities.add_premium_member(
219+
user_id=user_id,
220+
community_id=community_id,
221+
channel_id=channel_id,
222+
group_id=group_id
223+
)
224+
225+
async def delete_premium_member(self: "swibots.ApiClient", user_id: int,
226+
community_id: str,
227+
channel_id: str = None,
228+
group_id: str = None):
229+
"""Remove premium member to the community
230+
231+
Args:
232+
user_id (int): User id
233+
community_id (str): Community id
234+
channel_id (str, optional): Channel id
235+
group_id (str, optional): Group id
236+
237+
Returns:
238+
bool
239+
"""
240+
return await self.community_service.communities.delete_premium_member(
241+
user_id=user_id,
242+
community_id=community_id,
243+
channel_id=channel_id,
244+
group_id=group_id
245+
)
246+
247+
async def get_premium_members(self: "swibots.ApiClient", user_id: int,
248+
community_id: str,
249+
channel_id: str = None,
250+
group_id: str = None):
251+
"""Get all premium members in the community
252+
253+
Args:
254+
user_id (int): User id
255+
community_id (str): Community id
256+
channel_id (str, optional): Channel id
257+
group_id (str, optional): Group id
258+
"""
259+
return await self.community_service.communities.get_premium_members(
260+
user_id=user_id,
261+
community_id=community_id,
262+
channel_id=channel_id,
263+
group_id=group_id
264+
)

0 commit comments

Comments
 (0)