Skip to content

Commit

Permalink
Update get_genshin_characters method
Browse files Browse the repository at this point in the history
  • Loading branch information
seriaati committed Nov 1, 2024
1 parent 7eeb800 commit 3164e1d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 32 deletions.
8 changes: 0 additions & 8 deletions genshin/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,6 @@ async def genshin_characters(client: genshin.Client, uid: int) -> None:
f"lvl {char.weapon.level} R{char.weapon.refinement}"
)

if char.artifacts:
click.echo("Artifacts:")
for arti in char.artifacts:
click.echo(f" - {arti.pos_name}: {arti.set.name} ({'★' * arti.rarity})")

if char.outfits:
click.echo(f"Outfits: {', '.join(o.name for o in char.outfits)}")


@genshin_group.command("notes")
@click.argument("uid", type=int, default=None, required=False)
Expand Down
4 changes: 2 additions & 2 deletions genshin/client/components/chronicle/genshin.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ async def get_genshin_characters(
lang: typing.Optional[str] = None,
) -> typing.Sequence[models.Character]:
"""Get genshin user characters."""
data = await self._request_genshin_record("character", uid, lang=lang, method="POST")
return [models.Character(**i) for i in data["avatars"]]
data = await self._request_genshin_record("character/list", uid, lang=lang, method="POST")
return [models.Character(**i) for i in data["list"]]

@typing.overload
async def get_genshin_detailed_characters(
Expand Down
23 changes: 1 addition & 22 deletions genshin/models/genshin/chronicle/characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import enum
import typing
from collections import defaultdict

import pydantic

Expand Down Expand Up @@ -56,10 +55,8 @@ class CharacterWeapon(APIModel, Unique):
icon: str
name: str
rarity: int
description: str = Aliased("desc")
level: int
type: str = Aliased("type_name")
ascension: int = Aliased("promote_level")
type: int
refinement: int = Aliased("affix_level")


Expand Down Expand Up @@ -120,24 +117,6 @@ class Character(PartialCharacter):
"""Character with equipment."""

weapon: CharacterWeapon
artifacts: typing.Sequence[Artifact] = Aliased("reliquaries")
constellations: typing.Sequence[Constellation]
outfits: typing.Sequence[Outfit] = Aliased("costumes")

@pydantic.field_validator("artifacts")
@classmethod
def __enable_artifact_set_effects(cls, artifacts: typing.Sequence[Artifact]) -> typing.Sequence[Artifact]:
set_nums: defaultdict[int, int] = defaultdict(int)
for arti in artifacts:
set_nums[arti.set.id] += 1

for artifact in artifacts:
for effect in artifact.set.effects:
if effect.required_piece_num <= set_nums[artifact.set.id]:
# To bypass model's immutability
effect = effect.model_copy(update={"active": True})

return artifacts


class PropInfo(APIModel):
Expand Down

0 comments on commit 3164e1d

Please sign in to comment.