Source code for sidequest_common.schemas.recruitment

  1"""Recruitment drive schemas: constants, enums, the addon export/import additions, and the site HTTP API.
  2
  3``local://recruitment-contract.md`` is the source of truth. A drive is a ``GuildEvent`` of kind ``recruitment``
  4(``sidequest_common.schemas.events.EventKind.RECRUITMENT``) running 14 days by default; the inviter with the most
  5recruits who stay ``RECRUIT_STAY_DAYS`` days and reach ``RECRUIT_MIN_LEVEL`` wins ``DRIVE_PRIZE_COPPER``, ties each
  6win it, settled ``DRIVE_SETTLE_DAYS`` after the drive ends. Who invited whom comes from
  7the in-game guild log (``ExportGuildLogEntry``), not the addon.
  8"""
  9
 10from datetime import datetime, timedelta  # pydantic needs datetime at runtime
 11from enum import StrEnum
 12from uuid import UUID  # pydantic needs it at runtime
 13
 14from pydantic import BaseModel, Field
 15
 16DRIVE_PRIZE_COPPER = 100_000
 17"""10g, paid to the inviter(s) with the most qualifying recruits in a drive. Ties each win it."""
 18RECRUIT_MIN_LEVEL = 10
 19RECRUIT_STAY_DAYS = 7
 20DRIVE_SETTLE_DAYS = 7
 21"""Payouts settle this many days after the drive's ``ends_at``."""
 22DRIVE_DEFAULT_DAYS = 14
 23"""The site form's default drive length."""
 24RECRUIT_JOIN_WINDOW = timedelta(hours=48)
 25"""A join must follow its invite within this window, else the recruit is ``never_joined``."""
 26
 27MAX_GUILD_LOG_ENTRIES = 500
 28MAX_RECRUIT_PAYOUTS_PAID = 200
 29MAX_RECRUITMENT_LEADERS = 15
 30"""Cap on ``RecruitmentTally.leaders``, the most relevant inviters for the forum starter post."""
 31GUILD_LOG_DEDUPE_WINDOW = timedelta(hours=2)
 32"""A re-uploaded guild log row with the same kind/actor/target within this window of a stored row is the same entry."""
 33RECRUIT_NAME_MAX_LENGTH = 64
 34"""Matches the addon's character name format (``roster.members[].character``)."""
 35
 36
[docs] 37class GuildLogKind(StrEnum): 38 """One kind of in-game guild event log entry (``QueryGuildEventLog``/``GetGuildEventInfo``).""" 39 40 INVITE = "invite" 41 JOIN = "join" 42 QUIT = "quit" 43 REMOVE = "remove"
44 45
[docs] 46class DriveRecruitStatus(StrEnum): 47 """Where one recruit is in a drive's 7-day qualification clock.""" 48 49 INVITED = "invited" 50 COUNTING = "counting" 51 QUALIFIED = "qualified" 52 DISQUALIFIED = "disqualified"
53 54
[docs] 55class DriveRecruitReason(StrEnum): 56 """Why a recruit is ``disqualified``. Only set alongside ``DriveRecruitStatus.DISQUALIFIED``.""" 57 58 RETURNING = "returning" 59 OWN_ALT = "own_alt" 60 LEFT = "left" 61 LOW_LEVEL = "low_level" 62 NEVER_JOINED = "never_joined"
63 64
[docs] 65class PaidVia(StrEnum): 66 """How a recruit's payout was marked paid: the site's "Mark paid" button, or the addon's mail-send button.""" 67 68 SITE = "site" 69 ADDON = "addon"
70 71 72# --- Addon -> site: SQX1 export additions (additive; ``v`` stays 2) ------------------------------------------ 73 74
[docs] 75class ExportGuildLogEntry(BaseModel): 76 """One ``SQX1:`` guild event log row (max ``MAX_GUILD_LOG_ENTRIES``). ``at`` is rounded down to the hour. 77 78 ``actor`` is the inviter for ``invite``, the member for ``join``/``quit``, or the removing officer for 79 ``remove``; ``target`` is the invitee for ``invite`` or the removed member for ``remove``, and omitted for 80 ``join``/``quit``. ``promote``/``demote`` entries are never exported. 81 """ 82 83 kind: GuildLogKind 84 actor: str = Field(max_length=RECRUIT_NAME_MAX_LENGTH) 85 target: str | None = Field(default=None, max_length=RECRUIT_NAME_MAX_LENGTH) 86 at: int
87 88
[docs] 89class ExportRecruitPayoutPaid(BaseModel): 90 """One ``SQX1:`` row for a payout the addon's mail button already sent (max ``MAX_RECRUIT_PAYOUTS_PAID``).""" 91 92 event_id: UUID 93 inviter: str = Field(max_length=RECRUIT_NAME_MAX_LENGTH) 94 copper: int = Field(ge=0, description="The flat prize mailed; the site keys this on event + inviter, not amount.") 95 at: int 96 officer: str = Field(max_length=RECRUIT_NAME_MAX_LENGTH)
97 98
[docs] 99class GuildLogImportCounts(BaseModel): 100 """Counts for the ``guild_log`` section of one import. ``merged`` matches a stored row within the dedupe window.""" 101 102 new: int = 0 103 merged: int = 0
104 105
[docs] 106class RecruitPayoutImportCounts(BaseModel): 107 """Counts for the ``recruit_payouts_paid`` section of one import. ``already_paid`` is the idempotent no-op case.""" 108 109 new: int = 0 110 already_paid: int = 0
111 112 113# --- Site -> addon: SQI1 import addition (additive) ----------------------------------------------------------- 114 115
[docs] 116class GameImportRecruitPayout(BaseModel): 117 """One ``SQI1:`` officer payout row: a drive's winning inviter (most qualifying recruits, ties each win).""" 118 119 event_id: UUID 120 title: str 121 inviter: str 122 copper: int = Field(description="The flat prize this inviter won (not a per-recruit sum).") 123 recruits: list[str] = Field(description="The winning inviter's qualifying recruits in this drive.") 124 settles_at: int
125 126 127MAX_IMPORT_DRIVE_RECRUITS = 50 128"""Cap on ``GameImportDrive.recruits``, the most relevant recruit rows for the addon's Events tab.""" 129 130
[docs] 131class GameImportDriveLeader(BaseModel): 132 """One inviter on a drive's leaderboard in the ``SQI1:`` import.""" 133 134 inviter: str 135 invited: int 136 counting: int = Field(description='"Potential": joined and still inside their 7 days.') 137 qualified: int
138 139
[docs] 140class GameImportDriveRecruit(BaseModel): 141 """One recruit's state in the ``SQI1:`` import.""" 142 143 recruit: str 144 inviter: str 145 status: DriveRecruitStatus 146 reason: DriveRecruitReason | None = None 147 qualifies_at: int | None = Field(default=None, description="Unix seconds, set once joined.")
148 149
[docs] 150class GameImportDrive(BaseModel): 151 """``GameImportEvent.recruitment``: a drive's leaderboard and recruits for the addon's Events tab. 152 153 ``recruits`` is ordered counting first (soonest ``qualifies_at`` first), then invited (newest invite first), 154 then qualified (newest first), then disqualified (newest first), truncated to ``MAX_IMPORT_DRIVE_RECRUITS``. 155 """ 156 157 leaders: list[GameImportDriveLeader] = Field(default_factory=list, max_length=MAX_RECRUITMENT_LEADERS) 158 recruits: list[GameImportDriveRecruit] = Field(default_factory=list, max_length=MAX_IMPORT_DRIVE_RECRUITS)
159 160 161# --- Site HTTP API (tag "Recruitment drives") ------------------------------------------------------------------- 162 163
[docs] 164class RecruitmentDriveTotals(BaseModel): 165 """Headcounts across a drive's recruits, by ``DriveRecruitStatus`` plus how many are paid.""" 166 167 invited: int 168 joined: int 169 counting: int 170 qualified: int 171 disqualified: int 172 paid: int
173 174
[docs] 175class RecruitLeader(BaseModel): 176 """One inviter's standing in a drive's leaderboard.""" 177 178 inviter: str 179 member_name: str | None 180 discord_id: str | None = Field(description="The inviter's Discord id as a string (too big for JS numbers).") 181 invited: int 182 joined: int 183 counting: int 184 qualified: int
185 186
[docs] 187class DriveRecruit(BaseModel): 188 """One recruit's row in a drive's detail, including their qualification clock and pay state.""" 189 190 recruit: str 191 inviter: str 192 invited_at: datetime 193 joined_at: datetime | None 194 qualifies_at: datetime | None 195 status: DriveRecruitStatus 196 reason: DriveRecruitReason | None 197 paid_at: datetime | None
198 199
[docs] 200class RecruitmentDrive(BaseModel): 201 """``GET /api/events/{event_id}/recruitment``: one drive's full detail, leaderboard, and recruit rows.""" 202 203 event_id: UUID 204 title: str 205 starts_at: datetime 206 ends_at: datetime 207 settles_at: datetime 208 reward_copper: int = Field( 209 description="The flat prize for winning the drive (most qualifying recruits, ties each win); not per recruit." 210 ) 211 min_level: int 212 stay_days: int 213 totals: RecruitmentDriveTotals 214 leaders: list[RecruitLeader] 215 recruits: list[DriveRecruit]
216 217
[docs] 218class RecruitPayout(BaseModel): 219 """``GET /api/recruitment/payouts``: one winning inviter's owed (or already-paid) prize for one settled drive.""" 220 221 event_id: UUID 222 title: str 223 settles_at: datetime 224 inviter: str 225 member_name: str | None 226 recruits: list[str] = Field(description="This winner's qualifying recruits in the drive.") 227 copper: int = Field(description="The flat prize this inviter won (not a per-recruit sum).") 228 paid_at: datetime | None 229 paid_by: str | None 230 paid_via: PaidVia | None
231 232
[docs] 233class RecruitPayoutMarkPaid(BaseModel): 234 """Body for ``POST /api/recruitment/payouts/paid`` (officer). Idempotent.""" 235 236 event_id: UUID 237 inviter: str
238 239 240# --- Site -> bot (event sync; additive with defaults) ----------------------------------------------------------- 241 242
[docs] 243class RecruitmentTally(BaseModel): 244 """``DiscordEventPush.recruitment``: a drive's live leaderboard, for the forum starter post.""" 245 246 reward_copper: int = Field(description="The flat prize for winning the drive, not a per-recruit amount.") 247 settles_at: datetime 248 invited: int 249 joined: int 250 qualified: int 251 leaders: list[RecruitLeader] = Field(default_factory=list, max_length=MAX_RECRUITMENT_LEADERS)
252 253
[docs] 254class RecruitShoutout(BaseModel): 255 """One qualified recruit's shout-out, queued to post as a comment on the drive's forum thread.""" 256 257 id: UUID 258 thread_id: int 259 event_id: UUID 260 inviter: str 261 inviter_discord_id: int | None 262 recruit: str 263 reward_copper: int = Field( 264 description="The drive's flat prize amount, kept for older bots; the shout-out no longer names a gold amount." 265 )
266 267
[docs] 268class RecruitShoutoutAck(BaseModel): 269 """``POST /api/guilds/{guild_id}/event-sync/recruit-shoutouts/ack``: the bot posted these shout-outs.""" 270 271 ids: list[UUID]