From db3b1755df78c872110e47128c7031a64df2bacd Mon Sep 17 00:00:00 2001 From: qwerdvd <105906879+qwerdvd@users.noreply.github.com> Date: Fri, 11 Aug 2023 10:05:16 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E4=BD=BF=E7=94=A8=E5=8D=95?= =?UTF-8?q?=E5=BC=95=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ArknightsUID/arknightsuid_user/__init__.py | 8 +++--- ArknightsUID/utils/api/skd/api.py | 2 ++ ArknightsUID/utils/api/skd/request.py | 28 ++++++++++----------- ArknightsUID/utils/download.py | 4 +-- ArknightsUID/utils/resource/download_url.py | 4 +-- pyproject.toml | 2 +- 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/ArknightsUID/arknightsuid_user/__init__.py b/ArknightsUID/arknightsuid_user/__init__.py index 1122ecd..15d9aa9 100644 --- a/ArknightsUID/arknightsuid_user/__init__.py +++ b/ArknightsUID/arknightsuid_user/__init__.py @@ -29,13 +29,13 @@ ark_skd_cred_add = SV('森空岛cred绑定') (f'{PREFIX}绑定uid', f'{PREFIX}切换uid', f'{PREFIX}删除uid', f'{PREFIX}解绑uid') ) async def send_link_uid_msg(bot: Bot, ev: Event): - await bot.logger.info("开始执行[绑定/解绑用户信息]") + await bot.logger.info('开始执行[绑定/解绑用户信息]') qid = ev.user_id - await bot.logger.info(f"[绑定/解绑]UserID: {qid}") + await bot.logger.info(f'[绑定/解绑]UserID: {qid}') ark_uid = ev.text.strip() if ark_uid and not ark_uid.isdigit(): - return await bot.send("你输入了错误的格式!") + return await bot.send('你输入了错误的格式!') if '绑定' in ev.command: data = await ArknightsBind.insert_uid(qid, ev.bot_id, ark_uid, ev.group_id) @@ -67,7 +67,7 @@ async def send_link_uid_msg(bot: Bot, ev: Event): ) -@ark_skd_cred_add.on_prefix(("skd添加cred", "森空岛添加CRED")) +@ark_skd_cred_add.on_prefix(('skd添加cred', '森空岛添加CRED')) async def send_ark_skd_add_cred_msg(bot: Bot, ev: Event): im = await deal_skd_cred(ev.bot_id, ev.text, ev.user_id) await bot.send(im) diff --git a/ArknightsUID/utils/api/skd/api.py b/ArknightsUID/utils/api/skd/api.py index 43c7a4e..10f832a 100644 --- a/ArknightsUID/utils/api/skd/api.py +++ b/ArknightsUID/utils/api/skd/api.py @@ -1 +1,3 @@ ARK_USER_ME = 'https://zonai.skland.com/api/v1/user/me' + +ARK_GEN_CRED_BY_CODE = 'https://zonai.skland.com/api/v1/user/auth/generate_cred_by_code' diff --git a/ArknightsUID/utils/api/skd/request.py b/ArknightsUID/utils/api/skd/request.py index 551db4d..3484d67 100644 --- a/ArknightsUID/utils/api/skd/request.py +++ b/ArknightsUID/utils/api/skd/request.py @@ -13,12 +13,12 @@ from .api import ARK_USER_ME class BaseArkApi: ssl_verify = True _HEADER = { - "Host": "zonai.skland.com", - "Origin": "https://www.skland.com", - "Referer": "https://www.skland.com/", - "content-type": "application/json; charset=UTF-8", - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) \ - AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36", + 'Host': 'zonai.skland.com', + 'Origin': 'https://www.skland.com', + 'Referer': 'https://www.skland.com/', + 'content-type': 'application/json; charset=UTF-8', + 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) \ + AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36', } async def check_cred_valid(self, Cred: str) -> bool | ArknightsUserMeModel: @@ -33,33 +33,33 @@ class BaseArkApi: def unpack(self, raw_data: dict | int) -> dict | int: if isinstance(raw_data, dict): - return raw_data["data"] + return raw_data['data'] else: return raw_data async def _ark_request( self, url: str, - method: Literal["GET", "POST"] = "GET", + method: Literal['GET', 'POST'] = 'GET', header: dict[str, Any] = _HEADER, params: dict[str, Any] | None = None, data: dict[str, Any] | None = None, ) -> dict | int: - if "Cred" not in header: + if 'Cred' not in header: target_user_id = ( - data["friendUserId"] - if data and "friendUserId" in data + data['friendUserId'] + if data and 'friendUserId' in data else None ) Cred: str | None = await ArknightsUser.get_random_cookie( - target_user_id if target_user_id else "18888888" + target_user_id if target_user_id else '18888888' ) if Cred is None: return -61 arkUser = await ArknightsUser.base_select_data(ArknightsUser, Cred=Cred) if arkUser is None: return -61 - header["Cred"] = Cred + header['Cred'] = Cred async with ClientSession( connector=TCPConnector(verify_ssl=self.ssl_verify) @@ -76,7 +76,7 @@ class BaseArkApi: raw_data = await resp.json() except ContentTypeError: _raw_data = await resp.text() - raw_data = {"code": -999, "data": _raw_data} + raw_data = {'code': -999, 'data': _raw_data} if ( raw_data and 'code' in raw_data diff --git a/ArknightsUID/utils/download.py b/ArknightsUID/utils/download.py index 2b493f0..353df25 100644 --- a/ArknightsUID/utils/download.py +++ b/ArknightsUID/utils/download.py @@ -16,7 +16,7 @@ async def download_file( async with sess.get(url) as res: content = await res.read() except ClientConnectorError: - logger.warning(f"[wzry]{name}下载失败") + logger.warning(f'[Arknights]{name}下载失败') return url, path, name - async with aiofiles.open(path / name, "wb") as f: + async with aiofiles.open(path / name, 'wb') as f: await f.write(content) diff --git a/ArknightsUID/utils/resource/download_url.py b/ArknightsUID/utils/resource/download_url.py index 88b49b9..669846d 100644 --- a/ArknightsUID/utils/resource/download_url.py +++ b/ArknightsUID/utils/resource/download_url.py @@ -51,9 +51,9 @@ async def download_file( async with sess.get(url) as res: content = await res.read() except ClientConnectorError: - logger.warning(f"[cos]{name}下载失败") + logger.warning(f'[cos]{name}下载失败') return url, resource_type, name async with aiofiles.open( - PATHDICT[res_type] / resource_type / name, "wb" + PATHDICT[res_type] / resource_type / name, 'wb' ) as f: await f.write(content) diff --git a/pyproject.toml b/pyproject.toml index 413cb03..50b23dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,7 +53,7 @@ asyncio_mode = "auto" [tool.ruff] select = ["E", "W", "F", "UP", "C", "T", "PYI", "PT", "Q"] -ignore = ["E402", "C901", "UP037", "Q000"] +ignore = ["C901", "Q000"] line-length = 108 target-version = "py311"