Skip to content

Commit f259276

Browse files
committed
Fix issues
1 parent 68301f5 commit f259276

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

codingame/client/async_.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,31 @@ async def create_private_clash_of_code(
153153
)
154154
except HTTPError as error:
155155
if error.data["id"] in (500, 501):
156-
raise LoginRequired() from None
156+
raise LoginRequired(error.data.get("message", "")) from None
157157
raise # pragma: no cover
158158

159159
return await self.get_clash_of_code(data["publicHandle"])
160160

161-
async def join_private_clash_of_code(self, handle: str) -> ClashOfCode:
161+
async def join_private_clash_of_code(
162+
self, clash_of_code: typing.Union[ClashOfCode, str]
163+
) -> ClashOfCode:
164+
if not self.logged_in:
165+
raise LoginRequired()
166+
167+
handle = (
168+
clash_of_code
169+
if isinstance(clash_of_code, str)
170+
else clash_of_code.public_handle
171+
)
172+
162173
if not CLASH_OF_CODE_HANDLE_REGEX.match(handle):
163174
raise ValueError(
164175
f"Clash of Code handle {handle!r} isn't in the good format "
165176
"(regex: [0-9]{7}[0-9a-f]{32})."
166177
)
167178

168179
try:
169-
data = await self._state.http.join_clash_of_code_by_handle(
180+
await self._state.http.join_clash_of_code_by_handle(
170181
self.codingamer.id, handle
171182
)
172183
except HTTPError as error:
@@ -181,7 +192,7 @@ async def join_private_clash_of_code(self, handle: str) -> ClashOfCode:
181192
)
182193

183194
raise # pragma: no cover
184-
return ClashOfCode(self._state, data)
195+
return await self.get_clash_of_code(handle)
185196

186197
# --------------------------------------------------------------------------
187198
# Language IDs

codingame/client/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,8 @@ def join_private_clash_of_code(self, handle: str) -> "ClashOfCode":
340340
341341
Parameters
342342
-----------
343-
handle: :class:`str`
344-
The Clash of Code's public handle. 39 character long hexadecimal
345-
string (regex: ``[0-9]{7}[0-9a-f]{32}``).
343+
handle: :class:`~codingame.ClashOfCode` or :class:`str`
344+
The Clash of Code to join or its public handle.
346345
347346
Raises
348347
------

codingame/client/sync.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,31 @@ def create_private_clash_of_code(
148148
)
149149
except HTTPError as error:
150150
if error.data["id"] in (500, 501):
151-
raise LoginRequired() from None
151+
raise LoginRequired(error.data.get("message", "")) from None
152152
raise # pragma: no cover
153153

154154
return self.get_clash_of_code(data["publicHandle"])
155155

156-
def join_private_clash_of_code(self, handle: str) -> ClashOfCode:
156+
def join_private_clash_of_code(
157+
self, clash_of_code: typing.Union[ClashOfCode, str]
158+
) -> ClashOfCode:
159+
if not self.logged_in:
160+
raise LoginRequired()
161+
162+
handle = (
163+
clash_of_code
164+
if isinstance(clash_of_code, str)
165+
else clash_of_code.public_handle
166+
)
167+
157168
if not CLASH_OF_CODE_HANDLE_REGEX.match(handle):
158169
raise ValueError(
159170
f"Clash of Code handle {handle!r} isn't in the good format "
160171
"(regex: [0-9]{7}[0-9a-f]{32})."
161172
)
162173

163174
try:
164-
data = self._state.http.join_clash_of_code_by_handle(
175+
self._state.http.join_clash_of_code_by_handle(
165176
self.codingamer.id, handle
166177
)
167178
except HTTPError as error:
@@ -176,7 +187,7 @@ def join_private_clash_of_code(self, handle: str) -> ClashOfCode:
176187
)
177188

178189
raise # pragma: no cover
179-
return ClashOfCode(self._state, data)
190+
return self.get_clash_of_code(handle)
180191

181192
# --------------------------------------------------------------------------
182193
# Language IDs

0 commit comments

Comments
 (0)