Skip to content

Commit 89ff889

Browse files
committed
feat: add list_bots_in_community
1 parent 501dfe7 commit 89ff889

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

swibots/api/community/methods/community_methods.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,24 @@ async def get_premium_members(
281281
channel_id=channel_id,
282282
group_id=group_id,
283283
)
284+
285+
async def list_bots_in_community(self: "swibots.ApiClient", community_id: str):
286+
"""List all bots in the community
287+
288+
Args:
289+
community_id (str): Community ID
290+
"""
291+
community_client = self.community_service.communities.client
292+
response = await community_client.get(f"/v1/community/bots?communityId={community_id}")
293+
result = response.data['result']
294+
members = result['communityMembers']
295+
for member in members:
296+
297+
def filterMemberId(x):
298+
return int(x['id']) == int(member['userId'])
299+
300+
userInfo = list(filter(filterMemberId, result['userInfoList']))
301+
if userInfo:
302+
member['userInfo'] = userInfo[0]
303+
304+
return community_client.build_list(CommunityMember, members)

swibots/api/community/models/community.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(
2929
groups_count: Optional[int] = None,
3030
channels_count: Optional[int] = None,
3131
default_channel: Optional[Channel] = None,
32-
visible: Optional[bool] = True
32+
visible: Optional[bool] = True,
3333
):
3434
super().__init__(app)
3535
self.id = id
@@ -76,7 +76,9 @@ def to_json(self) -> JSONDict:
7676
"numberOfGroups": self.groups_count,
7777
"numberOfChannels": self.channels_count,
7878
"visible": self.visible,
79-
"defaultChannel": self.default_channel.to_json() if self.default_channel else None
79+
"defaultChannel": (
80+
self.default_channel.to_json() if self.default_channel else None
81+
),
8082
}
8183

8284
def from_json(self, data: Optional[JSONDict]) -> Optional["Community"]:

0 commit comments

Comments
 (0)