Skip to content

Commit 1b972b4

Browse files
committed
Merge remote-tracking branch 'origin/3.6.1' into 3.6.1
2 parents 41cfcd9 + 38a2fb9 commit 1b972b4

File tree

7 files changed

+53
-29
lines changed

7 files changed

+53
-29
lines changed

coc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
SOFTWARE.
2323
"""
2424

25-
__version__ = "3.6.1"
25+
__version__ = "3.7.0"
2626

2727
from .abc import BasePlayer, BaseClan
2828
from .clans import RankedClan, Clan

coc/enums.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"""
2424
from enum import Enum
2525

26+
2627
class ExtendedEnum(Enum):
2728
"""An Enum class that allows for the `__str__` method to be implemented."""
2829
def __str__(self):
@@ -61,10 +62,8 @@ class PlayerHouseElementType(ExtendedEnum):
6162
@property
6263
def in_game_name(self) -> str:
6364
"""Get a neat client-facing string value for the element type."""
64-
lookup = {PlayerHouseElementType.ground: "Ground", PlayerHouseElementType.roof: "Roof",
65-
PlayerHouseElementType.foot: "Foot", PlayerHouseElementType.deco: "Decoration",
66-
PlayerHouseElementType.walls: "Walls"}
67-
return lookup[self]
65+
lookup = {"ground": "Ground", "roof": "Roof", "foot": "Foot", "decoration": "Decoration", "walls": "Walls"}
66+
return lookup[self.value]
6867

6968

7069
class Role(ExtendedEnum):
@@ -78,8 +77,8 @@ class Role(ExtendedEnum):
7877
@property
7978
def in_game_name(self) -> str:
8079
"""Get a neat client-facing string value for the role."""
81-
lookup = {Role.member: "Member", Role.elder: "Elder", Role.co_leader: "Co-Leader", Role.leader: "Leader"}
82-
return lookup[self]
80+
lookup = {"member": "Member", "admin": "Elder", "coLeader": "Co-Leader", "leader": "Leader"}
81+
return lookup[self.value]
8382

8483

8584
class WarRound(ExtendedEnum):
@@ -90,16 +89,23 @@ class WarRound(ExtendedEnum):
9089
def __str__(self):
9190
return self.name
9291

92+
@property
93+
def in_game_name(self) -> str:
94+
lookup = ["Previous War", "Current War", "Current Preparation"]
95+
return lookup[self.value]
96+
97+
9398
class BattleModifier(ExtendedEnum):
9499
"""Enum to map the type of battle modifiers."""
95-
none = "None"
100+
none = "none"
96101
hard_mode = "hardMode"
97102

98103
@property
99104
def in_game_name(self) -> str:
100105
"""Get a neat client-facing string value for the battle modifier."""
101-
lookup = {BattleModifier.none: "None", BattleModifier.hard_mode: "Hard Mode"}
102-
return lookup[self]
106+
lookup = {"none": "None", "hardMode": "Hard Mode"}
107+
return lookup[self.value]
108+
103109

104110
class WarState(ExtendedEnum):
105111
"""Enum to map the state of the war.
@@ -112,9 +118,21 @@ class WarState(ExtendedEnum):
112118
@property
113119
def in_game_name(self) -> str:
114120
"""Get a neat client-facing string value for the war state."""
115-
lookup = {WarState.not_in_war: "Not in War", WarState.preparation: "Preparation",
116-
WarState.in_war: "In War", WarState.war_ended: "War Ended"}
117-
return lookup[self]
121+
lookup = {"notInWar": "Not in War", "preparation": "Preparation", "inWar": "In War", "warEnded": "War Ended"}
122+
return lookup[self.value]
123+
124+
125+
class WarResult(ExtendedEnum):
126+
"""Enum to map the result of the war"""
127+
win = "win"
128+
lose = "lose"
129+
tie = "tie"
130+
131+
@property
132+
def in_game_name(self) -> str:
133+
"""Get a neat client-facing string value for the war state."""
134+
lookup = {"win": "Win", "lose": "Lose", "tie": "Tie"}
135+
return lookup[self.value]
118136

119137

120138
class Resource(ExtendedEnum):
@@ -130,10 +148,10 @@ class Resource(ExtendedEnum):
130148
@property
131149
def in_game_name(self) -> str:
132150
"""Get a neat client-facing string value for the resource."""
133-
lookup = {Resource.elixir: "Elixir", Resource.builder_elixir: "Builder Elixir",
134-
Resource.dark_elixir: "Dark Elixir", Resource.gold: "Gold", Resource.builder_gold: "Builder Gold",
135-
Resource.shiny_ore: "Shiny Ore", Resource.glowy_ore: "Glowy Ore", Resource.starry_ore: "Starry Ore"}
136-
return lookup[self]
151+
lookup = {"Elixir": "Elixir", "Elixir2": "Builder Elixir",
152+
"DarkElixir": "Dark Elixir", "Gold": "Gold", "Gold2": "Builder Gold",
153+
"CommonOre": "Shiny Ore", "RareOre": "Glowy Ore", "EpicOre": "Starry Ore"}
154+
return lookup[self.value]
137155

138156

139157
ELIXIR_TROOP_ORDER = [

coc/miscmodels.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@
2525
from typing import Any, Type, TypeVar, Optional
2626

2727
import coc
28-
from .enums import PlayerHouseElementType
28+
from .enums import ExtendedEnum, PlayerHouseElementType
2929
from .utils import from_timestamp
3030

3131
T = TypeVar("T")
3232

3333

3434
def try_enum(_class: Type[T], data: Any, **kwargs) -> Optional[T]:
3535
"""Helper function to create a class from the given data."""
36+
if issubclass(_class, ExtendedEnum):
37+
return data and _class(data)
3638
return data and _class(data=data, **kwargs)
3739

3840

coc/wars.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from typing import AsyncIterator, List, Optional, Type, TYPE_CHECKING, Union
3030

31-
from .enums import BattleModifier, WarRound, WarState
31+
from .enums import BattleModifier, WarResult, WarRound, WarState
3232
from .iterators import LeagueWarIterator
3333
from .miscmodels import try_enum, Timestamp
3434
from .utils import cached_property, get
@@ -112,7 +112,7 @@ def _from_data(self, data: dict) -> None:
112112
self.start_time = try_enum(Timestamp, data=data_get("startTime"))
113113
self.end_time = try_enum(Timestamp, data=data_get("endTime"))
114114
self.war_tag: str = data_get("tag")
115-
self.battle_modifier: BattleModifier = try_enum(BattleModifier, data=str(data_get('battleModifier')))
115+
self.battle_modifier: BattleModifier = try_enum(BattleModifier, data=data_get('battleModifier', 'none'))
116116
if data_get("attacksPerMember") is None or self.is_cwl:
117117
self.attacks_per_member: int = 1
118118
else:
@@ -323,7 +323,7 @@ class ClanWarLogEntry:
323323
Attributes
324324
----------
325325
result:
326-
:class:`str`: The result of the war - ``win`` or ``loss``
326+
:class:`WarResult`: The result of the war - ``win``, ``lose`` or ``tie``
327327
end_time:
328328
:class:`Timestamp`: The :class:`Timestamp` that the war ended at.
329329
team_size:
@@ -334,11 +334,13 @@ class ClanWarLogEntry:
334334
:class:`WarClan`: The opposition clan.
335335
attacks_per_member:
336336
:class:`int`: The number of attacks each member had this war.
337+
battle_modifier:
338+
:class:`BattleModifier`: The battle modifier for this war.
337339
"""
338340

339341
__slots__ = (
340342
"result", "end_time", "team_size", "clan", "opponent", "_client",
341-
"attacks_per_member", "_raw_data", "_response_retry")
343+
"attacks_per_member", "battle_modifier", "_raw_data", "_response_retry")
342344

343345
def __init__(self, *, data, client, **kwargs):
344346
self._client = client
@@ -360,12 +362,13 @@ def __eq__(self, other) -> bool:
360362
def _from_data(self, data: dict) -> None:
361363
data_get = data.get
362364

363-
self.result: str = data_get("result")
365+
self.result: WarResult = try_enum(WarResult, data=data_get("result"))
364366
self.end_time = try_enum(Timestamp, data=data_get("endTime"))
365367
self.team_size: int = data_get("teamSize")
366368

367369
self.clan = self._fake_load_clan(data_get("clan"))
368370
self.opponent = self._fake_load_clan(data_get("opponent"))
371+
self.battle_modifier: BattleModifier = try_enum(BattleModifier, data=data_get('battleModifier', 'none'))
369372

370373
if data_get("attacksPerMember") is None and self.is_league_entry:
371374
self.attacks_per_member: int = 1

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
project = 'coc'
1616
copyright = '2022, mathsman5133'
1717
author = 'mathsman5133'
18-
release = '3.6.1'
18+
release = '3.7.0'
1919

2020
# -- General configuration ---------------------------------------------------
2121
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

docs/miscellaneous/changelog.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ Changelog
77
This page keeps a fairly detailed, human readable version
88
of what has changed, and whats new for each version of the lib.
99

10-
v3.6.1
10+
v3.7.0
1111
------
1212

1313
Additions:
1414
~~~~~~~~~~
1515
- Added inheritance of classes into the docs to make it easier to see what classes inherit from others.
16-
- Added the new `BattleModifier` to the `ClanWar` class.
16+
- Added the new :class:`BattleModifier` to :attr:`ClanWar.battle_modifier` and :class:`ClanWarLogEntry.battle_modifier`.
1717
- Added the new troop and equipment in June 2024 update to the static data.
1818

1919
Changes:
2020
~~~~~~~~
21-
- Changed the way the `ClanWar` class handles the `state` attribute. It now returns a `WarState` enumeration object
22-
instead of a string to allow better type hinting and easier comparison.
21+
- Changed the way the :class:`ClanWar` and :class:`ClanWarLogEntry` classes handles the :attr:`state` and :attr:`result`
22+
attribute, respectively. It now returns a :class:`WarState`/:class:`WarResult` enumeration object instead of a string
23+
to allow better type hinting and easier comparison.
2324
- Updated the static data to reflect the June 2024 update changes.
2425

2526
v3.6.0

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "coc.py"
77
authors = [{ name = "mathsman5133" }]
88
maintainers = [{ name = "majordoobie" }, { name = "MagicTheDev" }, { name = "Kuchenmampfer" },
99
{ name = "lukasthaler"}, { name = "doluk"}]
10-
version = "3.6.1"
10+
version = "3.7.0"
1111
description = "A python wrapper for the Clash of Clans API"
1212
requires-python = ">=3.7.3"
1313
readme = "README.rst"

0 commit comments

Comments
 (0)