Skip to content

Commit 3515cdc

Browse files
committed
Inject ClanMember into async-for clan.get_detailed_members
1 parent 7599b8a commit 3515cdc

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

coc/iterators.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,17 @@ class PlayerIterator(TaggedIterator):
133133
def __init__(self, client, tags: Iterable, cls=None, **kwargs):
134134
# pylint: disable=too-many-arguments
135135
super().__init__(client, tags, cls, **kwargs)
136-
self.get_method = client.get_player
136+
self.get_method = self.get_player
137+
138+
self.members = kwargs.pop("members", {})
139+
140+
def get_player(self, tag, cls=None, **kwargs):
141+
if cls:
142+
player = await self.client.get_player(tag, cls=cls, **kwargs)
143+
else:
144+
player = await self.client.get_player(tag, **kwargs)
145+
146+
player._inject_clan_member(self.members.get(tag))
137147

138148

139149
class ClanWarIterator(TaggedIterator):

coc/players.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ def _from_data(self, data: dict) -> None:
275275
self.__iter_heroes = (hero_cls(data=hdata) for hdata in data_get("heroes", []))
276276
self.__iter_spells = (spell_cls(data=sdata) for sdata in data_get("spells", []))
277277

278+
def _inject_clan_member(self, member):
279+
if member:
280+
self.clan_rank = getattr(member, "clan_rank", None)
281+
self.clan_previous_rank = getattr(member, "clan_previous_rank", None)
282+
278283
@property
279284
def labels(self) -> typing.List[Label]:
280285
"""List[:class:`Label`]: A :class:`List` of :class:`Label` that the player has."""

0 commit comments

Comments
 (0)