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
4 changes: 3 additions & 1 deletion CS2UID/csgo_info/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ async def send_csgo_match_msg(bot: Bot, ev: Event):
type_i = determine_match_type(ev.text)

# 获取比赛信息
resp = await bot.receive_resp(await get_csgo_match_img(ev.user_id, uid, tag, type_i))
resp = await bot.receive_resp(
await get_csgo_match_img(ev.user_id, uid, tag, type_i)
)
if resp is None:
return

Expand Down
26 changes: 20 additions & 6 deletions CS2UID/csgo_info/csgo_5e.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ async def get_csgo_5einfo_img(uid: str, season: str = "") -> Union[str, bytes]:
return await draw_csgo_5einfo_img(detail, info)


async def draw_csgo_5einfo_img(detail: UserHomeDetail5, info: UserSeason5) -> bytes | str:
async def draw_csgo_5einfo_img(
detail: UserHomeDetail5, info: UserSeason5
) -> bytes | str:
if not detail:
return "token已过期"
user_info = detail["user"]
Expand Down Expand Up @@ -115,7 +117,9 @@ async def draw_csgo_5einfo_img(detail: UserHomeDetail5, info: UserSeason5) -> by
# 赛季信息
main2_img = Image.open(TEXTURE / "base" / "banner.png")
main2_draw = ImageDraw.Draw(main2_img)
main2_draw.text((50, 10), season_info["now_season"], (255, 255, 255, 255), csgo_font_42)
main2_draw.text(
(50, 10), season_info["now_season"], (255, 255, 255, 255), csgo_font_42
)

img.paste(main2_img, (0, 600), main2_img)

Expand Down Expand Up @@ -345,7 +349,9 @@ async def draw_csgo_5einfo_img(detail: UserHomeDetail5, info: UserSeason5) -> by

base_img = Image.open(TEXTURE / "base" / "weapon_5ebg.png").resize((500, 110))
weapon_img = await save_img(usr_weapon["weapons_url"], "weapon5e")
weapon_img = weapon_img.resize((int(weapon_img.size[0] * 0.5), int(weapon_img.size[1] * 0.5)))
weapon_img = weapon_img.resize(
(int(weapon_img.size[0] * 0.5), int(weapon_img.size[1] * 0.5))
)
easy_paste(base_img, weapon_img, (100, 70), "cc")

weapon_draw = ImageDraw.Draw(base_img)
Expand All @@ -370,7 +376,9 @@ async def draw_csgo_5einfo_img(detail: UserHomeDetail5, info: UserSeason5) -> by
csgo_font_20,
"mm",
)
fsa = f"{usr_weapon['per_kill']}" if usr_weapon["per_kill"] is not None else "N/A"
fsa = (
f"{usr_weapon['per_kill']}" if usr_weapon["per_kill"] is not None else "N/A"
)
if usr_weapon["avg_harm"] is None:
weapon_draw.text(
(285, 60),
Expand All @@ -387,7 +395,11 @@ async def draw_csgo_5einfo_img(detail: UserHomeDetail5, info: UserSeason5) -> by
csgo_font_20,
"mm",
)
hdr = f"{usr_weapon['per_headshot']}" if usr_weapon["per_headshot"] is not None else "0%"
hdr = (
f"{usr_weapon['per_headshot']}"
if usr_weapon["per_headshot"] is not None
else "0%"
)
weapon_draw.text((430, 31), f"{hdr}", (255, 255, 255, 255), csgo_font_20, "mm")

if i % 2 == 0:
Expand Down Expand Up @@ -495,7 +507,9 @@ async def draw_csgo_5einfo_img(detail: UserHomeDetail5, info: UserSeason5) -> by
filtered_data = {selected_keys[key]: filter_data[key] for key in selected_keys}

total_value = sum(filtered_data.values())
normalized_data = {label: value / total_value for label, value in filtered_data.items()}
normalized_data = {
label: value / total_value for label, value in filtered_data.items()
}

width = 400
height = 400
Expand Down
20 changes: 15 additions & 5 deletions CS2UID/csgo_info/csgo_goods.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ async def get_csgo_goods_img(uid: str) -> Union[str, bytes]:
# return "出现意外错误,请重启core正常使用该功能"


async def draw_csgo_goods_img(detail: SteamGet, base: UserHomedetailData) -> bytes | str:
async def draw_csgo_goods_img(
detail: SteamGet, base: UserHomedetailData
) -> bytes | str:
if not detail:
return "token已过期"
if not detail["previewItem"]:
Expand All @@ -94,7 +96,9 @@ async def draw_csgo_goods_img(detail: SteamGet, base: UserHomedetailData) -> byt
level_img = Image.open(ICON_PATH / "main1.png").resize((700, 220))
await simple_paste_img(level_img, "steam库存信息", (100, 30), 40)
await simple_paste_img(level_img, f"总物品数量:{totalCount}", (100, 90), 40)
await simple_paste_img(level_img, f"总物品价值:{totalPrice / 100}馒头", (100, 150), 40)
await simple_paste_img(
level_img, f"总物品价值:{totalPrice / 100}馒头", (100, 150), 40
)

img.paste(level_img, (100, 300), level_img)

Expand Down Expand Up @@ -160,14 +164,18 @@ async def update_tag_data_for_special_types(tag_data: dict) -> None:

async def update_quality_info(one_get: OneGet, tag_data: dict) -> dict:
"""更新物品的品质信息"""
qua_color, qua_text_replacement = quality_mapping.get(tag_data.get("品质", "_default"), quality_mapping["_default"])
qua_color, qua_text_replacement = quality_mapping.get(
tag_data.get("品质", "_default"), quality_mapping["_default"]
)
if qua_text_replacement is not None:
tag_data["品质"] = qua_text_replacement
img_qua = Image.new("RGB", (5, 15), color=qua_color)
return {"img_qua": img_qua, "qua_color": qua_color}


async def paste_item_name(good_img: Image.Image, name_out: list, tag_data: dict, description: str) -> None:
async def paste_item_name(
good_img: Image.Image, name_out: list, tag_data: dict, description: str
) -> None:
"""粘贴物品的名称和种类"""
st = "ST™"
if len(name_out) == 1:
Expand Down Expand Up @@ -199,7 +207,9 @@ async def process_stat_trak(
if st_count:
await simple_paste_img(good_img, f"{st_count}个", (33, 5), color="red", size=13)

await simple_paste_img(good_img, msg1, (20, 60), color=tag_data.get("品质", "Purple"))
await simple_paste_img(
good_img, msg1, (20, 60), color=tag_data.get("品质", "Purple")
)
await simple_paste_img(good_img, msg2, (20, 25), color="Purple")


Expand Down
38 changes: 30 additions & 8 deletions CS2UID/csgo_info/csgo_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ async def draw_csgo_info_img(detail: UserDetailData) -> bytes | str:
# 主信息
main2_img = Image.open(TEXTURE / "base" / "base_bg.png")
if detail["stars"] < 10:
rank_img = Image.open(TEXTURE / "base" / "rank_logo.png").convert("RGBA").resize((120, 120))
rank_img = (
Image.open(TEXTURE / "base" / "rank_logo.png")
.convert("RGBA")
.resize((120, 120))
)
rank_draw = ImageDraw.Draw(rank_img)
rank_draw.text((58, 58), rank[0], (255, 255, 255, 255), csgo_font_30, "mm")
else:
Expand All @@ -86,7 +90,9 @@ async def draw_csgo_info_img(detail: UserDetailData) -> bytes | str:
else:
pj_img = "1.png"

rank_img = Image.open(TEXTURE / "rank" / pj_img).convert("RGBA").resize((100, 120))
rank_img = (
Image.open(TEXTURE / "rank" / pj_img).convert("RGBA").resize((100, 120))
)

easy_paste(main2_img, rank_img, (100, 100), "cc")
if detail["stars"] > 0:
Expand Down Expand Up @@ -136,7 +142,9 @@ async def draw_csgo_info_img(detail: UserDetailData) -> bytes | str:
csgo_font_42,
"mm",
)
main2_draw.text((105, 230), str(rank_scoce), (255, 255, 255, 255), csgo_font_42, "mm")
main2_draw.text(
(105, 230), str(rank_scoce), (255, 255, 255, 255), csgo_font_42, "mm"
)
main2_draw.text(
(260, 230),
str(detail["cnt"]),
Expand Down Expand Up @@ -249,7 +257,9 @@ async def draw_csgo_info_img(detail: UserDetailData) -> bytes | str:

base_img = Image.open(TEXTURE / "base" / "weapon_bg.png").resize((500, 110))
weapon_img = await save_img(usr_weapon["image"], "weapon")
weapon_img = weapon_img.resize((int(weapon_img.size[0] * 0.2), int(weapon_img.size[1] * 0.2)))
weapon_img = weapon_img.resize(
(int(weapon_img.size[0] * 0.2), int(weapon_img.size[1] * 0.2))
)
easy_paste(base_img, weapon_img, (100, 70), "cc")

weapon_draw = ImageDraw.Draw(base_img)
Expand All @@ -274,7 +284,11 @@ async def draw_csgo_info_img(detail: UserDetailData) -> bytes | str:
csgo_font_20,
"mm",
)
fsa = f"{usr_weapon['firstShotAccuracy'] * 100:.2f}%" if usr_weapon["firstShotAccuracy"] is not None else "N/A"
fsa = (
f"{usr_weapon['firstShotAccuracy'] * 100:.2f}%"
if usr_weapon["firstShotAccuracy"] is not None
else "N/A"
)
if usr_weapon["sprayAccuracy"] is None:
weapon_draw.text(
(285, 60),
Expand All @@ -291,7 +305,11 @@ async def draw_csgo_info_img(detail: UserDetailData) -> bytes | str:
csgo_font_20,
"mm",
)
hdr = f"{usr_weapon['headshotRate'] * 100:.2f}" if usr_weapon["headshotRate"] is not None else 0
hdr = (
f"{usr_weapon['headshotRate'] * 100:.2f}"
if usr_weapon["headshotRate"] is not None
else 0
)
weapon_draw.text((430, 31), f"{hdr}", (255, 255, 255, 255), csgo_font_20, "mm")

if i % 2 == 0:
Expand Down Expand Up @@ -431,7 +449,9 @@ def create_background(img_bg: Image.Image) -> Image.Image:
return Image.merge("RGBA", img_bg.split()[:3] + (new_alpha,))


def place_avatar_in_title(titel_img: Image.Image, round_head: Image.Image, name: str, uid: str) -> None:
def place_avatar_in_title(
titel_img: Image.Image, round_head: Image.Image, name: str, uid: str
) -> None:
"""在标题图像中放置头像和文本信息"""
easy_paste(titel_img, round_head, (112, 108), "cc")
head_draw = ImageDraw.Draw(titel_img)
Expand All @@ -445,7 +465,9 @@ async def add_summary_and_stars(titel_img: Image.Image, detail: UserDetailData)
pj_img = Image.open(TEXTURE / "base" / "blue.png")
pj_text = detail["summary"]
pj_draw = ImageDraw.Draw(pj_img)
pj_draw.text((118, 24), f"评价:{pj_text}", (255, 255, 255, 255), csgo_font_30, "mm")
pj_draw.text(
(118, 24), f"评价:{pj_text}", (255, 255, 255, 255), csgo_font_30, "mm"
)
titel_img.paste(pj_img, (235, 170), pj_img)

if detail["stars"] > 0:
Expand Down
12 changes: 9 additions & 3 deletions CS2UID/csgo_info/csgo_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
FONT_PATH = Path(__file__).parent / "font/萝莉体 第二版.ttf"


async def get_csgo_match_img(user_id, uid: str, tag: int, _type: int) -> Union[str, bytes]:
async def get_csgo_match_img(
user_id, uid: str, tag: int, _type: int
) -> Union[str, bytes]:
detail = await pf_api.get_csgopfmatch(uid, tag, _type)
logger.debug(detail)
if isinstance(detail, dict) and detail["data"] is None:
Expand Down Expand Up @@ -63,7 +65,9 @@ async def get_csgo_match_img(user_id, uid: str, tag: int, _type: int) -> Union[s
else:
match_type = "完美平台对战"

return await draw_csgo_match_img(detail["data"]["matchList"], name, avatar, uid, match_type)
return await draw_csgo_match_img(
detail["data"]["matchList"], name, avatar, uid, match_type
)


async def create_one_match_img(detail: Match) -> Image.Image:
Expand Down Expand Up @@ -103,7 +107,9 @@ async def create_one_match_img(detail: Match) -> Image.Image:
return img


async def draw_csgo_match_img(detail: List[Match], name: str, avatar: str, uid: str, match_type: str) -> bytes | str:
async def draw_csgo_match_img(
detail: List[Match], name: str, avatar: str, uid: str, match_type: str
) -> bytes | str:
if not detail:
return "token已过期"

Expand Down
16 changes: 12 additions & 4 deletions CS2UID/csgo_info/csgo_matchdetail.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,21 @@ async def draw_csgo_match_img(detail: MatchTotal) -> bytes | str:
await simple_paste_img(map_img, "地图时长", (220, 250), size=30)
await simple_paste_img(map_img, f"{base['duration']}分钟", (220, 300), size=30)
await simple_paste_img(map_img, "结束时间", (390, 250), size=30)
await simple_paste_img(map_img, str(base["endTime"][:10]).strip(), (390, 300), size=30)
await simple_paste_img(map_img, str(base["endTime"][11:]).strip(), (390, 340), size=30)
await simple_paste_img(
map_img, str(base["endTime"][:10]).strip(), (390, 300), size=30
)
await simple_paste_img(
map_img, str(base["endTime"][11:]).strip(), (390, 340), size=30
)
await simple_paste_img(map_img, "匹配方式", (560, 250), size=30)
if base["greenMatch"]:
await simple_paste_img(map_img, "天梯绿色对局", (560, 300), size=30, color="green")
await simple_paste_img(
map_img, "天梯绿色对局", (560, 300), size=30, color="green"
)
else:
await simple_paste_img(map_img, "天梯普通对局", (560, 300), size=30, color="blue")
await simple_paste_img(
map_img, "天梯普通对局", (560, 300), size=30, color="blue"
)
img_bg.paste(map_img, (75, -100), mask=map_img)
print(players[0])

Expand Down
16 changes: 12 additions & 4 deletions CS2UID/csgo_info/csgohome_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ async def get_csgohome_info_img(uid: str, friend: bool = False):
return await draw_csgohome_info_img(data["data"], fall["result"])


async def draw_csgohome_info_img(detail: UserHomedetailData, fall: UserFall) -> bytes | str:
async def draw_csgohome_info_img(
detail: UserHomedetailData, fall: UserFall
) -> bytes | str:
if not detail:
return "token已过期"

Expand Down Expand Up @@ -114,7 +116,9 @@ async def draw_csgohome_info_img(detail: UserHomedetailData, fall: UserFall) ->
csgo_font_42,
"mm",
)
main2_draw.text((105, 230), str(rank_scoce), (255, 255, 255, 255), csgo_font_42, "mm")
main2_draw.text(
(105, 230), str(rank_scoce), (255, 255, 255, 255), csgo_font_42, "mm"
)
main2_draw.text(
(260, 230),
str(detail["cnt"]),
Expand Down Expand Up @@ -173,7 +177,9 @@ async def draw_csgohome_info_img(detail: UserHomedetailData, fall: UserFall) ->
map_logo = (await save_img(usr_map["mapLogo"], "map")).resize((50, 50))
easy_paste(map_img, map_logo, (40, 60), "cc")
rank_png = f"{usr_map['rank'] if usr_map['rank'] is not None else '0'}.png"
rank_img = Image.open(TEXTURE / "rank_gp" / rank_png).resize((100, 40)).convert("RGBA")
rank_img = (
Image.open(TEXTURE / "rank_gp" / rank_png).resize((100, 40)).convert("RGBA")
)

easy_paste(map_img, rank_img, (70, 120), "cc")

Expand Down Expand Up @@ -231,7 +237,9 @@ async def draw_csgohome_info_img(detail: UserHomedetailData, fall: UserFall) ->

base_img = Image.open(TEXTURE / "base" / "weapon_bg.png").resize((500, 110))
weapon_img = await save_img(usr_weapon["weaponImage"], "weapon")
weapon_img = weapon_img.resize((int(weapon_img.size[0] * 0.2), int(weapon_img.size[1] * 0.2)))
weapon_img = weapon_img.resize(
(int(weapon_img.size[0] * 0.2), int(weapon_img.size[1] * 0.2))
)
easy_paste(base_img, weapon_img, (100, 70), "cc")

weapon_draw = ImageDraw.Draw(base_img)
Expand Down
10 changes: 8 additions & 2 deletions CS2UID/csgo_info/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ async def load_groudback(bg_img_path: Path | Image.Image, alpha_percent: float =
first_img = first_img.convert("RGBA")
else:
first_img = bg_img_path
transparent_img = Image.new("RGBA", first_img.size, (255, 255, 255, int(255 * alpha_percent)))
transparent_img = Image.new(
"RGBA", first_img.size, (255, 255, 255, int(255 * alpha_percent))
)
first_img.paste(transparent_img, None, transparent_img)

return first_img
Expand Down Expand Up @@ -337,7 +339,11 @@ async def make_homeweapen_img(usr_weapon: UserhomeWeapon):
await simple_paste_img(out_img, usr_weapon["weaponName"], (10, 70), size=30)

avkill = usr_weapon["weaponKill"] / usr_weapon["totalMatch"]
hs = usr_weapon["weaponHeadShot"] / usr_weapon["weaponKill"] if usr_weapon["weaponKill"] else 0
hs = (
usr_weapon["weaponHeadShot"] / usr_weapon["weaponKill"]
if usr_weapon["weaponKill"]
else 0
)
hs_out = f"{(hs * 100):.2f}%" if hs else "0%"

print_msg = [
Expand Down
Loading