Source code for sidequest_common.schemas.epgp

  1"""EPGP loot system schemas.
  2
  3Rules constants, the addon export/import wire shapes, and the HTTP API's request/response schemas
  4(``local://addon-contract.md`` is the source of truth; field names and string prefixes here are binding).
  5"""
  6
  7from datetime import datetime  # pydantic needs it at runtime
  8from enum import StrEnum
  9from typing import Literal
 10from uuid import UUID  # pydantic needs it at runtime
 11
 12from pydantic import BaseModel, ConfigDict, Field, field_validator
 13
 14from sidequest_common.schemas.directory import (
 15    MAX_DIRECTORY_ENTRIES,
 16    MAX_ITEM_NAMES,
 17    MAX_RECIPE_NAMES,
 18    DirectoryImportCounts,
 19    ExportDirectoryEntry,
 20)
 21from sidequest_common.schemas.events import EventKind, SignupRole, SignupStatus, WowClass
 22from sidequest_common.schemas.guild_hub import (
 23    MAX_ANNOUNCEMENTS_V2,
 24    MAX_BANK_ENTRIES,
 25    MAX_MEMBER_NOTES_V2,
 26    MAX_PROFESSION_PAIRS,
 27    MAX_RECRUITS_V2,
 28    MAX_SIGNUPS_V2,
 29    AnnouncementImportCounts,
 30    BankImportCounts,
 31    ExportAnnouncement,
 32    ExportBankEntry,
 33    ExportMemberNote,
 34    ExportProfession,
 35    ExportRecruit,
 36    ExportRoster,
 37    ExportSignupV2,
 38    GameImportCrafter,
 39    GameImportMember,
 40    GameImportNews,
 41    GameImportOfficerPart,
 42    GameImportSheet,
 43    MemberNoteImportCounts,
 44    ProfessionImportCounts,
 45    RecruitImportCounts,
 46    RosterImportCounts,
 47    SignupImportCounts,
 48)
 49from sidequest_common.schemas.pvp import MAX_BATTLEGROUNDS, BattlegroundImportCounts, ExportBattleground
 50from sidequest_common.schemas.recruitment import (
 51    MAX_GUILD_LOG_ENTRIES,
 52    MAX_RECRUIT_PAYOUTS_PAID,
 53    ExportGuildLogEntry,
 54    ExportRecruitPayoutPaid,
 55    GameImportDrive,
 56    GuildLogImportCounts,
 57    RecruitPayoutImportCounts,
 58)
 59
 60# --- Rules constants (the site owns these numbers; they ship in the SQI1 import string's ``rules`` object) -------
 61
 62EP_VALUES: dict[str, int] = {"boss_kill": 10, "progress": 10, "on_time": 5, "full_night": 5}
 63"""EP awarded per ``AwardReason``. ``standby`` earns the same as the raid (``on_time``/``full_night``/boss kills)."""
 64
 65GP_BY_INVTYPE: dict[str, int] = {
 66    "INVTYPE_HEAD": 100,
 67    "INVTYPE_CHEST": 100,
 68    "INVTYPE_ROBE": 100,
 69    "INVTYPE_LEGS": 100,
 70    "INVTYPE_SHOULDER": 75,
 71    "INVTYPE_HAND": 75,
 72    "INVTYPE_WAIST": 75,
 73    "INVTYPE_FEET": 75,
 74    "INVTYPE_NECK": 55,
 75    "INVTYPE_WRIST": 55,
 76    "INVTYPE_CLOAK": 55,
 77    "INVTYPE_FINGER": 55,
 78    "INVTYPE_HOLDABLE": 55,
 79    "INVTYPE_SHIELD": 55,
 80    "INVTYPE_TRINKET": 125,
 81    "INVTYPE_WEAPON": 150,
 82    "INVTYPE_WEAPONMAINHAND": 150,
 83    "INVTYPE_WEAPONOFFHAND": 150,
 84    "INVTYPE_2HWEAPON": 200,
 85    "INVTYPE_RANGED": 50,
 86    "INVTYPE_RANGEDRIGHT": 50,
 87    "INVTYPE_THROWN": 50,
 88    "INVTYPE_RELIC": 50,
 89}
 90"""GP by ``INVTYPE_*`` at main-spec cost. A 1H "main caster weapon" uses the 2H cost (200) by officer toggle; tier
 91tokens use the cost of the slot the officer picks; chase items are ``slot cost * CHASE_MULTIPLIER``; legendary
 92pieces and other special or rare items are flat ``LEGENDARY_GP``. None of those three cases key off ``inv_type``
 93alone, so they aren't in this map.
 94"""
 95
 96CHASE_MULTIPLIER = 1.5
 97LEGENDARY_GP = 300
 98OS_PERCENT = 10
 99"""Off-spec pays this percent of main-spec GP, rounded half up. Alt fill and disenchant/bank pay 0."""
100BASE_GP = 100
101MIN_GP = 100
102DECAY_PERCENT = 15
103"""Weekly decay applied to EP and GP at every reset, read-time only (``amount * (1 - DECAY_PERCENT/100) ** resets``)."""
104TRIAL_DAYS = 14
105WEEKLY_RESET_WEEKDAY = 1
106"""``datetime.weekday()`` value for Tuesday."""
107WEEKLY_RESET_HOUR_UTC = 15
108
109DEFAULT_REALM = "Whitemane"
110"""The guild's single WoW: Forever realm, used when a member claims a character without specifying one."""
111AWARD_AMOUNT_MIN = -1000
112AWARD_AMOUNT_MAX = 1000
113MAX_NAME_LENGTH = 64
114MAX_NOTE_LENGTH = 200
115MAX_IMPORT_BYTES = 2 * 1024 * 1024
116MAX_SESSIONS = 50
117MAX_ENCOUNTERS = 500
118MAX_LOOT = 1000
119MAX_AWARDS = 20000
120
121EPGP_RULES: dict[str, object] = {
122    "ep": dict(EP_VALUES),
123    "gp": dict(GP_BY_INVTYPE),
124    "chase_multiplier": CHASE_MULTIPLIER,
125    "legendary_gp": LEGENDARY_GP,
126    "os_percent": OS_PERCENT,
127    "base_gp": BASE_GP,
128    "min_gp": MIN_GP,
129    "decay_percent": DECAY_PERCENT,
130    "trial_days": TRIAL_DAYS,
131    "weekly_reset_weekday": WEEKLY_RESET_WEEKDAY,
132    "weekly_reset_hour_utc": WEEKLY_RESET_HOUR_UTC,
133}
134"""Exact shape of the ``rules`` object in the ``SQI1:`` import string."""
135
136
137# --- Enums ----------------------------------------------------------------------------------------------------
138
139
[docs] 140class LootResponse(StrEnum): 141 """How a character rolled on an item.""" 142 143 MS = "ms" 144 OS = "os" 145 ALT = "alt" 146 COUNCIL = "council" 147 DE = "de" 148 BANK = "bank"
149 150
[docs] 151class AwardReason(StrEnum): 152 """Why an EP/GP ledger entry was written.""" 153 154 BOSS_KILL = "boss_kill" 155 PROGRESS = "progress" 156 ON_TIME = "on_time" 157 FULL_NIGHT = "full_night" 158 STANDBY = "standby" 159 LOOT = "loot" 160 ADJUST = "adjust"
161 162
[docs] 163class LedgerKind(StrEnum): 164 """Whether a ledger entry is an EP or GP change.""" 165 166 EP = "ep" 167 GP = "gp"
168 169
[docs] 170class LedgerSource(StrEnum): 171 """Where a ledger entry came from: the addon export, or a site-made officer adjustment.""" 172 173 ADDON = "addon" 174 SITE = "site"
175 176
[docs] 177class CharacterSource(StrEnum): 178 """How a ``WowCharacter`` got linked to a member.""" 179 180 CLAIM = "claim" 181 OFFICER = "officer" 182 SIGNUP = "signup" 183 IMPORT = "import" 184 BATTLENET = "battlenet" 185 """Auto-linked because the site proved the member's linked Battle.net account owns this character."""
186 187
[docs] 188class RaidStatus(StrEnum): 189 """EPGP roster status, settable by an officer (``PUT /api/epgp/roster/{member_id}``).""" 190 191 TRIAL = "trial" 192 RAIDER = "raider"
193 194
[docs] 195class CouncilKind(StrEnum): 196 """Why a council-awarded item qualified: chase (one per boss), legendary/special/rare, or crafted tier.""" 197 198 CHASE = "chase" 199 LEGENDARY = "legendary" 200 TIER = "tier"
201 202
[docs] 203class CouncilLogKind(StrEnum): 204 """Whether a ``#loot-log`` entry is the council decision itself, or a later void of an already-posted one.""" 205 206 DECISION = "decision" 207 VOID = "void"
208 209 210# --- Addon export (``SQX1:`` + base64 JSON): the inbound payload the import service validates --------------------- 211 212
[docs] 213class ExportSessionMember(BaseModel): 214 """One session member entry in the export payload. 215 216 ``class`` arrives as the addon's uppercase token (e.g. ``"MAGE"``, Blizzard's ``UnitClass`` return), 217 normalized to lowercase before validation. 218 """ 219 220 model_config = ConfigDict(populate_by_name=True) 221 222 character: str = Field(max_length=MAX_NAME_LENGTH) 223 wow_class: WowClass | None = Field(default=None, alias="class") 224 first_seen: int 225 last_seen: int 226 standby: bool = False 227 228 @field_validator("wow_class", mode="before") 229 @classmethod 230 def _normalize_class(cls, value: object) -> object: 231 return value.lower() if isinstance(value, str) else value
232 233
[docs] 234class ExportSession(BaseModel): 235 """One raid session entry in the export payload. 236 237 Lua json encoders drop nil keys rather than emitting null, so every nullable contract field here is a pydantic 238 default, not a required key: the addon may omit ``event_id``/``ended_at`` entirely (e.g. a session exported 239 before the raid ended) rather than sending them as JSON ``null``. 240 """ 241 242 id: str = Field(max_length=120) 243 event_id: UUID | None = None 244 instance_name: str = Field(max_length=120) 245 instance_id: int 246 difficulty_id: int 247 size: int 248 started_at: int 249 ended_at: int | None = None 250 members: list[ExportSessionMember] = Field(default_factory=list)
251 252
[docs] 253class ExportEncounter(BaseModel): 254 """One boss pull entry in the export payload. ``session_id``/``ended_at`` may be absent (see ``ExportSession``).""" 255 256 id: str = Field(max_length=120) 257 session_id: str | None = None 258 encounter_id: int 259 name: str = Field(max_length=120) 260 size: int 261 difficulty_id: int 262 success: bool 263 started_at: int 264 ended_at: int | None = None 265 characters: list[str] = Field(default_factory=list) 266 standby: list[str] = Field(default_factory=list)
267 268
[docs] 269class ExportLoot(BaseModel): 270 """One loot award entry in the export payload.""" 271 272 id: str = Field(max_length=120) 273 session_id: str | None = None 274 encounter_row_id: str | None = None 275 item_id: int 276 item_name: str = Field(max_length=120) 277 quality: int 278 inv_type: str = Field(max_length=30) 279 character: str = Field(max_length=MAX_NAME_LENGTH) 280 response: LootResponse 281 gp: int = Field(ge=AWARD_AMOUNT_MIN, le=AWARD_AMOUNT_MAX, description="Gear points (GP) this item cost.") 282 at: int 283 officer: str = Field(max_length=MAX_NAME_LENGTH) 284 voided: bool = False 285 council_reason: str | None = Field(default=None, max_length=MAX_NOTE_LENGTH) 286 council_kind: CouncilKind | None = None
287 288
[docs] 289class ExportAward(BaseModel): 290 """One EP/GP ledger entry in the export payload.""" 291 292 id: str = Field(max_length=120) 293 session_id: str | None = None 294 kind: LedgerKind 295 character: str = Field(max_length=MAX_NAME_LENGTH) 296 amount: int = Field(ge=AWARD_AMOUNT_MIN, le=AWARD_AMOUNT_MAX, description="EP or GP change, as set by kind.") 297 reason: AwardReason 298 note: str | None = Field(default=None, max_length=MAX_NOTE_LENGTH) 299 loot_id: str | None = None 300 at: int 301 officer: str = Field(max_length=MAX_NAME_LENGTH) 302 voided: bool = False
303 304
[docs] 305class ExportPayload(BaseModel): 306 """The full decoded ``SQX1:`` payload, bounded per the contract. 307 308 ``v: 2`` adds the guild-hub sections below; every v2 section is optional so a ``v: 1`` addon keeps working 309 unchanged. ``directory``/``item_names``/``recipe_names`` are additive on top of ``v: 2`` (see 310 ``sidequest_common.schemas.directory``): older sites ignore them, so the version number doesn't change. 311 """ 312 313 v: int 314 addon_version: str 315 exported_at: int 316 guild: str 317 realm: str 318 recorder: str = Field(max_length=MAX_NAME_LENGTH) 319 sessions: list[ExportSession] = Field(default_factory=list, max_length=MAX_SESSIONS) 320 encounters: list[ExportEncounter] = Field(default_factory=list, max_length=MAX_ENCOUNTERS) 321 loot: list[ExportLoot] = Field(default_factory=list, max_length=MAX_LOOT) 322 awards: list[ExportAward] = Field(default_factory=list, max_length=MAX_AWARDS) 323 roster: ExportRoster | None = None 324 professions: list[ExportProfession] = Field(default_factory=list, max_length=MAX_PROFESSION_PAIRS) 325 signups: list[ExportSignupV2] = Field(default_factory=list, max_length=MAX_SIGNUPS_V2) 326 bank: list[ExportBankEntry] = Field(default_factory=list, max_length=MAX_BANK_ENTRIES) 327 announcements: list[ExportAnnouncement] = Field(default_factory=list, max_length=MAX_ANNOUNCEMENTS_V2) 328 recruits: list[ExportRecruit] = Field(default_factory=list, max_length=MAX_RECRUITS_V2) 329 member_notes: list[ExportMemberNote] = Field(default_factory=list, max_length=MAX_MEMBER_NOTES_V2) 330 directory: list[ExportDirectoryEntry] = Field(default_factory=list, max_length=MAX_DIRECTORY_ENTRIES) 331 item_names: dict[str, str] = Field(default_factory=dict, max_length=MAX_ITEM_NAMES) 332 recipe_names: dict[str, str] = Field(default_factory=dict, max_length=MAX_RECIPE_NAMES) 333 battlegrounds: list[ExportBattleground] = Field(default_factory=list, max_length=MAX_BATTLEGROUNDS) 334 """Finished battlegrounds' scoreboards (``sidequest_common.schemas.pvp``); additive, older sites ignore it.""" 335 guild_log: list[ExportGuildLogEntry] = Field(default_factory=list, max_length=MAX_GUILD_LOG_ENTRIES) 336 """Guild event log rows (``sidequest_common.schemas.recruitment``); additive, older sites ignore it.""" 337 recruit_payouts_paid: list[ExportRecruitPayoutPaid] = Field( 338 default_factory=list, max_length=MAX_RECRUIT_PAYOUTS_PAID 339 ) 340 """Recruitment drive payouts the addon's mail-send button already sent; additive, older sites ignore it."""
341 342 343# --- Site import (``SQI1:`` + base64 JSON): the outbound payload the game-import endpoint builds ------------------ 344 345
[docs] 346class GameImportSignup(BaseModel): 347 """One event sign-up in the game-import payload. ``character`` is the free-text sign-up name, no realm. 348 349 ``wow_class``/``role`` are ``None`` for sign-ups to non-``ROLE_KINDS`` events (social, transmog, leveling, 350 pvp, other); those events accept a bare going/maybe/can't RSVP, same as the site's own sign-up API. 351 """ 352 353 model_config = ConfigDict(populate_by_name=True, serialize_by_alias=True) 354 355 character: str 356 wow_class: WowClass | None = Field(default=None, alias="class") 357 role: SignupRole | None = None 358 status: SignupStatus 359 group: int | None 360 bench: bool
361 362
[docs] 363class GameImportEvent(BaseModel): 364 """One scheduled event in the game-import payload (upcoming in ``events``, recent in ``past_events``). 365 366 ``ends_at`` is additive (older addons ignore it); it is always set for a recruitment drive. ``recruitment`` is 367 set only for a recruitment-kind drive in ``events`` (upcoming and running), never in ``past_events``. 368 """ 369 370 id: UUID 371 title: str 372 kind: EventKind 373 starts_at: int 374 ends_at: int | None = None 375 size: int | None 376 signups: list[GameImportSignup] 377 recruitment: GameImportDrive | None = None
378 379
[docs] 380class GameImportPrice(BaseModel): 381 """One item's auction price in the game-import payload's ``prices`` section (SQI1, additive). 382 383 The lowest unit price across the guild's faction auction houses, for items the guild trades: directory 384 market sell/buy/request items, wishlist items, guild bank log items, and recipes' crafted items the site 385 already knows the item ID for. 386 """ 387 388 item_id: int 389 unit_price: int 390 quantity: int 391 at: int = Field(description="When this price was synced, Unix seconds.") 392 wanted: int = Field(default=0, description="Distinct guild members with this item on their wishlist.")
393 394
[docs] 395class GameImportStandingsRow(BaseModel): 396 """One standings row in the game-import payload.""" 397 398 model_config = ConfigDict(populate_by_name=True, serialize_by_alias=True) 399 400 member_id: int | None 401 name: str 402 main: str | None 403 wow_class: WowClass | None = Field(alias="class") 404 characters: list[str] 405 ep: float = Field(description="Effort points (EP, shown as Renown on the site).") 406 gp: float = Field(description="Gear points (GP).") 407 pr: float = Field(description="Priority: EP divided by GP.") 408 trial: bool
409 410
[docs] 411class GameImportPayload(BaseModel): 412 """The full ``SQI1:`` payload built by ``GET /api/epgp/game-import``. 413 414 ``members``/``news`` are the public part (the addon may broadcast them); ``sheets``/``crafters``/ 415 ``recipe_names`` are on-demand (an officer's addon answers members' requests, never broadcasts the whole 416 thing); ``officer`` stays on officers' addons only. All four v2 additions are always present since the 417 endpoint already requires an officer. 418 """ 419 420 v: int 421 generated_at: int 422 rules: dict 423 standings: list[GameImportStandingsRow] 424 killed_encounters: list[int] 425 events: list[GameImportEvent] 426 past_events: list[GameImportEvent] = Field(default_factory=list) 427 """Up to 20 events that started in the last 30 days (before the ``events`` window), newest first, cancelled ones 428 left out; additive, older addons ignore it.""" 429 members: list[GameImportMember] = Field(default_factory=list) 430 news: list[GameImportNews] = Field(default_factory=list) 431 sheets: dict[str, GameImportSheet] = Field(default_factory=dict) 432 crafters: list[GameImportCrafter] = Field(default_factory=list) 433 recipe_names: dict[str, str] = Field(default_factory=dict) 434 prices: list[GameImportPrice] = Field(default_factory=list) 435 officer: GameImportOfficerPart
436 437 438# --- HTTP API schemas ----------------------------------------------------------------------------------------- 439 440
[docs] 441class EpgpImportBody(BaseModel): 442 """Body for ``POST /api/epgp/imports``: any text containing one ``SQX1:`` string.""" 443 444 payload: str
445 446
[docs] 447class ImportCounts(BaseModel): 448 """New vs. updated (re-imported, unchanged ``external_id``) row counts.""" 449 450 new: int = 0 451 updated: int = 0
452 453
[docs] 454class LootImportCounts(ImportCounts): 455 """``ImportCounts`` plus rows newly voided by this import.""" 456 457 voided: int = 0
458 459
[docs] 460class AwardImportCounts(ImportCounts): 461 """``ImportCounts`` plus rows newly voided by this import.""" 462 463 voided: int = 0
464 465
[docs] 466class ImportAttendanceResult(BaseModel): 467 """What the attendance hand-off did for one import call.""" 468 469 event_id: UUID | None 470 marked: int = 0
471 472
[docs] 473class EpgpImportResult(BaseModel): 474 """Response for ``POST /api/epgp/imports``.""" 475 476 recorder: str 477 sessions: ImportCounts 478 encounters: ImportCounts 479 loot: LootImportCounts 480 awards: AwardImportCounts 481 unlinked_characters: list[str] = Field(default_factory=list) 482 attendance: ImportAttendanceResult 483 conflicts: list[str] = Field(default_factory=list) 484 """Session external ids skipped by the one-recorder-per-raid-night conflict rule.""" 485 roster: RosterImportCounts = Field(default_factory=RosterImportCounts) 486 professions: ProfessionImportCounts = Field(default_factory=ProfessionImportCounts) 487 signups: SignupImportCounts = Field(default_factory=SignupImportCounts) 488 bank: BankImportCounts = Field(default_factory=BankImportCounts) 489 announcements: AnnouncementImportCounts = Field(default_factory=AnnouncementImportCounts) 490 recruits: RecruitImportCounts = Field(default_factory=RecruitImportCounts) 491 member_notes: MemberNoteImportCounts = Field(default_factory=MemberNoteImportCounts) 492 directory: DirectoryImportCounts = Field(default_factory=DirectoryImportCounts) 493 battlegrounds: BattlegroundImportCounts = Field(default_factory=BattlegroundImportCounts) 494 guild_log: GuildLogImportCounts = Field(default_factory=GuildLogImportCounts) 495 recruit_payouts_paid: RecruitPayoutImportCounts = Field(default_factory=RecruitPayoutImportCounts) 496 scope: Literal["officer", "member"] = Field( 497 default="officer", 498 description=( 499 "Whether this import applied as an officer (every section) or a member (only their linked " 500 "characters' directory and signups). Defaults to `officer` for older clients that predate this field." 501 ), 502 )
503 504
[docs] 505class EpgpRules(BaseModel): 506 """The ``rules`` object as returned by ``GET /api/epgp/standings`` (same shape as the game-import payload).""" 507 508 ep: dict[str, int] = Field(description="Effort points (EP) awarded per AwardReason.") 509 gp: dict[str, int] = Field(description="Gear points (GP) by Discord item inventory type at main-spec cost.") 510 chase_multiplier: float 511 legendary_gp: int 512 os_percent: int 513 base_gp: int 514 min_gp: int 515 decay_percent: int 516 trial_days: int 517 weekly_reset_weekday: int = Field(description="`datetime.weekday()` value the weekly reset lands on (1 = Tuesday).") 518 weekly_reset_hour_utc: int = Field(description="UTC hour the weekly reset lands on.")
519 520
[docs] 521class EpgpStandingsRow(BaseModel): 522 """One row of ``GET /api/epgp/standings``.""" 523 524 model_config = ConfigDict(populate_by_name=True, serialize_by_alias=True) 525 526 member_id: int | None 527 name: str 528 main: str | None 529 main_name: str | None = Field(default=None, description="The main character's name as the game shows it.") 530 wow_class: WowClass | None = Field(alias="class") 531 characters: list[str] 532 ep: float = Field(description="Effort points (EP, shown as Renown on the site).") 533 gp: float = Field(description="Gear points (GP).") 534 pr: float = Field(description="Priority: EP divided by GP.") 535 trial: bool
536 537
[docs] 538class EpgpStandings(BaseModel): 539 """Response for ``GET /api/epgp/standings`` (public).""" 540 541 generated_at: datetime 542 rules: EpgpRules 543 rows: list[EpgpStandingsRow]
544 545
[docs] 546class EpgpLedgerRow(BaseModel): 547 """One row of ``GET /api/epgp/ledger``.""" 548 549 id: UUID 550 at: datetime 551 kind: LedgerKind 552 amount: int = Field(description="EP or GP change, as set by kind.") 553 decayed: float = Field(description="The amount after weekly decay has been applied, read-time only.") 554 reason: str 555 note: str | None 556 character: str | None 557 member_id: int | None 558 member_name: str | None 559 officer: str 560 item_name: str | None 561 response: LootResponse | None = Field(description="How the linked loot award was rolled, for a GP charge.") 562 voided: bool
563 564
[docs] 565class EpgpLedgerPage(BaseModel): 566 """Response for ``GET /api/epgp/ledger`` (public), newest first.""" 567 568 entries: list[EpgpLedgerRow]
569 570
[docs] 571class EpgpLootRow(BaseModel): 572 """One row of ``GET /api/epgp/loot``.""" 573 574 id: UUID 575 at: datetime 576 item_id: int 577 item_name: str 578 quality: int 579 character: str | None 580 member_id: int | None 581 member_name: str | None 582 response: LootResponse 583 gp: int = Field(description="Gear points (GP) this item cost.") 584 instance_name: str | None 585 encounter_name: str | None 586 voided: bool 587 council_reason: str | None = None 588 council_kind: CouncilKind | None = None
589 590
[docs] 591class EpgpLootPage(BaseModel): 592 """Response for ``GET /api/epgp/loot`` (public), newest first.""" 593 594 items: list[EpgpLootRow]
595 596
[docs] 597class EpgpProgressionEncounter(BaseModel): 598 """One boss's kill/wipe tally on the progression board.""" 599 600 encounter_id: int 601 name: str 602 first_kill_at: datetime | None 603 kills: int 604 wipes: int 605 last_attempt_at: datetime
606 607
[docs] 608class EpgpProgressionInstance(BaseModel): 609 """One instance's bosses on the progression board.""" 610 611 instance_id: int 612 name: str 613 size: int 614 encounters: list[EpgpProgressionEncounter]
615 616
[docs] 617class EpgpProgression(BaseModel): 618 """Response for ``GET /api/epgp/progression`` (public).""" 619 620 instances: list[EpgpProgressionInstance]
621 622
[docs] 623class EpgpGameImport(BaseModel): 624 """Response for ``GET /api/epgp/game-import`` (officer).""" 625 626 payload: str 627 generated_at: datetime
628 629
[docs] 630class EpgpAdjustmentCreate(BaseModel): 631 """Body for ``POST /api/epgp/adjustments`` (officer).""" 632 633 member_id: int 634 kind: LedgerKind 635 amount: int = Field(ge=AWARD_AMOUNT_MIN, le=AWARD_AMOUNT_MAX, description="EP or GP change, as set by kind.") 636 reason: str = Field(min_length=1, max_length=MAX_NOTE_LENGTH)
637 638
[docs] 639class EpgpCharacter(BaseModel): 640 """A ``WowCharacter``, as returned by the characters admin screen and ``/api/me/characters``.""" 641 642 model_config = ConfigDict(populate_by_name=True, serialize_by_alias=True) 643 644 id: UUID 645 name: str 646 realm: str 647 wow_class: WowClass | None = Field(alias="class") 648 member_id: int | None 649 member_name: str | None 650 is_main: bool 651 source: CharacterSource 652 last_seen_at: datetime | None
653 654
[docs] 655class EpgpCharacterList(BaseModel): 656 """Response for ``GET /api/epgp/characters`` (officer) and ``GET /api/me/characters`` (member).""" 657 658 characters: list[EpgpCharacter]
659 660
[docs] 661class EpgpCharacterUpdate(BaseModel): 662 """Body for ``PUT /api/epgp/characters/{id}`` (officer).""" 663 664 member_id: int | None 665 is_main: bool
666 667
[docs] 668class MyCharacterCreate(BaseModel): 669 """Body for ``POST /api/me/characters`` (member). 409 if another member already claimed this name-realm.""" 670 671 model_config = ConfigDict(populate_by_name=True) 672 673 name: str = Field(min_length=2, max_length=MAX_NAME_LENGTH) 674 realm: str | None = None 675 wow_class: WowClass | None = Field(default=None, alias="class")
676 677
[docs] 678class EpgpRosterRow(BaseModel): 679 """One row of ``GET /api/epgp/roster`` (officer).""" 680 681 member_id: int 682 name: str 683 raid_status: RaidStatus | None 684 trial_started_at: datetime | None
685 686
[docs] 687class EpgpRoster(BaseModel): 688 """Response for ``GET /api/epgp/roster`` (officer).""" 689 690 members: list[EpgpRosterRow]
691 692
[docs] 693class EpgpRosterUpdate(BaseModel): 694 """Body for ``PUT /api/epgp/roster/{member_id}`` (officer). Setting ``"trial"`` stamps ``trial_started_at`` now.""" 695 696 raid_status: RaidStatus | None
697 698
[docs] 699class EpgpSyncTokenSummary(BaseModel): 700 """One non-revoked sync token, without the secret (``GET /api/epgp/sync-tokens``, officer, own tokens only).""" 701 702 id: UUID 703 name: str 704 created_at: datetime 705 last_used_at: datetime | None
706 707
[docs] 708class EpgpSyncTokenList(BaseModel): 709 """Response for ``GET /api/epgp/sync-tokens`` (officer).""" 710 711 tokens: list[EpgpSyncTokenSummary]
712 713
[docs] 714class EpgpSyncTokenCreate(BaseModel): 715 """Body for ``POST /api/epgp/sync-tokens`` (officer).""" 716 717 name: str = Field(min_length=1, max_length=60)
718 719
[docs] 720class EpgpSyncTokenCreated(BaseModel): 721 """Response for ``POST /api/epgp/sync-tokens``: the token shown once, never stored in plaintext.""" 722 723 id: UUID 724 name: str 725 token: str
726 727 728MAX_DEVICE_NAME_LENGTH = 60 729"""Cap on ``EpgpDeviceAuthorizationCreate.device_name``, trimmed; also the sync token name length it feeds into.""" 730 731_LAST_CONTROL_CHAR = 0x1F 732_DEL_CHAR = 0x7F 733 734
[docs] 735class DeviceAuthorizationPollStatus(StrEnum): 736 """``status`` on ``POST /api/epgp/device-authorizations/token``.""" 737 738 PENDING = "pending" 739 SLOW_DOWN = "slow_down" 740 DENIED = "denied" 741 EXPIRED = "expired" 742 APPROVED = "approved"
743 744
[docs] 745class DeviceAuthorizationStatus(StrEnum): 746 """``status`` on ``GET /api/epgp/device-authorizations/{user_code}``.""" 747 748 PENDING = "pending" 749 APPROVED = "approved" 750 DENIED = "denied" 751 EXPIRED = "expired"
752 753
[docs] 754class EpgpDeviceAuthorizationCreate(BaseModel): 755 """Body for ``POST /api/epgp/device-authorizations`` (public): the device starting a browser sign-in.""" 756 757 device_name: str = Field(min_length=1, max_length=MAX_DEVICE_NAME_LENGTH) 758 759 @field_validator("device_name") 760 @classmethod 761 def _validate_device_name(cls, value: str) -> str: 762 trimmed = value.strip() 763 if not trimmed: 764 msg = "device_name must not be blank" 765 raise ValueError(msg) 766 if any(ord(char) <= _LAST_CONTROL_CHAR or ord(char) == _DEL_CHAR for char in trimmed): 767 msg = "device_name must not contain control characters" 768 raise ValueError(msg) 769 return trimmed
770 771
[docs] 772class EpgpDeviceAuthorizationCreated(BaseModel): 773 """Response for ``POST /api/epgp/device-authorizations`` (public): poll ``.../token`` with ``device_code``.""" 774 775 device_code: str 776 user_code: str 777 verification_uri: str 778 verification_uri_complete: str 779 expires_in: int 780 interval: int
781 782
[docs] 783class EpgpDeviceAuthorizationPoll(BaseModel): 784 """Body for ``POST /api/epgp/device-authorizations/token`` (public).""" 785 786 device_code: str
787 788
[docs] 789class EpgpDeviceAuthorizationPollResult(BaseModel): 790 """Response for ``POST /api/epgp/device-authorizations/token`` (public): always 200, never an oracle. 791 792 ``token``/``name`` are set only once, on the first ``"approved"`` poll; a later poll for the same device code 793 gets ``"expired"``. 794 """ 795 796 status: DeviceAuthorizationPollStatus 797 token: str | None = None 798 name: str | None = None
799 800
[docs] 801class EpgpDeviceAuthorizationStatus(BaseModel): 802 """Response for ``GET /api/epgp/device-authorizations/{user_code}`` (any guild member).""" 803 804 user_code: str 805 device_name: str 806 created_at: datetime 807 expires_at: datetime 808 status: DeviceAuthorizationStatus
809 810
[docs] 811class EpgpSyncTokenMe(BaseModel): 812 """Response for ``GET /api/epgp/sync-tokens/me`` (Bearer only). 813 814 What the presenting token's owner can see about themselves. ``is_guild_member`` is always ``true``: a token 815 whose owner left the guild gets 403 instead. 816 """ 817 818 display_name: str 819 avatar_url: str | None 820 is_officer: bool 821 is_guild_member: bool 822 calendar_url: str | None 823 token_name: str
824 825
[docs] 826class CouncilLogEntry(BaseModel): 827 """One row of ``GET /api/guilds/{guild_id}/loot/council/pending`` (bot, bot-key only). 828 829 ``kind`` is ``"decision"`` for a council row not yet posted, or ``"void"`` for one voided after its decision 830 already posted. ``at`` is the decision time for a decision, or the void time for a void. 831 """ 832 833 loot_id: UUID 834 kind: CouncilLogKind 835 item_id: int 836 item_name: str 837 quality: int 838 character: str 839 member_name: str | None 840 gp: int = Field(description="Gear points (GP) this item cost.") 841 council_kind: CouncilKind | None 842 council_reason: str | None 843 instance_name: str | None 844 encounter_name: str | None 845 at: datetime
846 847
[docs] 848class CouncilLogPage(BaseModel): 849 """Response for ``GET /api/guilds/{guild_id}/loot/council/pending`` (bot), oldest first, capped at 25.""" 850 851 items: list[CouncilLogEntry]
852 853
[docs] 854class CouncilPostedBody(BaseModel): 855 """Body for ``POST /api/guilds/{guild_id}/loot/council/{loot_id}/posted`` (bot). Idempotent.""" 856 857 kind: CouncilLogKind