1"""Hall of Heroes badge definitions and earned-badge schemas.
2
3Badges are defined in code, not configured on the site: ``BADGES`` is the single source of truth for every badge's
4id, display name, description, icon, and the color its Discord role gets. The bot creates one Discord role per
5badge (stored in ``GuildConfigSchema.badge_role_ids``) and keeps membership in sync with ``MemberBadge`` rows the
6API computes. Adjust thresholds here; nothing else needs to change.
7"""
8
9from datetime import datetime # pydantic needs it at runtime
10
11from pydantic import BaseModel, ConfigDict
12
13
[docs]
14class BadgeDefinition(BaseModel):
15 """One badge's fixed metadata. ``color`` is a Discord role color (0xRRGGBB)."""
16
17 id: str
18 name: str
19 description: str
20 icon: str
21 color: int
22
23
24BADGE_LIST: tuple[BadgeDefinition, ...] = (
25 BadgeDefinition(
26 id="first_steps",
27 name="First Steps",
28 description="Attended their first guild event.",
29 icon="👣",
30 color=0x9AA6B2,
31 ),
32 BadgeDefinition(
33 id="first_raid",
34 name="First Raid",
35 description="Attended their first raid.",
36 icon="⚔️",
37 color=0xC69B6D,
38 ),
39 BadgeDefinition(
40 id="raid_regular",
41 name="Raid Regular",
42 description="Attended 10 raids with the guild.",
43 icon="🛡️",
44 color=0x4A9DF2,
45 ),
46 BadgeDefinition(
47 id="raid_veteran",
48 name="Raid Veteran",
49 description="Attended 25 raids with the guild.",
50 icon="🏅",
51 color=0xB673F5,
52 ),
53 BadgeDefinition(
54 id="perfect_month",
55 name="Perfect Month",
56 description="Attended every raid the guild ran in a calendar month (at least 4 raids that month).",
57 icon="🌙",
58 color=0xFFD36A,
59 ),
60 BadgeDefinition(
61 id="founding_member",
62 name="Founding Member",
63 description="Confirmed on the guild roster before launch.",
64 icon="🏰",
65 color=0xF48CBA,
66 ),
67 BadgeDefinition(
68 id="chatterbox",
69 name="Chatterbox",
70 description="Reached level 10.",
71 icon="💬",
72 color=0x3FC7EB,
73 ),
74 BadgeDefinition(
75 id="top_helper",
76 name="Top Helper",
77 description="Attended the most dungeon and leveling events last month. A moving monthly title.",
78 icon="🌟",
79 color=0xFF8C2A,
80 ),
81 BadgeDefinition(
82 id="party_animal",
83 name="Party Animal",
84 description="Grouped up from #lfg 50 times (ten minutes or more with at least one other member).",
85 icon="🎉",
86 color=0x5FD38D,
87 ),
88 BadgeDefinition(
89 id="party_leader",
90 name="Party Leader",
91 description="Started 25 groups from #lfg that others joined.",
92 icon="🚩",
93 color=0xE0533D,
94 ),
95 BadgeDefinition(
96 id="open_road",
97 name="Open Road",
98 description="Hosted a first PUG group from #lfg: outside players grouped with the guild for ten minutes.",
99 icon="🪧",
100 color=0xC8A165,
101 ),
102 BadgeDefinition(
103 id="crossroads_host",
104 name="Crossroads Host",
105 description="Hosted 10 PUG groups from #lfg that outside players joined.",
106 icon="🧭",
107 color=0x2FB7A3,
108 ),
109 BadgeDefinition(
110 id="caravan_master",
111 name="Caravan Master",
112 description="Hosted 25 PUG groups from #lfg that outside players joined.",
113 icon="🐫",
114 color=0xD4AF37,
115 ),
116)
117
118BADGES: dict[str, BadgeDefinition] = {badge.id: badge for badge in BADGE_LIST}
119
120RAID_REGULAR_THRESHOLD = 10
121RAID_VETERAN_THRESHOLD = 25
122PERFECT_MONTH_MIN_RAIDS = 4
123CHATTERBOX_LEVEL = 10
124FOUNDING_MEMBER_CUTOFF_ISO = "2026-11-04T00:00:00+00:00"
125"""Members confirmed on the roster before this instant (the launch date, UTC midnight) earn Founding Member."""
126
127
[docs]
128class EarnedBadge(BaseModel):
129 """One badge a member has earned, for the profile's badge case."""
130
131 model_config = ConfigDict(from_attributes=True)
132
133 id: str
134 name: str
135 description: str
136 icon: str
137 earned_at: datetime
138
139
[docs]
140class BadgeRoleState(BaseModel):
141 """One member's current badge ids, for the bot's role sync (``GET /api/guilds/{id}/badges/state``)."""
142
143 discord_id: int
144 badge_ids: list[str]
145
146
[docs]
147class PendingBadgeAnnouncement(BaseModel):
148 """A newly earned badge not yet announced in Discord."""
149
150 discord_id: int
151 badge_id: str
152 name: str
153 description: str
154
155
[docs]
156class BadgeSyncReport(BaseModel):
157 """``GET /api/guilds/{id}/badges/sync``: recomputes every member's badges, then reports the result.
158
159 ``role_state`` is every linked member's full current badge set (the bot diffs this against actual role
160 membership). ``pending`` is newly earned badges not yet announced; the bot posts them, then calls
161 ``POST /api/guilds/{id}/badges/ack`` to mark them announced.
162 """
163
164 role_state: list[BadgeRoleState]
165 pending: list[PendingBadgeAnnouncement]
166
167
[docs]
168class BadgeAck(BaseModel):
169 """Body for ``POST /api/guilds/{id}/badges/ack``: badges whose announcement has posted."""
170
171 discord_id: int
172 badge_id: str