From cc4d7bfe66bd96de91d0fcc8a45c7e3e12f9efb3 Mon Sep 17 00:00:00 2001 From: baiqwerdvd <158065462+baiqwerdvd@users.noreply.github.com> Date: Thu, 27 Feb 2025 00:11:44 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20line-length=20=3D=20108?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StarRailUID/sruid_utils/api/mys/api.py | 36 +++------ .../starrailuid_abyss/draw_abyss_card.py | 4 +- .../starrailuid_abyss_boss/draw_abyss_card.py | 4 +- .../draw_abyss_card.py | 4 +- .../starrailuid_charinfo/draw_char_img.py | 78 +++++-------------- .../starrailuid_charinfo/get_char_img.py | 21 ++--- StarRailUID/starrailuid_charinfo/to_card.py | 14 +--- .../starrailuid_config/config_default.py | 4 +- .../starrailuid_gachalog/draw_gachalogs.py | 55 +++---------- .../starrailuid_gachalog/get_gachalogs.py | 8 +- .../starrailuid_note/draw_note_card.py | 12 +-- StarRailUID/starrailuid_note/note_text.py | 11 +-- .../starrailuid_rogue/draw_rogue_card.py | 24 ++---- .../draw_roleinfo_card.py | 20 ++--- .../starrailuid_stamina/draw_stamina_card.py | 4 +- StarRailUID/starrailuid_stamina/notice.py | 8 +- .../starrailuid_stamina/stamina_text.py | 5 +- StarRailUID/starrailuid_user/__init__.py | 4 +- StarRailUID/utils/error_reply.py | 4 +- StarRailUID/utils/image/image_tools.py | 12 +-- StarRailUID/utils/mys_api.py | 24 ++---- pyproject.toml | 46 +---------- 22 files changed, 88 insertions(+), 314 deletions(-) diff --git a/StarRailUID/sruid_utils/api/mys/api.py b/StarRailUID/sruid_utils/api/mys/api.py index 28c3344..881fe96 100644 --- a/StarRailUID/sruid_utils/api/mys/api.py +++ b/StarRailUID/sruid_utils/api/mys/api.py @@ -14,48 +14,30 @@ STAR_RAIL_SIGN_EXTRA_REWARD_URL = f"{OLD_URL}/event/luna/extra_reward" STAR_RAIL_SIGN_URL = f"{OLD_URL}/event/luna/sign" STAR_RAIL_SIGN_URL_OS = f"{OS_URL}/event/luna/os/sign" STAR_RAIL_MONTH_INFO_URL = f"{OLD_URL}/event/srledger/month_info" # 开拓阅历接口 -STAR_RAIL_MONTH_DETAIL_URL = ( - f"{OLD_URL}/event/srledger/month_detail" # 开拓阅历详情接口 -) +STAR_RAIL_MONTH_DETAIL_URL = f"{OLD_URL}/event/srledger/month_detail" # 开拓阅历详情接口 STAR_RAIL_NOTE_URL = f"{NEW_URL}/game_record/app/hkrpg/api/note" # 实时便签接口 STAR_RAIL_NOTE_URL_OS = f"{OS_INFO_URL}/game_record/hkrpg/api/note" # OS实时便签接口 STAR_RAIL_INDEX_URL = f"{NEW_URL}/game_record/app/hkrpg/api/index" # 角色橱窗接口 STAR_RAIL_INDEX_URL_OS = f"{OS_INFO_URL}/game_record/hkrpg/api/index" # OS角色橱窗接口 -STAR_RAIL_AVATAR_BASIC_URL = ( - f"{NEW_URL}/game_record/app/hkrpg/api/avatar/basic" # 全部角色接口 -) -STAR_RAIL_ROLE_BASIC_INFO_URL = ( - f"{NEW_URL}/game_record/app/hkrpg/api/role/basicInfo" # 角色基础信息接口 -) +STAR_RAIL_AVATAR_BASIC_URL = f"{NEW_URL}/game_record/app/hkrpg/api/avatar/basic" # 全部角色接口 +STAR_RAIL_ROLE_BASIC_INFO_URL = f"{NEW_URL}/game_record/app/hkrpg/api/role/basicInfo" # 角色基础信息接口 STAR_RAIL_ROLE_BASIC_INFO_URL_OS = f"{OS_INFO_URL}/game_record/hkrpg/api/index" -STAR_RAIL_AVATAR_INFO_URL = ( - f"{NEW_URL}/game_record/app/hkrpg/api/avatar/info" # 角色详细信息接口 -) -STAR_RAIL_AVATAR_INFO_URL_OS = ( - f"{OS_INFO_URL}/game_record/hkrpg/api/avatar/info" # OS角色详细信息接口 -) +STAR_RAIL_AVATAR_INFO_URL = f"{NEW_URL}/game_record/app/hkrpg/api/avatar/info" # 角色详细信息接口 +STAR_RAIL_AVATAR_INFO_URL_OS = f"{OS_INFO_URL}/game_record/hkrpg/api/avatar/info" # OS角色详细信息接口 STAR_RAIL_AVATAR_LIST_URL = f"{OLD_URL}/event/rpgcalc/avatar/list" STAR_RAIL_AVATAR_DETAIL_URL = f"{OLD_URL}/event/rpgcalc/avatar/detail" CHALLENGE_INFO_URL = f"{NEW_URL}/game_record/app/hkrpg/api/challenge" # 忘却之庭 CHALLENGE_INFO_URL_OS = f"{OS_INFO_URL}/game_record/hkrpg/api/challenge" # OS忘却之庭 -CHALLENGE_STORY_INFO_URL = ( - f"{NEW_URL}/game_record/app/hkrpg/api/challenge_story" # 虚构叙事 -) -CHALLENGE_BOSS_INFO_URL = ( - f"{NEW_URL}/game_record/app/hkrpg/api/challenge_boss" # 末日幻影 -) +CHALLENGE_STORY_INFO_URL = f"{NEW_URL}/game_record/app/hkrpg/api/challenge_story" # 虚构叙事 +CHALLENGE_BOSS_INFO_URL = f"{NEW_URL}/game_record/app/hkrpg/api/challenge_boss" # 末日幻影 ROGUE_INFO_URL = f"{NEW_URL}/game_record/app/hkrpg/api/rogue" # 角色模拟宇宙信息接口 -ROGUE_LOCUST_INFO_URL = ( - f"{NEW_URL}/game_record/app/hkrpg/api/rogue_locust" # 角色寰宇蝗灾信息接口 -) +ROGUE_LOCUST_INFO_URL = f"{NEW_URL}/game_record/app/hkrpg/api/rogue_locust" # 角色寰宇蝗灾信息接口 -STAR_RAIL_GACHA_LOG_URL = ( - f"https://public-operation-hkrpg.mihoyo.com/common/gacha_record/api/getGachaLog" -) +STAR_RAIL_GACHA_LOG_URL = f"https://public-operation-hkrpg.mihoyo.com/common/gacha_record/api/getGachaLog" STAR_RAIL_GACHA_LOG_URL_OS = f"{OS_OLD_URL}/common/gacha_record/api/getGachaLog" GET_FP_URL = "https://public-data-api.mihoyo.com/device-fp/api/getFp" diff --git a/StarRailUID/starrailuid_abyss/draw_abyss_card.py b/StarRailUID/starrailuid_abyss/draw_abyss_card.py index a4563b7..8277f67 100644 --- a/StarRailUID/starrailuid_abyss/draw_abyss_card.py +++ b/StarRailUID/starrailuid_abyss/draw_abyss_card.py @@ -120,9 +120,7 @@ async def draw_abyss_img( if raw_abyss_data.max_floor == "": return f"你还没有挑战本期深渊!\n可以使用[{prefix}上期深渊]命令查询上期~" # 过滤掉 is_fast (快速通关) 为 True 的项 - floor_detail = [ - detail for detail in raw_abyss_data.all_floor_detail if not detail.is_fast - ] + floor_detail = [detail for detail in raw_abyss_data.all_floor_detail if not detail.is_fast] floor_num = len(floor_detail) # 获取背景图片各项参数 diff --git a/StarRailUID/starrailuid_abyss_boss/draw_abyss_card.py b/StarRailUID/starrailuid_abyss_boss/draw_abyss_card.py index 7d341ba..82d21c2 100644 --- a/StarRailUID/starrailuid_abyss_boss/draw_abyss_card.py +++ b/StarRailUID/starrailuid_abyss_boss/draw_abyss_card.py @@ -124,9 +124,7 @@ async def draw_abyss_img( if raw_abyss_data.max_floor == "": return f"你还没有挑战本期末日幻影!\n可以使用[{prefix}上期末日幻影]命令查询上期~" # 过滤掉 is_fast (快速通关) 为 True 的项 - floor_detail = [ - detail for detail in raw_abyss_data.all_floor_detail if not detail.is_fast - ] + floor_detail = [detail for detail in raw_abyss_data.all_floor_detail if not detail.is_fast] floor_num = len(floor_detail) # 获取背景图片各项参数 diff --git a/StarRailUID/starrailuid_abyss_story/draw_abyss_card.py b/StarRailUID/starrailuid_abyss_story/draw_abyss_card.py index 4695da6..68ea3c5 100644 --- a/StarRailUID/starrailuid_abyss_story/draw_abyss_card.py +++ b/StarRailUID/starrailuid_abyss_story/draw_abyss_card.py @@ -139,9 +139,7 @@ async def draw_abyss_img( if raw_abyss_data.max_floor == "": return f"你还没有挑战本期虚构叙事!\n可以使用[{prefix}上期虚构叙事]命令查询上期~" # 过滤掉 is_fast (快速通关) 为 True 的项 - floor_detail = [ - detail for detail in raw_abyss_data.all_floor_detail if not detail.is_fast - ] + floor_detail = [detail for detail in raw_abyss_data.all_floor_detail if not detail.is_fast] floor_num = len(floor_detail) # 获取背景图片各项参数 diff --git a/StarRailUID/starrailuid_charinfo/draw_char_img.py b/StarRailUID/starrailuid_charinfo/draw_char_img.py index 3b4b6fb..3fa4846 100644 --- a/StarRailUID/starrailuid_charinfo/draw_char_img.py +++ b/StarRailUID/starrailuid_charinfo/draw_char_img.py @@ -96,9 +96,7 @@ RELIC_CNT = { } -async def draw_char_img( - char_data: MihomoCharacter, sr_uid: str, msg: str -) -> Union[bytes, str]: +async def draw_char_img(char_data: MihomoCharacter, sr_uid: str, msg: str) -> Union[bytes, str]: if isinstance(char_data, str): return char_data char = await cal_char_info(char_data) @@ -122,11 +120,7 @@ async def draw_char_img( # 放角色立绘 char_info = bg_img.copy() char_info = char_info.resize((1050, 2050 + bg_height)) - char_img = ( - Image.open(CHAR_PORTRAIT_PATH / f"{char.char_id}.png") - .resize((1050, 1050)) - .convert("RGBA") - ) + char_img = Image.open(CHAR_PORTRAIT_PATH / f"{char.char_id}.png").resize((1050, 1050)).convert("RGBA") char_info.paste(char_img, (-220, -130), char_img) # 放属性图标 @@ -152,17 +146,13 @@ async def draw_char_img( ) # 放星级 - rarity_img = Image.open( - TEXT_PATH / f"LightCore_Rarity{char.char_rarity}.png" - ).resize((306, 72)) + rarity_img = Image.open(TEXT_PATH / f"LightCore_Rarity{char.char_rarity}.png").resize((306, 72)) char_info.paste(rarity_img, (490, 189), rarity_img) # 放命座 rank_img = Image.open(TEXT_PATH / "ImgNewBg.png") rank_img_draw = ImageDraw.Draw(rank_img) - rank_img_draw.text( - (70, 44), f"{NUM_MAP[char.char_rank]}命", white_color, sr_font_28, "mm" - ) + rank_img_draw.text((70, 44), f"{NUM_MAP[char.char_rank]}命", white_color, sr_font_28, "mm") char_info.paste(rank_img, (722, 181), rank_img) # 放uid @@ -198,8 +188,7 @@ async def draw_char_img( # 攻击力 attack = int(char.base_attributes.attack) add_attack = int( - char.add_attr.get("AttackDelta", 0) - + attack * char.add_attr.get("AttackAddedRatio", 0) + char.add_attr.get("AttackDelta", 0) + attack * char.add_attr.get("AttackAddedRatio", 0) ) attr_bg_draw.text( (413, 31 + 48), @@ -218,8 +207,7 @@ async def draw_char_img( # 防御力 defence = int(char.base_attributes.defence) add_defence = int( - char.add_attr.get("DefenceDelta", 0) - + defence * char.add_attr.get("DefenceAddedRatio", 0) + char.add_attr.get("DefenceDelta", 0) + defence * char.add_attr.get("DefenceAddedRatio", 0) ) attr_bg_draw.text( (413, 31 + 48 * 2), @@ -237,10 +225,7 @@ async def draw_char_img( ) # 速度 speed = int(char.base_attributes.speed) - add_speed = int( - char.add_attr.get("SpeedDelta", 0) - + speed * char.add_attr.get("SpeedAddedRatio", 0) - ) + add_speed = int(char.add_attr.get("SpeedDelta", 0) + speed * char.add_attr.get("SpeedAddedRatio", 0)) attr_bg_draw.text( (413, 31 + 48 * 3), f"{speed + add_speed}", @@ -324,11 +309,7 @@ async def draw_char_img( .resize((50, 50)) .convert("RGBA") ) - rank_img.putalpha( - rank_img.getchannel("A").point( - lambda x: round(x * 0.45) if x > 0 else 0 - ) - ) + rank_img.putalpha(rank_img.getchannel("A").point(lambda x: round(x * 0.45) if x > 0 else 0)) rank_no_bg.paste(rank_img, (19, 19), rank_img) char_info.paste(rank_no_bg, (20 + rank * 80, 630), rank_no_bg) @@ -339,10 +320,7 @@ async def draw_char_img( skill_attr_img = Image.open(TEXT_PATH / f"skill_attr{i + 1}.png") skill_panel_img = Image.open(TEXT_PATH / "skill_panel.png") skill_img = ( - Image.open( - SKILL_PATH / f"{char.char_id}_" - f"{skill_type_map[skill.skillAttackType][1]}.png" - ) + Image.open(SKILL_PATH / f"{char.char_id}_{skill_type_map[skill.skillAttackType][1]}.png") .convert("RGBA") .resize((55, 55)) ) @@ -378,11 +356,7 @@ async def draw_char_img( if char.equipment != {}: weapon_bg = Image.open(TEXT_PATH / "weapon_bg.png") weapon_id = char.equipment.equipmentID - weapon_img = ( - Image.open(WEAPON_PATH / f"{weapon_id}.png") - .convert("RGBA") - .resize((170, 180)) - ) + weapon_img = Image.open(WEAPON_PATH / f"{weapon_id}.png").convert("RGBA").resize((170, 180)) weapon_bg.paste(weapon_img, (20, 90), weapon_img) weapon_bg_draw = ImageDraw.Draw(weapon_bg) weapon_bg_draw.text( @@ -411,9 +385,9 @@ async def draw_char_img( ) weapon_bg.paste(rank_img, (weapon_name_len + 330, 2), rank_img) - rarity_img = Image.open( - TEXT_PATH / f"LightCore_Rarity{char.equipment.equipmentRarity}.png" - ).resize((306, 72)) + rarity_img = Image.open(TEXT_PATH / f"LightCore_Rarity{char.equipment.equipmentRarity}.png").resize( + (306, 72) + ) weapon_bg.paste(rarity_img, (223, 55), rarity_img) weapon_bg_draw.text( (498, 90), @@ -466,16 +440,12 @@ async def draw_char_img( rarity = RelicId2Rarity[str(relic.relicId)] relic_img = Image.open(TEXT_PATH / f"yq_bg{rarity}.png") if str(relic.SetId)[0] == "3": - relic_piece_img = Image.open( - RELIC_PATH / f"{relic.SetId}_{relic.Type - 5}.png" - ) + relic_piece_img = Image.open(RELIC_PATH / f"{relic.SetId}_{relic.Type - 5}.png") else: - relic_piece_img = Image.open( - RELIC_PATH / f"{relic.SetId}_{relic.Type - 1}.png" - ) - relic_piece_new_img = relic_piece_img.resize( - (105, 105), Image.Resampling.LANCZOS - ).convert("RGBA") + relic_piece_img = Image.open(RELIC_PATH / f"{relic.SetId}_{relic.Type - 1}.png") + relic_piece_new_img = relic_piece_img.resize((105, 105), Image.Resampling.LANCZOS).convert( + "RGBA" + ) relic_img.paste( relic_piece_new_img, (200, 90), @@ -509,9 +479,7 @@ async def draw_char_img( mainValueStr = str(math.floor(main_value * 1000) / 10) + "%" mainNameNew = ( - main_name.replace("百分比", "") - .replace("伤害加成", "伤加成") - .replace("属性伤害", "伤害") + main_name.replace("百分比", "").replace("伤害加成", "伤加成").replace("属性伤害", "伤害") ) relic_img_draw.text( @@ -551,9 +519,7 @@ async def draw_char_img( subValue = i.Value subProperty = i.Property - tmp_score = await get_relic_score( - subProperty, subValue, char.char_name, False, relic.Type - ) + tmp_score = await get_relic_score(subProperty, subValue, char.char_name, False, relic.Type) single_relic_score += tmp_score if subName in ["攻击力", "生命值", "防御力", "速度"]: @@ -747,9 +713,7 @@ async def draw_char_img( return res -async def get_char_data( - uid: str, char_name: str, enable_self: bool = True -) -> Union[Dict, str]: +async def get_char_data(uid: str, char_name: str, enable_self: bool = True) -> Union[Dict, str]: player_path = PLAYER_PATH / str(uid) SELF_PATH = player_path / "SELF" if "开拓者" in str(char_name): diff --git a/StarRailUID/starrailuid_charinfo/get_char_img.py b/StarRailUID/starrailuid_charinfo/get_char_img.py index d6ee711..c39db5c 100644 --- a/StarRailUID/starrailuid_charinfo/get_char_img.py +++ b/StarRailUID/starrailuid_charinfo/get_char_img.py @@ -226,9 +226,7 @@ async def get_fake_char_data( return char_data -async def get_char_data( - uid: str, char_name: str, enable_self: bool = True -) -> Union[MihomoCharacter, str]: +async def get_char_data(uid: str, char_name: str, enable_self: bool = True) -> Union[MihomoCharacter, str]: if "开拓者" in str(char_name): char_name = "开拓者" char_id = await name_to_avatar_id(char_name) @@ -331,19 +329,14 @@ async def get_baseAttributes( # 攻击力 base_attributes.attack = ( - avatar_promotion_base.AttackBase.Value - + avatar_promotion_base.AttackAdd.Value * (80 - 1) + avatar_promotion_base.AttackBase.Value + avatar_promotion_base.AttackAdd.Value * (80 - 1) ) # 防御力 base_attributes.defence = ( - avatar_promotion_base.DefenceBase.Value - + avatar_promotion_base.DefenceAdd.Value * (80 - 1) + avatar_promotion_base.DefenceBase.Value + avatar_promotion_base.DefenceAdd.Value * (80 - 1) ) # 血量 - base_attributes.hp = ( - avatar_promotion_base.HPBase.Value - + avatar_promotion_base.HPAdd.Value * (80 - 1) - ) + base_attributes.hp = avatar_promotion_base.HPBase.Value + avatar_promotion_base.HPAdd.Value * (80 - 1) # 速度 base_attributes.speed = avatar_promotion_base.SpeedBase.Value # 暴击率 @@ -467,8 +460,7 @@ async def get_char( skilllevel_max = 12 skilllevel = min( skilllevel_max, - char_data.avatarSkill[index].skillLevel - + skill_up_num, + char_data.avatarSkill[index].skillLevel + skill_up_num, ) char_data.avatarSkill[index].skillLevel = skilllevel break @@ -507,8 +499,7 @@ async def get_char( # 生命值 equipment_info.baseAttributes.hp = ( - equipment_promotion_base.BaseHP.Value - + equipment_promotion_base.BaseHPAdd.Value * (80 - 1) + equipment_promotion_base.BaseHP.Value + equipment_promotion_base.BaseHPAdd.Value * (80 - 1) ) # 攻击力 equipment_info.baseAttributes.attack = ( diff --git a/StarRailUID/starrailuid_charinfo/to_card.py b/StarRailUID/starrailuid_charinfo/to_card.py index a33ad04..1c24ae1 100644 --- a/StarRailUID/starrailuid_charinfo/to_card.py +++ b/StarRailUID/starrailuid_charinfo/to_card.py @@ -33,9 +33,7 @@ async def api_to_card(uid: str) -> Union[Tuple[bytes, List[str]], bytes]: uid, save_path=PLAYER_PATH, ) - if (not isinstance(char_id_list, str) and char_id_list == []) or isinstance( - char_id_list, str - ): + if (not isinstance(char_id_list, str) and char_id_list == []) or isinstance(char_id_list, str): return await convert_img(pic_500) img = await draw_enka_card(uid=uid, char_list=char_id_list, showfrom=1) @@ -115,11 +113,7 @@ async def draw_mihomo_char(index: int, img: Image.Image, char_data: Dict): char_star = await avatar_id_to_char_star(str(char_id)) char_card = Image.open(TEXT_PATH / f"char{char_star}_bg.png") char_temp = Image.new("RGBA", (300, 650)) - char_img = ( - Image.open(str(CHAR_PREVIEW_PATH / f"{char_id}.png")) - .convert("RGBA") - .resize((449, 615)) - ) + char_img = Image.open(str(CHAR_PREVIEW_PATH / f"{char_id}.png")).convert("RGBA").resize((449, 615)) if char_name == "希儿": char_img = char_img.resize((449, 650)) char_img = char_img.crop((135, 0, 379, 457)) @@ -147,9 +141,7 @@ async def draw_enka_char(index: int, img: Image.Image, char_data: Dict): char_card = Image.open(TEXT_PATH / f"ring_{char_star}.png") _path = CHAR_PREVIEW_PATH / f"{char_id}.png" char_img = Image.open(_path).convert("RGBA") - char_img = char_img.resize( - (int(char_img.size[0] * 0.76), int(char_img.size[1] * 0.76)) - ) + char_img = char_img.resize((int(char_img.size[0] * 0.76), int(char_img.size[1] * 0.76))) char_temp = Image.new("RGBA", (300, 400)) card_temp = Image.new("RGBA", (300, 400)) diff --git a/StarRailUID/starrailuid_config/config_default.py b/StarRailUID/starrailuid_config/config_default.py index b45e25c..a64cb97 100644 --- a/StarRailUID/starrailuid_config/config_default.py +++ b/StarRailUID/starrailuid_config/config_default.py @@ -8,9 +8,7 @@ from gsuid_core.utils.plugins_config.models import ( ) CONIFG_DEFAULT: Dict[str, GSC] = { - "SignTime": GsListStrConfig( - "每晚签到时间设置", "每晚米游社签到时间设置(时,分)", ["0", "38"] - ), + "SignTime": GsListStrConfig("每晚签到时间设置", "每晚米游社签到时间设置(时,分)", ["0", "38"]), "PrivateSignReport": GsBoolConfig( "签到私聊报告", "关闭后将不再给任何人推送当天签到任务完成情况", diff --git a/StarRailUID/starrailuid_gachalog/draw_gachalogs.py b/StarRailUID/starrailuid_gachalog/draw_gachalogs.py index 6ad22eb..3044ddd 100644 --- a/StarRailUID/starrailuid_gachalog/draw_gachalogs.py +++ b/StarRailUID/starrailuid_gachalog/draw_gachalogs.py @@ -238,18 +238,14 @@ async def draw_gachalogs_img(uid: str, ev: Event) -> Union[bytes, str]: total_data[i]["avg"] = 0 else: total_data[i]["avg"] = float( - "{:.2f}".format( - sum(total_data[i]["r_num"]) / len(total_data[i]["r_num"]) - ) + "{:.2f}".format(sum(total_data[i]["r_num"]) / len(total_data[i]["r_num"])) ) # 计算平均up数量 if len(total_data[i]["up_list"]) == 0: total_data[i]["avg_up"] = 0 else: total_data[i]["avg_up"] = float( - "{:.2f}".format( - sum(total_data[i]["r_num"]) / len(total_data[i]["up_list"]) - ) + "{:.2f}".format(sum(total_data[i]["r_num"]) / len(total_data[i]["up_list"])) ) # 计算抽卡类型 @@ -257,37 +253,20 @@ async def draw_gachalogs_img(uid: str, ev: Event) -> Union[bytes, str]: if gacha_data[f"{CHANGE_MAP[i]}_gacha_num"] <= 40: total_data[i]["type"] = "佛系型" # 如果长时抽卡总数占据了总抽卡数的70% - elif ( - total_data[i]["long_gacha_data"]["num"] - / gacha_data[f"{CHANGE_MAP[i]}_gacha_num"] - >= 0.7 - ): + elif total_data[i]["long_gacha_data"]["num"] / gacha_data[f"{CHANGE_MAP[i]}_gacha_num"] >= 0.7: total_data[i]["type"] = "随缘型" # 如果短时抽卡总数占据了总抽卡数的70% - elif ( - total_data[i]["short_gacha_data"]["num"] - / gacha_data[f"{CHANGE_MAP[i]}_gacha_num"] - >= 0.7 - ): + elif total_data[i]["short_gacha_data"]["num"] / gacha_data[f"{CHANGE_MAP[i]}_gacha_num"] >= 0.7: total_data[i]["type"] = "规划型" # 如果抽卡数量远远大于标称抽卡数量 - elif ( - total_data[i]["all_time"] / 30000 - <= gacha_data[f"{CHANGE_MAP[i]}_gacha_num"] - ): + elif total_data[i]["all_time"] / 30000 <= gacha_data[f"{CHANGE_MAP[i]}_gacha_num"]: # 如果长时抽卡数量大于短时抽卡数量 - if ( - total_data[i]["long_gacha_data"]["num"] - >= total_data[i]["short_gacha_data"]["num"] - ): + if total_data[i]["long_gacha_data"]["num"] >= total_data[i]["short_gacha_data"]["num"]: total_data[i]["type"] = "规划型" else: total_data[i]["type"] = "氪金型" # 如果抽卡数量远远小于标称抽卡数量 - elif ( - total_data[i]["all_time"] / 32000 - >= gacha_data[f"{CHANGE_MAP[i]}_gacha_num"] * 2 - ): + elif total_data[i]["all_time"] / 32000 >= gacha_data[f"{CHANGE_MAP[i]}_gacha_num"] * 2: total_data[i]["type"] = "仓鼠型" # 常量偏移数据 @@ -323,21 +302,13 @@ async def draw_gachalogs_img(uid: str, ev: Event) -> Union[bytes, str]: for index, i in enumerate(type_list): title = Image.open(TEXT_PATH / "bg2.png") if i == "群星跃迁": - level = await get_level_from_list( - total_data[i]["avg"], [54, 61, 67, 73, 80] - ) + level = await get_level_from_list(total_data[i]["avg"], [54, 61, 67, 73, 80]) elif i == "始发跃迁": - level = await get_level_from_list( - total_data[i]["avg"], [10, 20, 30, 40, 50] - ) + level = await get_level_from_list(total_data[i]["avg"], [10, 20, 30, 40, 50]) elif i == "光锥跃迁": - level = await get_level_from_list( - total_data[i]["avg_up"], [62, 75, 88, 99, 111] - ) + level = await get_level_from_list(total_data[i]["avg_up"], [62, 75, 88, 99, 111]) else: - level = await get_level_from_list( - total_data[i]["avg_up"], [74, 87, 99, 105, 120] - ) + level = await get_level_from_list(total_data[i]["avg_up"], [74, 87, 99, 105, 120]) emo_pic = await random_emo_pic(level) emo_pic = emo_pic.resize((195, 195)) @@ -384,9 +355,7 @@ async def draw_gachalogs_img(uid: str, ev: Event) -> Union[bytes, str]: "mm", ) y_extend += ( - (1 + ((total_data[type_list[index - 1]]["total"] - 1) // 5)) * single_y - if index != 0 - else 0 + (1 + ((total_data[type_list[index - 1]]["total"] - 1) // 5)) * single_y if index != 0 else 0 ) y = 350 + index * 400 + y_extend img.paste(title, (0, y), title) diff --git a/StarRailUID/starrailuid_gachalog/get_gachalogs.py b/StarRailUID/starrailuid_gachalog/get_gachalogs.py index 45be4d9..683c65b 100644 --- a/StarRailUID/starrailuid_gachalog/get_gachalogs.py +++ b/StarRailUID/starrailuid_gachalog/get_gachalogs.py @@ -20,9 +20,7 @@ gacha_type_meta_data = { } -async def get_new_gachalog_by_link( - uid: str, gacha_url: str, full_data: Dict, is_force: bool -): +async def get_new_gachalog_by_link(uid: str, gacha_url: str, full_data: Dict, is_force: bool): full_data = msgspec.convert( full_data, type=Dict[str, List[SingleGachaLog]], @@ -120,9 +118,7 @@ async def save_gachalogs( # 获取新抽卡记录 if raw_data is None: - raw_data = await get_new_gachalog_by_link( - uid, gacha_url, gachalogs_history, is_force - ) + raw_data = await get_new_gachalog_by_link(uid, gacha_url, gachalogs_history, is_force) else: new_data = { "始发跃迁": [], diff --git a/StarRailUID/starrailuid_note/draw_note_card.py b/StarRailUID/starrailuid_note/draw_note_card.py index 28081e3..b0541e0 100644 --- a/StarRailUID/starrailuid_note/draw_note_card.py +++ b/StarRailUID/starrailuid_note/draw_note_card.py @@ -61,9 +61,7 @@ async def draw_note_img(sr_uid: str) -> Union[bytes, str]: return get_error(data) # 保存数据 - with Path.open( - path / f"monthly_{current_year_mon}.json", "w", encoding="utf-8" - ) as f: + with Path.open(path / f"monthly_{current_year_mon}.json", "w", encoding="utf-8") as f: save_json_data = msgjson.format(msgjson.encode(data), indent=4) save_data = json.dumps( { @@ -85,9 +83,7 @@ async def draw_note_img(sr_uid: str) -> Union[bytes, str]: if last_monthly_path.exists(): with Path.open(last_monthly_path, encoding="utf-8") as f: last_monthly_data = json.load(f) - last_monthly_data = msgjson.decode( - last_monthly_data["data"], type=MonthlyAward - ) + last_monthly_data = msgjson.decode(last_monthly_data["data"], type=MonthlyAward) else: add_month = "" if int(last_month) < 10: @@ -97,9 +93,7 @@ async def draw_note_img(sr_uid: str) -> Union[bytes, str]: if isinstance(last_monthly_data, int): return get_error(last_monthly_data) # 保存上月数据 - with Path.open( - path / f"monthly_{last_year_mon}.json", "w", encoding="utf-8" - ) as f: + with Path.open(path / f"monthly_{last_year_mon}.json", "w", encoding="utf-8") as f: save_json_data = msgjson.format(msgjson.encode(last_monthly_data), indent=4) save_data = json.dumps( { diff --git a/StarRailUID/starrailuid_note/note_text.py b/StarRailUID/starrailuid_note/note_text.py index 16f224c..b1ce11d 100644 --- a/StarRailUID/starrailuid_note/note_text.py +++ b/StarRailUID/starrailuid_note/note_text.py @@ -40,16 +40,7 @@ async def award(uid) -> str: lastmonth_rails_pass = data.month_data.last_rails_pass group_str = "" for i in data.month_data.group_by: - group_str = ( - group_str - + i.action_name - + ":" - + str(i.num) - + "(" - + str(i.percent) - + "%)" - + "\n" - ) + group_str = group_str + i.action_name + ":" + str(i.num) + "(" + str(i.percent) + "%)" + "\n" return month_im.format( uid, diff --git a/StarRailUID/starrailuid_rogue/draw_rogue_card.py b/StarRailUID/starrailuid_rogue/draw_rogue_card.py index 25ef4d7..a1c3c80 100644 --- a/StarRailUID/starrailuid_rogue/draw_rogue_card.py +++ b/StarRailUID/starrailuid_rogue/draw_rogue_card.py @@ -385,16 +385,12 @@ async def draw_rogue_img( floor_center_pic = Image.open(TEXT_PATH / "floor_bg_center.png") floor_center_pic = floor_center_pic.convert("RGBA") - floor_center_pic = floor_center_pic.resize( - (900, detail_h_list[index_floor] - 170) - ) + floor_center_pic = floor_center_pic.resize((900, detail_h_list[index_floor] - 170)) floor_pic.paste(floor_center_pic, (0, 100), floor_center_pic) floor_bot_pic = Image.open(TEXT_PATH / "floor_bg_bot.png") floor_bot_pic = floor_bot_pic.convert("RGBA") - floor_pic.paste( - floor_bot_pic, (0, detail_h_list[index_floor] - 70), floor_bot_pic - ) + floor_pic.paste(floor_bot_pic, (0, detail_h_list[index_floor] - 70), floor_bot_pic) floor_name = progresslist[detail.progress] difficulty_name = difficultylist[detail.difficulty] @@ -653,16 +649,12 @@ async def draw_rogue_locust_img( floor_center_pic = Image.open(TEXT_PATH / "floor_bg_center.png") floor_center_pic = floor_center_pic.convert("RGBA") - floor_center_pic = floor_center_pic.resize( - (900, detail_h_list[index_floor] - 170) - ) + floor_center_pic = floor_center_pic.resize((900, detail_h_list[index_floor] - 170)) floor_pic.paste(floor_center_pic, (0, 100), floor_center_pic) floor_bot_pic = Image.open(TEXT_PATH / "floor_bg_bot.png") floor_bot_pic = floor_bot_pic.convert("RGBA") - floor_pic.paste( - floor_bot_pic, (0, detail_h_list[index_floor] - 70), floor_bot_pic - ) + floor_pic.paste(floor_bot_pic, (0, detail_h_list[index_floor] - 70), floor_bot_pic) floor_name = detail.name difficulty_name = difficultylist[detail.difficulty] @@ -757,9 +749,7 @@ async def draw_rogue_locust_img( sr_font_34, "lm", ) - floor_pic.paste( - content_center, (0, 370 + miracles_height + 80), content_center - ) + floor_pic.paste(content_center, (0, 370 + miracles_height + 80), content_center) draw_height = await _draw_rogue_miracles( detail.miracles, floor_pic, @@ -778,9 +768,7 @@ async def draw_rogue_locust_img( sr_font_34, "lm", ) - floor_pic.paste( - content_center, (0, 370 + blocks_height + 80), content_center - ) + floor_pic.paste(content_center, (0, 370 + blocks_height + 80), content_center) draw_height = await _draw_rogue_blocks( detail.blocks, floor_pic, diff --git a/StarRailUID/starrailuid_roleinfo/draw_roleinfo_card.py b/StarRailUID/starrailuid_roleinfo/draw_roleinfo_card.py index 9aa86ed..142522d 100644 --- a/StarRailUID/starrailuid_roleinfo/draw_roleinfo_card.py +++ b/StarRailUID/starrailuid_roleinfo/draw_roleinfo_card.py @@ -68,9 +68,7 @@ def wrap_list(lst: List[T], n: int) -> Generator[List[T], None, None]: yield lst[i : i + n] -async def _draw_card_1( - ev: Event, sr_uid: str, role_basic_info: RoleBasicInfo, stats: Stats -) -> Image.Image: +async def _draw_card_1(ev: Event, sr_uid: str, role_basic_info: RoleBasicInfo, stats: Stats) -> Image.Image: # 名称 nickname = role_basic_info.nickname @@ -131,9 +129,7 @@ async def _draw_card_1( fill=white_color, anchor="mm", ) # 战利品开启 - bg1_draw.text( - (666, 590), str(level), font=sr_font_36, fill=white_color, anchor="mm" - ) # 开拓等级 + bg1_draw.text((666, 590), str(level), font=sr_font_36, fill=white_color, anchor="mm") # 开拓等级 # 画忘却之庭 bg1_draw.text( @@ -147,9 +143,7 @@ async def _draw_card_1( return img_bg1 -async def _draw_avatar_card( - avatar: AvatarListItem, equips: Dict[int, Optional[str]] -) -> Image.Image: +async def _draw_avatar_card(avatar: AvatarListItem, equips: Dict[int, Optional[str]]) -> Image.Image: char_bg = (char_bg_4 if avatar.rarity == 4 else char_bg_5).copy() char_draw = ImageDraw.Draw(char_bg) char_icon = (await get_roleinfo_icon(avatar.icon)).resize((110, 120)) @@ -183,9 +177,7 @@ async def _draw_avatar_card( return char_bg -async def _draw_line( - avatars: List[AvatarListItem], equips: Dict[int, Optional[str]] -) -> Image.Image: +async def _draw_line(avatars: List[AvatarListItem], equips: Dict[int, Optional[str]]) -> Image.Image: line = bg2.copy() x = 70 char_bgs: List[Image.Image] = await asyncio.gather( @@ -197,9 +189,7 @@ async def _draw_line( return line -async def _draw_card_2( - avatars: List[AvatarListItem], equips: Dict[int, Optional[str]] -) -> Image.Image: +async def _draw_card_2(avatars: List[AvatarListItem], equips: Dict[int, Optional[str]]) -> Image.Image: # 角色部分 每五个一组 lines = await asyncio.gather( *[_draw_line(five_avatars, equips) for five_avatars in wrap_list(avatars, 5)] diff --git a/StarRailUID/starrailuid_stamina/draw_stamina_card.py b/StarRailUID/starrailuid_stamina/draw_stamina_card.py index 1c578f9..c1a2c3c 100644 --- a/StarRailUID/starrailuid_stamina/draw_stamina_card.py +++ b/StarRailUID/starrailuid_stamina/draw_stamina_card.py @@ -121,9 +121,7 @@ async def get_stamina_img(bot_id: str, user_id: str): return "请先绑定一个可用CK & UID再来查询哦~" # 开始绘图任务 task = [] - img = Image.new( - "RGBA", (based_w * len(useable_uid_list), based_h), (0, 0, 0, 0) - ) + img = Image.new("RGBA", (based_w * len(useable_uid_list), based_h), (0, 0, 0, 0)) for uid_index, uid in enumerate(useable_uid_list): task.append(_draw_all_stamina_img(img, uid, uid_index)) await asyncio.gather(*task) diff --git a/StarRailUID/starrailuid_stamina/notice.py b/StarRailUID/starrailuid_stamina/notice.py index c622293..ffc764f 100644 --- a/StarRailUID/starrailuid_stamina/notice.py +++ b/StarRailUID/starrailuid_stamina/notice.py @@ -59,9 +59,7 @@ async def all_check( if push_data[f"{mode}_is_push"] == "on": if not srconfig.get_config("CrazyNotice").data: if not _check: - await SrPush.update_data_by_uid( - uid, bot_id, "sr", **{f"{mode}_is_push": "off"} - ) + await SrPush.update_data_by_uid(uid, bot_id, "sr", **{f"{mode}_is_push": "off"}) continue # 准备推送 @@ -105,9 +103,7 @@ async def all_check( else: group_data[gid][user_id] += notice - await SrPush.update_data_by_uid( - uid, bot_id, "sr", **{f"{mode}_is_push": "on"} - ) + await SrPush.update_data_by_uid(uid, bot_id, "sr", **{f"{mode}_is_push": "on"}) return msg_dict diff --git a/StarRailUID/starrailuid_stamina/stamina_text.py b/StarRailUID/starrailuid_stamina/stamina_text.py index b7ce15b..decdb8c 100644 --- a/StarRailUID/starrailuid_stamina/stamina_text.py +++ b/StarRailUID/starrailuid_stamina/stamina_text.py @@ -31,10 +31,7 @@ async def get_stamina_text(uid: str) -> str: recover_time = seconds2hours(dailydata.stamina_recover_time) next_stamina_rec_time = seconds2hours( 8 * 60 - - ( - (max_stamina - dailydata.current_stamina) * 8 * 60 - - dailydata.stamina_recover_time - ) + - ((max_stamina - dailydata.current_stamina) * 8 * 60 - dailydata.stamina_recover_time) ) rec_time = f" ({next_stamina_rec_time}/{recover_time})" diff --git a/StarRailUID/starrailuid_user/__init__.py b/StarRailUID/starrailuid_user/__init__.py index 8a2178c..df62f69 100644 --- a/StarRailUID/starrailuid_user/__init__.py +++ b/StarRailUID/starrailuid_user/__init__.py @@ -44,9 +44,7 @@ async def send_link_uid_msg(bot: Bot, ev: Event): return await bot.send("你输入了错误的格式!") if "绑定" in ev.command: - data = await GsBind.insert_uid( - qid, ev.bot_id, sr_uid, ev.group_id, 9, game_name="sr" - ) + data = await GsBind.insert_uid(qid, ev.bot_id, sr_uid, ev.group_id, 9, game_name="sr") return await send_diff_msg( bot, data, diff --git a/StarRailUID/utils/error_reply.py b/StarRailUID/utils/error_reply.py index 8f6dbef..be424f6 100644 --- a/StarRailUID/utils/error_reply.py +++ b/StarRailUID/utils/error_reply.py @@ -7,9 +7,7 @@ prefix = get_plugin_available_prefix("StarRailUID") UID_HINT = f"你还没有绑定过uid哦!\n请使用[{prefix}绑定uid123456]命令绑定!" _CHAR_HINT = f"再使用【{prefix}强制刷新】命令来缓存数据进行查询! !" -CHAR_HINT = ( - "您的支援/星海同行角色没有{}的数据哦!\n请先把{}放入支援/星海同行中" + _CHAR_HINT -) +CHAR_HINT = "您的支援/星海同行角色没有{}的数据哦!\n请先把{}放入支援/星海同行中" + _CHAR_HINT SR_ERROR_CODE = deepcopy(ERROR_CODE) diff --git a/StarRailUID/utils/image/image_tools.py b/StarRailUID/utils/image/image_tools.py index 788d8fb..7903daf 100644 --- a/StarRailUID/utils/image/image_tools.py +++ b/StarRailUID/utils/image/image_tools.py @@ -15,15 +15,9 @@ NATURE_ICON_PATH = Path(__file__).parent / "icon_nature" elements = { "ice": Image.open(NATURE_ICON_PATH / "IconNatureColorIce.png").convert("RGBA"), "fire": Image.open(NATURE_ICON_PATH / "IconNatureColorFire.png").convert("RGBA"), - "imaginary": Image.open(NATURE_ICON_PATH / "IconNatureColorImaginary.png").convert( - "RGBA" - ), - "quantum": Image.open(NATURE_ICON_PATH / "IconNatureColorQuantum.png").convert( - "RGBA" - ), - "lightning": Image.open(NATURE_ICON_PATH / "IconNatureColorThunder.png").convert( - "RGBA" - ), + "imaginary": Image.open(NATURE_ICON_PATH / "IconNatureColorImaginary.png").convert("RGBA"), + "quantum": Image.open(NATURE_ICON_PATH / "IconNatureColorQuantum.png").convert("RGBA"), + "lightning": Image.open(NATURE_ICON_PATH / "IconNatureColorThunder.png").convert("RGBA"), "wind": Image.open(NATURE_ICON_PATH / "IconNatureColorWind.png").convert("RGBA"), "physical": Image.open(NATURE_ICON_PATH / "IconNaturePhysical.png").convert("RGBA"), } diff --git a/StarRailUID/utils/mys_api.py b/StarRailUID/utils/mys_api.py index 48f4bd7..a3c67a3 100644 --- a/StarRailUID/utils/mys_api.py +++ b/StarRailUID/utils/mys_api.py @@ -46,9 +46,7 @@ class MysApi(_MysApi): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - async def get_sr_ck( - self, uid: str, mode: Literal["OWNER", "RANDOM"] = "RANDOM" - ) -> Optional[str]: + async def get_sr_ck(self, uid: str, mode: Literal["OWNER", "RANDOM"] = "RANDOM") -> Optional[str]: return await self.get_ck(uid, mode, "sr") async def simple_sr_req( @@ -87,15 +85,11 @@ class MysApi(_MysApi): header=header, ) else: - data = await self.simple_sr_req( - "STAR_RAIL_NOTE_URL", uid, header=self._HEADER - ) + data = await self.simple_sr_req("STAR_RAIL_NOTE_URL", uid, header=self._HEADER) if isinstance(data, Dict): # workaround for mistake params in hoyolab if data["data"]["accepted_epedition_num"]: - data["data"]["accepted_expedition_num"] = data["data"][ - "accepted_epedition_num" - ] + data["data"]["accepted_expedition_num"] = data["data"]["accepted_epedition_num"] data = msgspec.convert(data["data"], type=DailyNoteData) return data @@ -147,9 +141,7 @@ class MysApi(_MysApi): header=header, ) else: - data = await self.simple_sr_req( - "STAR_RAIL_INDEX_URL", uid, header=self._HEADER - ) + data = await self.simple_sr_req("STAR_RAIL_INDEX_URL", uid, header=self._HEADER) if isinstance(data, Dict): data = msgspec.convert(data["data"], type=RoleIndex) return data @@ -496,9 +488,7 @@ class MysApi(_MysApi): data = msgspec.convert(data["data"], type=RogueLocustData) return data - async def sr_mys_sign( - self, uid, header=None, server_id="cn_gf01" - ) -> Union[MysSign, int]: + async def sr_mys_sign(self, uid, header=None, server_id="cn_gf01") -> Union[MysSign, int]: if header is None: header = {} ck = await self.get_sr_ck(uid, "OWNER") @@ -576,9 +566,7 @@ class MysApi(_MysApi): self, sr_uid: str, ) -> Union[RoleBasicInfo, int]: - data = await self.simple_sr_req( - "STAR_RAIL_ROLE_BASIC_INFO_URL", sr_uid, header=self._HEADER - ) + data = await self.simple_sr_req("STAR_RAIL_ROLE_BASIC_INFO_URL", sr_uid, header=self._HEADER) if isinstance(data, Dict): data = msgspec.convert(data["data"], type=RoleBasicInfo) return data diff --git a/pyproject.toml b/pyproject.toml index c57b1e2..1481e39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,44 +1,5 @@ -[tool.isort] -profile = "black" -line_length = 79 -length_sort = true -skip_gitignore = true -force_sort_within_sections = true -extra_standard_library = ["typing_extensions"] - -[tool.pytest.ini_options] -asyncio_mode = "auto" - -[tool.poetry] -name = "StarRailUID" -version = "0.1.0" -description = "" -authors = ["qwerdvd <2450899274@qq.com>"] -license = "GPL-3.0-or-later" -readme = "README.md" - -[tool.poetry.dependencies] -python = "^3.8.1" - -[[tool.poetry.source]] -name = "USTC" -url = "https://pypi.mirrors.ustc.edu.cn/simple" -default = false -secondary = true - -[tool.poetry.group.dev.dependencies] -flake8 = "^6.0.0" -isort = "^5.12.0" -pre-commit = "^2.21.0" -pycln = "^2.1.2" - -[tool.poetry.group.test.dependencies] -nonebug = "^0.3.0" -pytest = "^7.2.0" -pytest-asyncio = "^0.20.3" - [tool.ruff] -line-length = 88 +line-length = 108 target-version = "py38" [tool.ruff.lint] @@ -94,11 +55,6 @@ combine-as-imports = true order-by-type = true relative-imports-order = "closest-to-furthest" - -[tool.pdm] -[tool.pdm.build] -includes = [] - [[tool.pdm.source]] name = "USTC" url = "https://pypi.mirrors.ustc.edu.cn/simple"