From 237f82f6724a35985d22667546bdc525ace2bfc3 Mon Sep 17 00:00:00 2001 From: omg-xtao <100690902+omg-xtao@users.noreply.github.com> Date: Mon, 25 Mar 2024 23:33:38 +0800 Subject: [PATCH] :art: Add tags to player_card caption --- plugins/genshin/player_cards.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/plugins/genshin/player_cards.py b/plugins/genshin/player_cards.py index b567aae1..84054736 100644 --- a/plugins/genshin/player_cards.py +++ b/plugins/genshin/player_cards.py @@ -158,6 +158,35 @@ class PlayerCards(Plugin): uid = player_info.player_id return uid, ch_name + @staticmethod + def get_caption_stats(character: "CharacterInfo") -> List[str]: + tags = [] + stats = character.stats + + def num(_s) -> int: + return int(round(_s, 0)) + + tags.append(f"生命{num(stats.FIGHT_PROP_MAX_HP.to_rounded())}") + tags.append(f"攻击{num(stats.FIGHT_PROP_CUR_ATTACK.to_rounded())}") + tags.append(f"防御{num(stats.FIGHT_PROP_CUR_DEFENSE.to_rounded())}") + tags.append(f"暴击{num(stats.FIGHT_PROP_CRITICAL.to_percentage())}") + tags.append(f"暴伤{num(stats.FIGHT_PROP_CRITICAL_HURT.to_percentage())}") + tags.append(f"充能{num(stats.FIGHT_PROP_CHARGE_EFFICIENCY.to_percentage())}") + tags.append(f"精通{num(stats.FIGHT_PROP_ELEMENT_MASTERY.to_rounded())}") + return tags + + @staticmethod + def get_caption(character: "CharacterInfo") -> str: + tags = [character.name, f"等级{character.level}", f"命座{character.constellations_unlocked}"] + if character.equipments: + for item in character.equipments: + if item.type == EquipmentsType.WEAPON and item.detail: + tags.append(item.detail.name) + tags.append(f"武器等级{item.level}") + tags.append(f"精{item.refinement}") + tags.extend(PlayerCards.get_caption_stats(character)) + return "#" + " #".join(tags) + @handler.command(command="player_card", player=True, block=False) @handler.command(command="player_cards", player=True, block=False) @handler.message(filters=filters.Regex("^角色卡片查询(.*)"), player=True, block=False) @@ -249,6 +278,7 @@ class PlayerCards(Plugin): await render_result.reply_photo( message, filename=f"player_card_{uid}_{character_name}.png", + caption=self.get_caption(characters), ) @handler.callback_query(pattern=r"^update_player_card\|", block=False) @@ -376,6 +406,7 @@ class PlayerCards(Plugin): uid, characters, self.fight_prop_rule, self.damage_config, self.template_service, original_data ).render() # pylint: disable=W0631 render_result.filename = f"player_card_{uid}_{result}.png" + render_result.caption = self.get_caption(characters) await render_result.edit_media(message) @staticmethod