Skip to content

Commit

Permalink
refactor: Add add_description method to Embed
Browse files Browse the repository at this point in the history
  • Loading branch information
seriaati committed Oct 23, 2024
1 parent 68dadb0 commit 5e3a232
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 1 addition & 3 deletions hoyo_buddy/bot/error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,8 @@ def get_error_embed(error: Exception, locale: discord.Locale, translator: Transl
game_strs = [
f"- {get_game_emoji(game)} {EnumStr(game).translate(translator, locale)}" for game in error.games
]
if embed.description is None:
embed.description = ""
joined_str = "\n".join(game_strs)
embed.description += f"\n{joined_str}"
embed.add_description(joined_str)
elif isinstance(error, genshin_errors.GenshinException | enka_errors.EnkaAPIError):
err_info = None

Expand Down
8 changes: 8 additions & 0 deletions hoyo_buddy/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ def copy(self) -> Self:
copy.translator = self.translator
return copy

def add_description(self, description: LocaleStr | str) -> Self:
translated_description = self.translator.translate(description, self.locale)
if self.description is None:
self.description = translated_description
else:
self.description += f"\n{translated_description}"
return self


class DefaultEmbed(Embed):
def __init__(
Expand Down
3 changes: 1 addition & 2 deletions hoyo_buddy/hoyo/clients/ambr.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ def get_weapon_embed(
)

if sub_stat_name and sub_stat_value:
assert embed.description is not None
embed.description += f"\n{sub_stat_name}: {sub_stat_value}"
embed.add_description(f"{sub_stat_name}: {sub_stat_value}")

if weapon.affix:
embed.add_field(
Expand Down
3 changes: 1 addition & 2 deletions hoyo_buddy/hoyo/clients/hakushin.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,9 @@ def get_bangboo_embed(self, bangboo: hakushin.zzz.BangbooDetail) -> DefaultEmbed

def get_engine_embed(self, engine: hakushin.zzz.WeaponDetail, refinement: str) -> DefaultEmbed:
embed = DefaultEmbed(self._locale, self._translator, title=engine.name)
embed.description = ""
if engine.rarity is not None:
embed.description = "★" * STAR_NUMS[engine.rarity]
embed.description += f"\n{engine.description}\n\n{engine.description2}"
embed.add_description(f"{engine.description}\n\n{engine.description2}")

effect = engine.refinements[refinement]
embed.add_field(name=f"{effect.name} ({refinement})", value=effect.description)
Expand Down

0 comments on commit 5e3a232

Please sign in to comment.