From 7b867d14d6b209358cc44d1aa7854a2e4db91834 Mon Sep 17 00:00:00 2001 From: 201st-Luka Date: Sat, 26 Aug 2023 21:22:39 +0200 Subject: [PATCH] feat: player sorting in `ClanCurrentWarRequest` implemented automatic player sorting (by map position) for the clan and opponent members of the `ClanCurrentWarRequest` --- README.md | 2 -- pyclasher/api/requests/clan_current_war.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7144a4c..1492a70 100644 --- a/README.md +++ b/README.md @@ -70,8 +70,6 @@ I'm planning to keep the API wrapper up to date and improve it as good as I can. - attributes `king`, `queen`, `warden`, `royal_champion` for the `Player.heroes` attribute -- autosort for the `ClanCurrentWarRequest` members of the `member_list` -attribute (sorted by the map position) - events and an `EventClient` --- diff --git a/pyclasher/api/requests/clan_current_war.py b/pyclasher/api/requests/clan_current_war.py index ae73b7e..dcfa3b4 100644 --- a/pyclasher/api/requests/clan_current_war.py +++ b/pyclasher/api/requests/clan_current_war.py @@ -35,3 +35,14 @@ async def from_base_clan(cls, base_clan): self = await cls(base_clan.tag).request() return self + async def request(self, client_id=None): + await super().request(client_id) + + self._data['clan']['members'] = sorted( + self._data['clan']['members'], + key=lambda member: member['mapPosition'] + ) + self._data['opponent']['members'] = sorted( + self._data['opponent']['members'], + key=lambda member: member['mapPosition'] + )