This commit is contained in:
NotSoToothless
2026-06-17 01:21:00 -07:00
committed by GitHub
parent 7bd8a1b72c
commit c5b74de367
3 changed files with 133 additions and 26 deletions
+30 -4
View File
@@ -119,22 +119,48 @@ def save_guild_preferences(guild_id: int | str, prefs: dict[str, Any]) -> bool:
return _write_json(_guild_pref_path(guild_id), prefs)
# Tokens a user can type to mean "log everything".
WILDCARD_TOKENS: frozenset[str] = frozenset({"*", "all", "everything"})
# Storage key for the wildcard route. NOT "*" — SREBOT treats keys in {"*","all",
# "everything"} as ITS wildcard and would post SRE boards to this channel. Prefixed
# keys also stop a numeric team-name/uid colliding with an SRE clan_id key.
WILDCARD_KEY = "tss-wildcard"
def team_pref_key(name: str) -> str:
"""Storage key for a team route (teams have no stable id — keyed by name)."""
return f"tss-team:{name.casefold()}"
def player_pref_key(uid: int | str) -> str:
"""Storage key for a player route (keyed by stable uid)."""
return f"tss-player:{uid}"
def upsert_log_entry(
guild_id: int | str,
entity_id: int | str,
key: str,
type_: str,
name: str,
channel_id: int | str,
extra: Optional[dict[str, Any]] = None,
) -> bool:
"""Add/replace a ``tss-team``/``tss-player`` route for a guild."""
"""Add/replace a ``tss-team``/``tss-player``/``tss-wildcard`` route for a guild.
``key`` is the storage slot (use ``team_pref_key``/``player_pref_key``/
``WILDCARD_KEY``); the matchable value lives in fields (``Name`` for teams,
``UID`` for players) so the key stays SRE-collision-safe.
"""
prefs = load_guild_preferences(guild_id)
entry = prefs.setdefault(str(entity_id), {})
entry = prefs.setdefault(key, {})
if not isinstance(entry, dict):
entry = {}
prefs[str(entity_id)] = entry
prefs[key] = entry
entry["Type"] = type_
entry["Name"] = name
entry["Logs"] = channel_mention(channel_id)
if extra:
entry.update(extra)
return save_guild_preferences(guild_id, prefs)