Skip to content

Commit

Permalink
Update checking logic for GeetestTriggered (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
seriaati authored Jun 9, 2023
1 parent 87b509e commit b5c9332
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ exclude = tests, test.py
# S303: Use of md5
# S311: Use of pseudo-random generators
# S324: Use of md5 without usedforsecurity=False (3.9+)
# W503: line break before binary operator
ignore =
A001, A002, A003,
C408,
D105, D106, D419
S101, S303, S311, S324,
W503,

# F401: unused import.
# F403: cannot detect unused vars if we use starred import
Expand Down
4 changes: 2 additions & 2 deletions genshin/client/manager/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ async def _request(
cookies.update(new_cookies)
_LOGGER.debug("Updating cookies for %s: %s", get_cookie_identifier(cookies), new_keys)

if data["data"] and "gt_result" in data["data"]:
raise errors.GeetestTriggered(data)
errors.check_for_geetest(data)

if data["retcode"] == 0:
return data["data"]

Expand Down
18 changes: 18 additions & 0 deletions genshin/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"RedemptionException",
"RedemptionInvalid",
"TooManyRequests",
"check_for_geetest",
"raise_for_retcode",
]

Expand Down Expand Up @@ -250,3 +251,20 @@ def raise_for_retcode(data: typing.Dict[str, typing.Any]) -> typing.NoReturn:
raise RedemptionException(data)

raise GenshinException(data)


def check_for_geetest(data: typing.Dict[str, typing.Any]) -> None:
"""Check if geetest was triggered and raise an error."""
if not data.get("data") or data["data"].get("gt_result"):
return

gt_result = data["data"]["gt_result"]

if (
gt_result.get("risk_code") != 0
and gt_result.get("gt")
and gt_result.get("challenge")
and gt_result.get("success") != 0
and gt_result.get("is_risk")
):
raise GeetestTriggered(data)
2 changes: 1 addition & 1 deletion genshin/models/starrail/chronicle/characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from .. import character

__all__ = [
"StarRailEquipment",
"Rank",
"Relic",
"StarRailDetailCharacter",
"StarRailDetailCharacters",
"StarRailEquipment",
]


Expand Down
2 changes: 1 addition & 1 deletion genshin/models/starrail/chronicle/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

__all__ = [
"PartialStarRailUserStats",
"StarRailStats",
"StarRailUserInfo",
"StarRailUserStats",
"StarRailStats",
]


Expand Down

0 comments on commit b5c9332

Please sign in to comment.