Skip to content

Commit f835782

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 15b39bf + 7986d0d commit f835782

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

coc/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,9 @@ async def get_current_war(
734734
round_tags = league_group.rounds[-1]
735735

736736
async for war in self.get_league_wars(round_tags, cache=cache, fetch=fetch, update_cache=update_cache):
737-
if war.clan_tag == clan_tag:
737+
if war.clan and war.clan.tag == clan_tag:
738+
return war
739+
if war.opponent and war.opponent.tag == clan_tag:
738740
return war
739741

740742
def get_current_wars(

coc/players.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
Role,
4242
HERO_ORDER,
4343
BUILDER_TROOPS_ORDER,
44+
ELIXIR_TROOP_ORDER,
4445
HOME_TROOP_ORDER,
4546
SUPER_TROOP_ORDER,
4647
SPELL_ORDER,
@@ -200,7 +201,7 @@ def __init__(self, data, war, clan):
200201

201202
self.town_hall = data.get("townhallLevel")
202203
self.map_position = data.get("mapPosition")
203-
self._best_opponent_attack = data.get("bestOpponentAttack")
204+
self._best_opponent_attack = data.get("bestOpponentAttack", {}).get("attackerTag")
204205

205206
def _get_attacks(self):
206207
# pylint: disable=import-outside-toplevel
@@ -445,7 +446,12 @@ def get_ordered_troops(self, valid_troops):
445446
--------
446447
:class:`collections.OrderedDict` - An ordered dict of troops by name.
447448
"""
448-
troops_dict = {t.name: t for t in self.troops if t.name in set(valid_troops)}
449+
if valid_troops == ELIXIR_TROOP_ORDER:
450+
troops_dict = {t.name: t for t in self.troops if t.is_home_base and t.name in set(valid_troops)}
451+
elif valid_troops == BUILDER_TROOPS_ORDER:
452+
troops_dict = {t.name: t for t in self.troops if t.is_builder_base and t.name in set(valid_troops)}
453+
else:
454+
troops_dict = {t.name: t for t in self.troops if t.name in set(valid_troops)}
449455
key_order = {k: v for v, k in enumerate(valid_troops)}
450456
return OrderedDict(sorted(troops_dict.items(), key=lambda i: key_order.get(i[0], 0)))
451457

0 commit comments

Comments
 (0)