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.12
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.11.8
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 @@ -127,7 +127,10 @@ async def _va_request(
) -> Union[Dict, int]:
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 @@ -181,7 +184,13 @@ async def _request_with_fallback(
random_cookie: Optional[str] = None,
) -> Union[Any, int]:
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 @@ -192,7 +201,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 @@ -211,7 +224,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 @@ -239,11 +254,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})
return await self._request_with_fallback(
Expand All @@ -254,7 +276,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})
return await self._request_with_fallback(
Expand All @@ -265,7 +291,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(
url=GunAPI,
Expand All @@ -279,7 +309,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(
url=MapAPI,
Expand All @@ -293,7 +327,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]:
request = ApiRequest(url=ViveAPI, json={"scene": scene})
return await self._request_with_fallback(
Expand All @@ -304,7 +342,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]:
request = ApiRequest(
url=PFAPI,
Expand All @@ -318,7 +360,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(
url=ShopAPI,
Expand All @@ -337,7 +383,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(
url=AssetAPI,
Expand Down
7 changes: 6 additions & 1 deletion VAUID/utils/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ async def get_latest_battle_id(cls, user_id: str, bot_id: str) -> Optional[str]:
@classmethod
@with_session
async def update_latest_battle(
cls, session: AsyncSession, user_id: str, bot_id: str, battle_id: str, battle_time: int
cls,
session: AsyncSession,
user_id: str,
bot_id: str,
battle_id: str,
battle_time: int,
) -> None:
"""更新用户最新战绩ID"""
data = await cls.select_data(user_id, bot_id)
Expand Down
32 changes: 26 additions & 6 deletions VAUID/va_info/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ async def draw_va_info_img(

# 在线状态
if online is not None and online.get("online_text"):
online_filename = "online.png" if "在线" in online["online_text"] else "offline.png"
online_filename = (
"online.png" if "在线" in online["online_text"] else "offline.png"
)
online_img = get_cached_texture(f"online/{online_filename}")
easy_paste(img, online_img, (180, 190), direction="cc")

Expand All @@ -96,7 +98,9 @@ async def draw_va_info_img(
# 文字信息
img_draw.text((240, 60), detail["nickName"], (255, 255, 255, 255), va_font_42)
img_draw.text((240, 120), card_info["name"], (200, 200, 200, 255), va_font_30)
img_draw.text((240, 160), f"UID {detail['appNum']}", (200, 200, 200, 255), va_font_20)
img_draw.text(
(240, 160), f"UID {detail['appNum']}", (200, 200, 200, 255), va_font_20
)

# === 综合信息 ===
rank_bg = images["bg"]
Expand All @@ -110,7 +114,13 @@ def draw_stat(x: int, y: int, value: str, label: str):
rank_draw.text((x, y + 40), label, (255, 255, 255, 255), va_font_20, "mm")

# 左侧信息
rank_draw.text((100, 170), card_info["left_data"]["title"], (255, 255, 255, 255), va_font_20, "mm")
rank_draw.text(
(100, 170),
card_info["left_data"]["title"],
(255, 255, 255, 255),
va_font_20,
"mm",
)
easy_paste(rank_bg, images["rank"].resize((80, 80)), (100, 100), "cc")

draw_stat(100, 260, f"Lv{detail['gameInfoList'][0]['level']}", "游戏等级")
Expand Down Expand Up @@ -174,13 +184,17 @@ def draw_stat(x: int, y: int, value: str, label: str):
(590, 210), # 右上
]

for pos, (six_val, p_six_val) in zip(data_positions, zip(six_info["data_array"], p_six_info["data_array"])):
for pos, (six_val, p_six_val) in zip(
data_positions, zip(six_info["data_array"], p_six_info["data_array"])
):
dx = pos[0] - center_x
dy = pos[1] - center_y
distance = math.sqrt(dx**2 + dy**2)
new_x = pos[0] + (dx / distance) * 20
new_y = pos[1] + (dy / distance) * 20
draw_base.text((new_x, new_y), f"{p_six_val} | {six_val}", "white", va_font_20, "mm")
draw_base.text(
(new_x, new_y), f"{p_six_val} | {six_val}", "white", va_font_20, "mm"
)

draw_base.text((465, 628), six_info["sub_tab_name"], "white", va_font_30, "mm")
easy_paste(img, base_image, (750, 50))
Expand Down Expand Up @@ -260,7 +274,13 @@ async def draw_asset_section(
pass

item_name = item.get(name_key, "未知物品")
img_draw.text((x + 50, y + size[1] + 40), item_name, (255, 255, 255, 255), va_font_20, "mm")
img_draw.text(
(x + 50, y + size[1] + 40),
item_name,
(255, 255, 255, 255),
va_font_20,
"mm",
)

y_offset += section_bottom_offset
return y_offset
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