meow (#1330)
This commit is contained in:
+17
-12
@@ -74,19 +74,22 @@ def _present_players(game: dict[str, Any]) -> set[str]:
|
||||
|
||||
|
||||
def _bar_color(game: dict[str, Any], guild_id: int) -> str:
|
||||
"""Header/separator tint from the guild's own team vs the result."""
|
||||
"""Header/separator tint from the guild's own team vs the result.
|
||||
|
||||
Compared by team *name* (case-insensitive) — TSS team ids are per-tournament.
|
||||
"""
|
||||
if game.get("draw"):
|
||||
return "draw"
|
||||
guild_team = preferences.get_guild_team(guild_id)
|
||||
if not guild_team or guild_team.get("team_id") is None:
|
||||
my_name = str((guild_team or {}).get("TM_Name") or "").casefold()
|
||||
if not my_name:
|
||||
return "not_set"
|
||||
my_id = str(guild_team["team_id"])
|
||||
tss = game.get("tss") or {}
|
||||
slot_ids = {s: str((tss.get(s) or {}).get("team_id")) for s in ("1", "2")}
|
||||
slot_names = {s: str((tss.get(s) or {}).get("team_name") or "").casefold() for s in ("1", "2")}
|
||||
winner = str(game.get("winner") or "")
|
||||
if slot_ids.get(winner) == my_id:
|
||||
if slot_names.get(winner) == my_name:
|
||||
return "win"
|
||||
if my_id in slot_ids.values():
|
||||
if my_name in slot_names.values():
|
||||
return "loss"
|
||||
return "not_involved"
|
||||
|
||||
@@ -176,26 +179,28 @@ async def process_game(game: dict[str, Any]) -> None:
|
||||
if not session_id:
|
||||
return
|
||||
|
||||
present_team_ids, present_team_names = _present_teams(game)
|
||||
_, present_team_names = _present_teams(game)
|
||||
present_uids = _present_players(game)
|
||||
sent = _sent_channels_by_session.setdefault(session_id, set())
|
||||
|
||||
for guild_id, prefs in preferences.iter_guild_preferences():
|
||||
for entity_id, entry in prefs.items():
|
||||
for _pref_key, entry in prefs.items():
|
||||
if not isinstance(entry, dict):
|
||||
continue
|
||||
type_ = entry.get("Type")
|
||||
if type_ not in ("tss-team", "tss-player"):
|
||||
if type_ not in ("tss-team", "tss-player", "tss-wildcard"):
|
||||
continue
|
||||
channel_id, enabled = preferences.parse_channel(entry.get("Logs"))
|
||||
if not channel_id or not enabled or channel_id in sent:
|
||||
continue
|
||||
|
||||
if type_ == "tss-team":
|
||||
if type_ == "tss-wildcard":
|
||||
matched = True
|
||||
elif type_ == "tss-team":
|
||||
name = (entry.get("Name") or "").lower()
|
||||
matched = str(entity_id) in present_team_ids or (bool(name) and name in present_team_names)
|
||||
matched = bool(name) and name in present_team_names
|
||||
else: # tss-player
|
||||
matched = str(entity_id) in present_uids
|
||||
matched = str(entry.get("UID") or "") in present_uids
|
||||
if not matched:
|
||||
continue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user