From c7b0f530f7d753ac3f1b0c09c3dfe168ac16ca9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Wed, 23 Nov 2022 09:11:29 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20black=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/apihelper/helpers.py | 45 +++++++++++++++++----------------- plugins/genshin/gacha/gacha.py | 2 +- plugins/genshin/sign.py | 2 +- plugins/system/webapp.py | 4 ++- utils/decorators/error.py | 4 ++- utils/helpers.py | 14 +++++------ 6 files changed, 38 insertions(+), 33 deletions(-) diff --git a/modules/apihelper/helpers.py b/modules/apihelper/helpers.py index 0d5a00cd..5bd0c0ff 100644 --- a/modules/apihelper/helpers.py +++ b/modules/apihelper/helpers.py @@ -29,6 +29,7 @@ def hex_digest(text): def get_ds(ds_type: str = None, new_ds: bool = False, data: Any = None, params: Optional[Mapping[str, Any]] = None): """DS 算法 + 代码来自 https://github.com/y1ndan/genshinhelper :param ds_type: 1:ios 2:android 4:pc web 5:mobile web :param new_ds: 是否为DS2算法 @@ -40,35 +41,35 @@ def get_ds(ds_type: str = None, new_ds: bool = False, data: Any = None, params: def new(): t = str(int(time.time())) r = str(random.randint(100001, 200000)) # nosec - b = json.dumps(data) if data else '' - q = "&".join(f"{k}={v}" for k, v in sorted(params.items())) if params else '' - c = hex_digest(f'salt={salt}&t={t}&r={r}&b={b}&q={q}') - return f'{t},{r},{c}' + b = json.dumps(data) if data else "" + q = "&".join(f"{k}={v}" for k, v in sorted(params.items())) if params else "" + c = hex_digest(f"salt={salt}&t={t}&r={r}&b={b}&q={q}") + return f"{t},{r},{c}" def old(): t = str(int(time.time())) - r = ''.join(random.sample(string.ascii_lowercase + string.digits, 6)) - c = hex_digest(f'salt={salt}&t={t}&r={r}') - return f'{t},{r},{c}' + r = "".join(random.sample(string.ascii_lowercase + string.digits, 6)) + c = hex_digest(f"salt={salt}&t={t}&r={r}") + return f"{t},{r},{c}" - app_version = '2.36.1' - client_type = '5' - salt = 'YVEIkzDFNHLeKXLxzqCA9TzxCpWwbIbk' + app_version = "2.36.1" + client_type = "5" + salt = "YVEIkzDFNHLeKXLxzqCA9TzxCpWwbIbk" ds = old() - if ds_type in ('android', '2'): - app_version = '2.36.1' - client_type = '2' - salt = 'n0KjuIrKgLHh08LWSCYP0WXlVXaYvV64' + if ds_type in ("android", "2"): + app_version = "2.36.1" + client_type = "2" + salt = "n0KjuIrKgLHh08LWSCYP0WXlVXaYvV64" ds = old() - if ds_type == 'android_new': - app_version = '2.36.1' - client_type = '2' - salt = 't0qEgfub6cvueAPgR5m9aQWWVciEer7v' + if ds_type == "android_new": + app_version = "2.36.1" + client_type = "2" + salt = "t0qEgfub6cvueAPgR5m9aQWWVciEer7v" ds = new() if new_ds: - app_version = '2.36.1' - client_type = '5' - salt = 'xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs' + app_version = "2.36.1" + client_type = "5" + salt = "xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs" ds = new() return app_version, client_type, ds @@ -86,5 +87,5 @@ def get_ua(device: str = "Paimon Build", version: str = "2.36.1"): return ( f"Mozilla/5.0 (Linux; Android 12; {device}; wv) " "AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/103.0.5060.129 Mobile Safari/537.36 " - f"miHoYoBBS/{version}" + f"{'miHoYoBBS/'+version if version else ''}" ) diff --git a/plugins/genshin/gacha/gacha.py b/plugins/genshin/gacha/gacha.py index 503dc0b9..e8b191e2 100644 --- a/plugins/genshin/gacha/gacha.py +++ b/plugins/genshin/gacha/gacha.py @@ -145,7 +145,7 @@ class Gacha(Plugin, BasePlugin): self.banner_cache.setdefault(gacha_base_info.gacha_id, banner) return banner - async def de_item_list(self,item_list: List[int]) -> List[dict]: + async def de_item_list(self, item_list: List[int]) -> List[dict]: gacha_item: List[dict] = [] for item_id in item_list: if 10000 <= item_id <= 100000: diff --git a/plugins/genshin/sign.py b/plugins/genshin/sign.py index 60aab08b..1c034061 100644 --- a/plugins/genshin/sign.py +++ b/plugins/genshin/sign.py @@ -109,7 +109,7 @@ class SignSystem: data = resp.json() status = data.get("status") if status != 0: - logger.error("recognize 解析错误:[%s]%s", data.get('code'), data.get('msg')) + logger.error("recognize 解析错误:[%s]%s", data.get("code"), data.get("msg")) if data.get("code", 0) != 0: raise RuntimeError logger.info("recognize 解析成功") diff --git a/plugins/system/webapp.py b/plugins/system/webapp.py index c70037c6..325d650d 100644 --- a/plugins/system/webapp.py +++ b/plugins/system/webapp.py @@ -55,7 +55,9 @@ class WebApp(Plugin): if web_app_data: logger.info("用户 %s[%s] 触发 WEB_APP_DATA 请求", user.full_name, user.id) result = self.de_web_app_data(web_app_data.data) - logger.debug("path[%s]\ndata[%s]\ncode[%s]\nmessage[%s]", result.path, result.data, result.code, result.message) + logger.debug( + "path[%s]\ndata[%s]\ncode[%s]\nmessage[%s]", result.path, result.data, result.code, result.message + ) if result.code == 0: if result.path == "verify": validate = result.data.get("geetest_validate") diff --git a/utils/decorators/error.py b/utils/decorators/error.py index b40eae3f..bfee2649 100644 --- a/utils/decorators/error.py +++ b/utils/decorators/error.py @@ -128,7 +128,9 @@ def error_callable(func: Callable) -> Callable: logger.error("GenshinException") logger.exception(exc) await send_user_notification( - update, context, f"出错了呜呜呜 ~ 获取账号信息发生错误 错误信息为 {exc.original if exc.original else exc.retcode} ~ 请稍后再试" + update, + context, + f"出错了呜呜呜 ~ 获取账号信息发生错误 错误信息为 {exc.original if exc.original else exc.retcode} ~ 请稍后再试", ) return ConversationHandler.END except ReturnCodeError as exc: diff --git a/utils/helpers.py b/utils/helpers.py index b363caf8..913b72cf 100644 --- a/utils/helpers.py +++ b/utils/helpers.py @@ -174,11 +174,11 @@ async def execute(command, pass_error=True): async def async_re_sub( - pattern: str | Pattern, - repl: str | Callable[[Match], str] | Callable[[Match], Awaitable[str]], - string: str, - count: int = 0, - flags: int = 0, + pattern: str | Pattern, + repl: str | Callable[[Match], str] | Callable[[Match], Awaitable[str]], + string: str, + count: int = 0, + flags: int = 0, ) -> str: """ 一个支持 repl 参数为 async 函数的 re.sub @@ -205,7 +205,7 @@ async def async_re_sub( # noinspection PyCallingNonCallable replaced = repl(match) result += temp[: match.span(1)[0]] + (replaced or repl) - temp = temp[match.span(1)[1]:] + temp = temp[match.span(1)[1] :] else: while match := re.search(pattern, temp, flags=flags): replaced = None @@ -216,5 +216,5 @@ async def async_re_sub( # noinspection PyCallingNonCallable replaced = repl(match) result += temp[: match.span(1)[0]] + (replaced or repl) - temp = temp[match.span(1)[1]:] + temp = temp[match.span(1)[1] :] return result + temp