Skip to content

Commit efced00

Browse files
authored
Merge pull request #152 from mathsman5133/g5_2.2.2_candidate
G5 2.2.2 candidate
2 parents 1395266 + fe92f3b commit efced00

File tree

11 files changed

+105
-8
lines changed

11 files changed

+105
-8
lines changed

coc/clans.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class Clan(BaseClan):
107107
The clan's versus trophy count. This is calculated according to members' versus trophy counts.
108108
required_trophies: :class:`int`
109109
The minimum trophies required to apply to this clan.
110+
required_townhall: :class:`int`
111+
The minimum townhall level required to apply to this clan.
110112
war_frequency: :class:`str`
111113
The frequency for when this clan goes to war.
112114
For example, this could be ``always``.
@@ -159,6 +161,7 @@ class Clan(BaseClan):
159161
"capital_district_cls",
160162
"war_league",
161163
"chat_language",
164+
"required_townhall",
162165

163166
"_cs_labels",
164167
"_cs_members",
@@ -197,6 +200,7 @@ def _from_data(self, data: dict) -> None:
197200
self.description: str = data_get("description")
198201
self.war_league = try_enum(WarLeague, data=data_get("warLeague"))
199202
self.chat_language = try_enum(ChatLanguage, data=data_get("chatLanguage"))
203+
self.required_townhall = data_get("requiredTownhallLevel")
200204

201205
label_cls = self.label_cls
202206
self._iter_labels = (label_cls(data=ldata, client=self._client) for ldata in data_get("labels", []))

coc/client.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"""
2424
import asyncio
2525
import logging
26+
from enum import Enum
2627

2728
from itertools import cycle
2829
from pathlib import Path
@@ -67,6 +68,16 @@
6768
BUILDING_FILE_PATH = Path(__file__).parent.joinpath(Path("static/buildings.json"))
6869

6970

71+
class ClashAccountScopes(Enum):
72+
"""
73+
Values represent the scope required for each type of user. A USER is
74+
anyone who has access to the API. A REAL user is a user with special
75+
access from SuperCell with realtime scope access.
76+
"""
77+
USER = "clash"
78+
REAL = "clash:*:verifytoken,realtime"
79+
80+
7081
class Client:
7182
"""This is the client connection used to interact with the Clash of Clans API.
7283
@@ -120,6 +131,11 @@ class Client:
120131
load_game_data: :class:`LoadGameData`
121132
The option for how coc.py will load game data. See :ref:`initialising_game_data` for more info.
122133
134+
realtime: :class:`bool`
135+
Some developers are given special access to an uncached API access by
136+
Super Cell. If you are one of those developers, your account will have
137+
special flags that will only be interpreted by coc.py if you set this
138+
bool to True.
123139
124140
Attributes
125141
----------
@@ -158,7 +174,6 @@ def __init__(
158174
*,
159175
key_count: int = 1,
160176
key_names: str = "Created with coc.py Client",
161-
key_scopes: str = "clash",
162177
throttle_limit: int = 10,
163178
loop: asyncio.AbstractEventLoop = None,
164179
correct_tags: bool = True,
@@ -168,7 +183,7 @@ def __init__(
168183
cache_max_size: int = 10000,
169184
stats_max_size: int = 1000,
170185
load_game_data: LoadGameData = LoadGameData(default=True),
171-
realtime = False,
186+
realtime=False,
172187
**_,
173188
):
174189

@@ -180,7 +195,7 @@ def __init__(
180195
raise RuntimeError("Key count must be within {}-{}".format(KEY_MINIMUM, KEY_MAXIMUM))
181196

182197
self.key_names = key_names
183-
self.key_scopes = key_scopes
198+
self.key_scopes = ClashAccountScopes.REAL.value if realtime else ClashAccountScopes.USER.value
184199
self.throttle_limit = throttle_limit
185200
self.throttler = throttler
186201
self.connector = connector
@@ -190,6 +205,7 @@ def __init__(
190205

191206
self.http = None # set in method login()
192207
self.realtime = realtime
208+
193209
self.correct_tags = correct_tags
194210
self.load_game_data = load_game_data
195211

@@ -253,6 +269,8 @@ def _create_holders(self):
253269
async def login(self, email: str, password: str) -> None:
254270
"""Retrieves all keys and creates an HTTP connection ready for use.
255271
272+
@Deprecated
273+
256274
Parameters
257275
----------
258276
email : str

coc/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class Resource(Enum):
111111
"Super Witch",
112112
"Ice Hound",
113113
"Super Bowler",
114+
"Super Miner",
114115
]
115116

116117
HOME_TROOP_ORDER = HOME_TROOP_ORDER + SIEGE_MACHINE_ORDER

coc/http.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,11 @@ async def initialise_keys(self):
480480

481481
resp = await session.post("https://developer.clashofclans.com/api/apikey/create", json=data)
482482
key = await resp.json()
483+
484+
if resp.status != 200:
485+
LOG.error(key.get("description"))
486+
raise ValueError(key.get("description"))
487+
483488
self._keys.append(key["key"]["key"])
484489

485490
if len(keys) == 10 and len(self._keys) < self.key_count:

coc/static/pets.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

coc/static/texts_EN.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

coc/static/update_static.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
("pets.json", None),
1717
("spells.json", None),
1818
("supers.json", None),
19+
("townhall_levels.json", None),
1920
("lang/texts_EN.json", "texts_EN.json"),
2021
]
2122

coc/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,13 @@ def get_season_end(month: Optional[int] = None, year: Optional[int] = None) -> d
344344
The end of the season.
345345
"""
346346
if month and year:
347-
return get_season_start(month + 1, year)
347+
if month == 12:
348+
next_month = 1
349+
next_year = year + 1
350+
else:
351+
next_month = month + 1
352+
next_year = year
353+
return get_season_start(next_month, next_year)
348354

349355
now = datetime.utcnow()
350356
end = get_season_start(now.month, now.year)

coc/war_clans.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def _from_data(self, data: dict) -> None:
104104

105105
if self._war:
106106
self.max_stars: int = self._war.team_size * 3
107-
self.total_attacks: int = self._war.team_size * 2
107+
self.total_attacks: int = self._war.team_size * self._war.attacks_per_member
108108
else:
109109
self.max_stars: int = (data_get("teamSize") or 0) * 3
110110
self.total_attacks: int = (data_get("teamSize") or 0) * 3

coc/wars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def _from_data(self, data: dict) -> None:
103103
self.start_time = try_enum(Timestamp, data=data_get("startTime"))
104104
self.end_time = try_enum(Timestamp, data=data_get("endTime"))
105105
self.war_tag: str = data_get("tag")
106-
if data_get("attacksPerMember") is None and self.is_cwl:
106+
if data_get("attacksPerMember") is None or self.is_cwl:
107107
self.attacks_per_member: int = 1
108108
else:
109109
self.attacks_per_member: int = data_get("attacksPerMember")

0 commit comments

Comments
 (0)