forked from sass/tipibot
feat(teams): resolve team dividers by role ID instead of name
Divider placement matched the divider role by its exact Discord name, so renaming the role in Discord silently broke positioning. Switch the TEAM_DIVIDER_<SUFFIX> config to hold a role ID; resolve the ID to the role's current name in apply_team_role_positions and keep the existing name-based ordering maths downstream unchanged. - config._parse_team_dividers now parses values as ints (rejects non-ints) - resolve_divider / _team_divider cache / get_team_dividers return IDs - apply_team_role_positions resolves each ID via guild.get_role once - .env.example documents IDs and ships the CS2/LoL divider role IDs - resolve_divider tests updated to assert IDs Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XPRsW4tazVtYi2jNzVQkre
This commit is contained in:
35
config.py
35
config.py
@@ -72,32 +72,39 @@ BOT_ADMIN_ROLES: dict[int, set[int]] = _parse_admin_roles(os.getenv("DISCORD_ADM
|
||||
_TEAM_DIVIDER_PREFIX = "TEAM_DIVIDER_"
|
||||
|
||||
|
||||
def _parse_team_dividers() -> dict[str, str]:
|
||||
"""Collect TEAM_DIVIDER_<SUFFIX> env vars into {suffix: divider role name}.
|
||||
def _parse_team_dividers() -> dict[str, int]:
|
||||
"""Collect TEAM_DIVIDER_<SUFFIX> env vars into {suffix: divider role ID}.
|
||||
|
||||
The suffix says which sheet sections the divider covers, the value is the
|
||||
exact Discord role name their teams get positioned under:
|
||||
Discord role ID their teams get positioned under:
|
||||
|
||||
TEAM_DIVIDER_CS2_2026="====== COUNTER-STRIKE 2 2026 ======"
|
||||
TEAM_DIVIDER_CS2_2026=1498736834656604251
|
||||
|
||||
Every underscore-separated part of the suffix must appear in the section's
|
||||
title row, so `CS2_2026` matches only "TipiLAN 2026 CS2 Registration Log"
|
||||
while a plain `CS2` would match that section in any year. Defining a var is
|
||||
what switches positioning on for those sections; teams whose section matches
|
||||
nothing are still granted their role, just never moved.
|
||||
Matching by ID (not name) means renaming the divider role in Discord never
|
||||
breaks positioning. Every underscore-separated part of the suffix must appear
|
||||
in the section's title row, so `CS2_2026` matches only "TipiLAN 2026 CS2
|
||||
Registration Log" while a plain `CS2` would match that section in any year.
|
||||
Defining a var is what switches positioning on for those sections; teams
|
||||
whose section matches nothing are still granted their role, just never moved.
|
||||
"""
|
||||
dividers: dict[str, str] = {}
|
||||
dividers: dict[str, int] = {}
|
||||
for key, value in os.environ.items():
|
||||
if not key.startswith(_TEAM_DIVIDER_PREFIX):
|
||||
continue
|
||||
suffix = key[len(_TEAM_DIVIDER_PREFIX):].strip().lower()
|
||||
name = value.strip()
|
||||
if suffix and name:
|
||||
dividers[suffix] = name
|
||||
raw = value.strip()
|
||||
if not suffix or not raw:
|
||||
continue
|
||||
try:
|
||||
dividers[suffix] = int(raw)
|
||||
except ValueError:
|
||||
raise SystemExit(
|
||||
f"{key}: expected a Discord role ID (integer), got {raw!r}"
|
||||
)
|
||||
return dividers
|
||||
|
||||
|
||||
TEAM_DIVIDERS: dict[str, str] = _parse_team_dividers()
|
||||
TEAM_DIVIDERS: dict[str, int] = _parse_team_dividers()
|
||||
|
||||
PB_URL = os.getenv("PB_URL", "http://127.0.0.1:8090")
|
||||
PB_ADMIN_EMAIL = os.getenv("PB_ADMIN_EMAIL", "")
|
||||
|
||||
Reference in New Issue
Block a user