1"""Characters as Battle.net publishes them: the SideQuest roster, plus anyone looked up by name.
2
3Forever has no realms: a character's address is its lowercase ``name-surname`` slug. Battle.net publishes a profile
4only some time after the character logs out, so a roster member can have no profile yet (``profile_found`` false):
5its row then carries only what the roster says (level, class, race, rank).
6"""
7
8from datetime import datetime # SQLAlchemy resolves Mapped[] annotations at runtime
9from typing import Any
10
11from advanced_alchemy.base import UUIDAuditBase
12from advanced_alchemy.types import DateTimeUTC, JsonB
13from sqlalchemy import BigInteger, Boolean, Integer, Text, UniqueConstraint
14from sqlalchemy.orm import Mapped, mapped_column
15
16
[docs]
17class BattlenetCharacter(UUIDAuditBase):
18 """One character's Battle.net summary, and its character sheet as last fetched.
19
20 ``in_roster`` marks a current member of the SideQuest guild, from the last roster sync; ``guild_rank`` is its
21 roster rank (0 is the Guild Master). The summary columns (item level, honorable kills, PvP rank, achievement
22 points, spec) feed the Hall of Heroes boards and raid readiness without opening ``sheet``, the full character
23 page as ``CharacterSheet`` built it.
24 """
25
26 __tablename__ = "battlenet_character"
27 __table_args__ = {"comment": "Battle.net character profiles: the guild roster and characters looked up by name."}
28
29 slug: Mapped[str] = mapped_column(Text, unique=True, index=True)
30 blizzard_id: Mapped[int] = mapped_column(BigInteger, index=True)
31 name: Mapped[str] = mapped_column(Text)
32 surname: Mapped[str] = mapped_column(Text)
33 level: Mapped[int] = mapped_column(Integer)
34 wow_class: Mapped[str | None] = mapped_column(Text, default=None)
35 race: Mapped[str | None] = mapped_column(Text, default=None)
36 faction: Mapped[str | None] = mapped_column(Text, default=None)
37 guild_name: Mapped[str | None] = mapped_column(Text, default=None)
38 guild_slug: Mapped[str | None] = mapped_column(Text, default=None)
39 in_roster: Mapped[bool] = mapped_column(Boolean, default=False, index=True)
40 guild_rank: Mapped[int | None] = mapped_column(Integer, default=None)
41 joined_roster_at: Mapped[datetime | None] = mapped_column(DateTimeUTC(timezone=True), default=None)
42 left_roster_at: Mapped[datetime | None] = mapped_column(DateTimeUTC(timezone=True), default=None)
43 profile_found: Mapped[bool] = mapped_column(Boolean, default=False)
44 item_level: Mapped[int | None] = mapped_column(Integer, default=None)
45 achievement_points: Mapped[int | None] = mapped_column(Integer, default=None)
46 honorable_kills: Mapped[int | None] = mapped_column(Integer, default=None)
47 pvp_rank: Mapped[int | None] = mapped_column(Integer, default=None)
48 spec: Mapped[str | None] = mapped_column(Text, default=None)
49 last_login_at: Mapped[datetime | None] = mapped_column(DateTimeUTC(timezone=True), default=None)
50 sheet: Mapped[dict[str, Any] | None] = mapped_column(JsonB, default=None)
51 fetched_at: Mapped[datetime | None] = mapped_column(DateTimeUTC(timezone=True), index=True, default=None)
52 """When the profile was last asked for, found or not. ``None`` until the first try."""
53
54
[docs]
55class CharacterMilestone(UUIDAuditBase):
56 """A roster character reaching a milestone level (40 or 60), queued for the bot to post to Discord.
57
58 Written once per character and level, when a sync or a profile refresh first sees the character at or above the
59 level after having stored it below. ``posted_at`` is set when the bot has posted it.
60 """
61
62 __tablename__ = "character_milestone"
63 __table_args__ = (
64 UniqueConstraint("slug", "level", name="uq_character_milestone_slug_level"),
65 {"comment": "Roster characters reaching levels 40 and 60, queued for the Discord feed."},
66 )
67
68 slug: Mapped[str] = mapped_column(Text, index=True)
69 name: Mapped[str] = mapped_column(Text)
70 surname: Mapped[str] = mapped_column(Text)
71 wow_class: Mapped[str | None] = mapped_column(Text, default=None)
72 level: Mapped[int] = mapped_column(Integer)
73 reached_at: Mapped[datetime] = mapped_column(DateTimeUTC(timezone=True), index=True)
74 posted_at: Mapped[datetime | None] = mapped_column(DateTimeUTC(timezone=True), index=True, default=None)
75 discord_message_id: Mapped[int | None] = mapped_column(BigInteger, default=None)