Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ci:
autoupdate_commit_msg: "⬆️ `pre-commit-ci`自动升级"
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.14
rev: v0.15.4
hooks:
- id: ruff
args: [--fix]
Expand All @@ -20,7 +20,7 @@ repos:

- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.9.28
rev: 0.10.7
hooks:
- id: uv-lock
- id: uv-export
77 changes: 63 additions & 14 deletions VAUID/utils/api/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ async def _va_request(
"""统一的 API 请求方法"""
req_headers = dict(self._HEADER)
if headers:
headers = {k.capitalize() if k.lower() == "cookie" else k: v for k, v in headers.items()}
headers = {
k.capitalize() if k.lower() == "cookie" else k: v
for k, v in headers.items()
}
req_headers.update(headers)

if json:
Expand Down Expand Up @@ -210,7 +213,13 @@ async def _request_with_fallback(
"""
# 使用优先 cookie 请求
if cookie:
data = await self._va_request(request.url, request.method, {"Cookie": cookie}, request.params, request.json)
data = await self._va_request(
request.url,
request.method,
{"Cookie": cookie},
request.params,
request.json,
)
result = self._parse_response(data, parser, default_on_error="")
if not isinstance(result, int) or result >= 0:
return result
Expand All @@ -222,7 +231,11 @@ async def _request_with_fallback(
return -511

data = await self._va_request(
request.url, request.method, {"Cookie": random_cookie}, request.params, request.json
request.url,
request.method,
{"Cookie": random_cookie},
request.params,
request.json,
)
return self._parse_response(data, parser, default_on_error="")

Expand All @@ -244,7 +257,9 @@ async def search_player(self, key_word: str) -> Union[List[InfoBody], int]:
return data
return cast(List[InfoBody], data["data"]["userList"])

async def get_player_info(self, ctx: QueryContext, uid_list: List[str]) -> Union[SummonerInfo, int, str, None]:
async def get_player_info(
self, ctx: QueryContext, uid_list: List[str]
) -> Union[SummonerInfo, int, str, None]:
"""获取玩家信息"""
if len(uid_list) < 1 or not ctx.cookie:
return None
Expand Down Expand Up @@ -274,11 +289,18 @@ async def get_player_info(self, ctx: QueryContext, uid_list: List[str]) -> Union
async def get_player_card(self, uid: str) -> Union[CardInfo, int, str]:
"""获取玩家卡片"""
uid, ck = await self._get_cookie(uid)
data = await self._va_request(CardAPI, headers={"Cookie": ck}, json={"uuid": uid, "jump_key": "mine"})
return self._parse_response(data, lambda d: cast(CardInfo, d["data"]), default_on_error="")
data = await self._va_request(
CardAPI, headers={"Cookie": ck}, json={"uuid": uid, "jump_key": "mine"}
)
return self._parse_response(
data, lambda d: cast(CardInfo, d["data"]), default_on_error=""
)

async def get_detail_card(
self, scene: str, cookie: Optional[str] = None, random_cookie: Optional[str] = None
self,
scene: str,
cookie: Optional[str] = None,
random_cookie: Optional[str] = None,
) -> Union[List[Battle], int]:
"""获取详细卡片"""
request = ApiRequest(url=ValCardAPI, json={"scene": scene})
Expand All @@ -290,7 +312,11 @@ async def get_detail_card(
)

async def get_online(
self, uid: str, scene: str, cookie: Optional[str] = None, random_cookie: Optional[str] = None
self,
uid: str,
scene: str,
cookie: Optional[str] = None,
random_cookie: Optional[str] = None,
) -> Union[CardOnline, int]:
"""获取在线信息"""
request = ApiRequest(url=OnlineAPI, json={"uuid": uid, "scene": scene})
Expand All @@ -302,7 +328,11 @@ async def get_online(
)

async def get_gun(
self, uid: str, scene: str, cookie: Optional[str] = None, random_cookie: Optional[str] = None
self,
uid: str,
scene: str,
cookie: Optional[str] = None,
random_cookie: Optional[str] = None,
) -> Union[List[GunInfo], int]:
"""获取枪械信息"""
request = ApiRequest(
Expand All @@ -317,7 +347,11 @@ async def get_gun(
)

async def get_map(
self, uid: str, scene: str, cookie: Optional[str] = None, random_cookie: Optional[str] = None
self,
uid: str,
scene: str,
cookie: Optional[str] = None,
random_cookie: Optional[str] = None,
) -> Union[List[MapInfo], int]:
"""获取地图信息"""
request = ApiRequest(
Expand All @@ -332,7 +366,11 @@ async def get_map(
)

async def get_vive(
self, uid: str, scene: str, cookie: Optional[str] = None, random_cookie: Optional[str] = None
self,
uid: str,
scene: str,
cookie: Optional[str] = None,
random_cookie: Optional[str] = None,
) -> Union[List[Vive], int]:
"""获取 Vive 信息"""
request = ApiRequest(url=ViveAPI, json={"scene": scene})
Expand All @@ -344,7 +382,11 @@ async def get_vive(
)

async def get_pf(
self, uid: str, scene: str, cookie: Optional[str] = None, random_cookie: Optional[str] = None
self,
uid: str,
scene: str,
cookie: Optional[str] = None,
random_cookie: Optional[str] = None,
) -> Union[List[PFInfo], int]:
"""获取 PF 信息"""
request = ApiRequest(
Expand All @@ -359,7 +401,11 @@ async def get_pf(
)

async def get_shop(
self, uid: str, scene: str, cookie: Optional[str] = None, random_cookie: Optional[str] = None
self,
uid: str,
scene: str,
cookie: Optional[str] = None,
random_cookie: Optional[str] = None,
) -> Union[List[Shop], int]:
"""获取商店信息"""
request = ApiRequest(
Expand All @@ -379,7 +425,10 @@ async def get_shop(
)

async def get_asset(
self, scene: str, cookie: Optional[str] = None, random_cookie: Optional[str] = None
self,
scene: str,
cookie: Optional[str] = None,
random_cookie: Optional[str] = None,
) -> Union[AssetData, int]:
"""获取资产信息"""
request = ApiRequest(
Expand Down
42 changes: 30 additions & 12 deletions VAUID/va_info/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ async def draw_hero_section(left_bg: Image.Image, hero: List[PFInfo]):
hero_tasks = [save_img(one_hero["image_url"], "hero2") for one_hero in hero[:3]]
hero_images = await asyncio.gather(*hero_tasks)

for index, (one_hero, hero_img) in enumerate(zip(hero[:3], hero_images), start=1):
for index, (one_hero, hero_img) in enumerate(
zip(hero[:3], hero_images), start=1
):
hero_one = Image.new("RGBA", (700, 70), (0, 0, 0, 0))

# 创建圆角头像背景
Expand Down Expand Up @@ -131,7 +133,9 @@ async def draw_weapon_section(left_bg: Image.Image, gun: List[GunInfo]):
weapon_tasks = [save_img(one_gun["image_url"], "weapon") for one_gun in gun[:8]]
weapon_images = await asyncio.gather(*weapon_tasks)

for index, (one_gun, one_weapon) in enumerate(zip(gun[:8], weapon_images), start=1):
for index, (one_gun, one_weapon) in enumerate(
zip(gun[:8], weapon_images), start=1
):
weapon_bg = get_cached_texture("weapon.png")
weapon_draw = ImageDraw.Draw(weapon_bg)

Expand Down Expand Up @@ -178,7 +182,9 @@ async def draw_weapon_section(left_bg: Image.Image, gun: List[GunInfo]):
easy_paste(left_bg, weapon_bg, (weapon_x, weapon_y), "lt")

@staticmethod
def draw_vive_section(right_bg: Image.Image, right_draw: ImageDrawType, vive: List[Vive]):
def draw_vive_section(
right_bg: Image.Image, right_draw: ImageDrawType, vive: List[Vive]
):
"""绘制射击数据部分"""
if vive is None:
return
Expand All @@ -187,7 +193,9 @@ def draw_vive_section(right_bg: Image.Image, right_draw: ImageDrawType, vive: Li
positions = [(370, 45), (370, 120), (370, 195)]

for data, pos in zip(shooting_data[:3], positions):
right_draw.text(pos, data["content"], (255, 255, 255, 255), va_font_30, "mm")
right_draw.text(
pos, data["content"], (255, 255, 255, 255), va_font_30, "mm"
)
right_draw.text(
(pos[0] + 280, pos[1]),
data["sub_content"],
Expand Down Expand Up @@ -223,11 +231,13 @@ async def draw_battle_section(
"失败": "head_icon_fail",
"平局": "head_icon_draw",
}
icon_key: Literal["head_icon_win", "head_icon_fail", "head_icon_draw"] = icon_key_map.get(
battle["result_title"], "head_icon_draw"
)
icon_key: Literal[
"head_icon_win", "head_icon_fail", "head_icon_draw"
] = icon_key_map.get(battle["result_title"], "head_icon_draw")
if icon_key in battle["score_level"]:
image_tasks.append(save_img(battle["score_level"][icon_key], "rank"))
image_tasks.append(
save_img(battle["score_level"][icon_key], "rank")
)
if battle.get("achievement"):
for ach in battle["achievement"]:
image_tasks.append(save_img(ach["icon"], "icon"))
Expand All @@ -243,7 +253,9 @@ async def draw_battle_section(
"胜利": ("win", "green_head.png"),
"失败": ("fail", "red_head.png"),
}
result, head_file = result_map.get(one_valcard["result_title"], ("draw", "grey_head.png"))
result, head_file = result_map.get(
one_valcard["result_title"], ("draw", "grey_head.png")
)

head2_bg = get_cached_texture(head_file)
result_color = one_valcard["result_color"]
Expand Down Expand Up @@ -307,7 +319,9 @@ async def draw_battle_section(
radius=15,
fill=hex_to_rgba(score_color, alpha=255),
)
score_draw.text((40, 20), one_valcard["score"], "white", va_font_20, "mm")
score_draw.text(
(40, 20), one_valcard["score"], "white", va_font_20, "mm"
)
easy_paste(battle_bg, score_bg, (610, 25), "lt")

if one_valcard["is_friend"] == 1:
Expand Down Expand Up @@ -349,8 +363,12 @@ def draw_hexagonal_panel(
# 角度:270°, 210°, 150°, 90°, 30°, 330°
hexagon_points = [
(
center_x + (proportion_array[i] / 100 * 200) * math.cos(-math.pi / 2 - math.pi / 3 * i),
center_y + (proportion_array[i] / 100 * 200) * math.sin(-math.pi / 2 - math.pi / 3 * i),
center_x
+ (proportion_array[i] / 100 * 200)
* math.cos(-math.pi / 2 - math.pi / 3 * i),
center_y
+ (proportion_array[i] / 100 * 200)
* math.sin(-math.pi / 2 - math.pi / 3 * i),
)
for i in range(6)
]
Expand Down
Loading