2026-03-27 20:45:15 -07:00
|
|
|
import { buildTiedRankChecker } from "~/lib/standings-display";
|
|
|
|
|
|
2026-03-17 11:16:36 -07:00
|
|
|
interface DiscordEmbed {
|
|
|
|
|
title?: string;
|
|
|
|
|
description?: string;
|
|
|
|
|
color?: number;
|
|
|
|
|
footer?: { text: string };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface DiscordWebhookPayload {
|
|
|
|
|
content?: string;
|
|
|
|
|
embeds?: DiscordEmbed[];
|
2026-05-15 10:06:54 -07:00
|
|
|
allowed_mentions?: { parse: string[]; users: string[] };
|
2026-03-17 11:16:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function sendDiscordWebhook(
|
|
|
|
|
webhookUrl: string,
|
|
|
|
|
payload: DiscordWebhookPayload
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
const response = await fetch(webhookUrl, {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
|
body: JSON.stringify(payload),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const text = await response.text().catch(() => "");
|
|
|
|
|
throw new Error(`Discord webhook failed: ${response.status} ${text}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 15:52:57 -07:00
|
|
|
/** Escape characters that trigger Discord markdown formatting. */
|
|
|
|
|
function escapeMarkdown(text: string): string {
|
|
|
|
|
return text.replace(/[_*~`|\\]/g, "\\$&");
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 11:16:36 -07:00
|
|
|
export interface StandingEntry {
|
Partial bracket scoring, code review fixes, and double-chance logic (#156)
## Partial bracket scoring
- `processMatchResult`: new exported function that scores a single match
immediately (loser → final placement, winner → provisional floor).
Called from `set-winner` and `set-round-winners` so points are awarded
as soon as a winner is set, before the full round is complete.
- `set-winner`: passes `eventName` to `processMatchResult`.
- `set-round-winners`: batches side effects — calls `recalculateAffectedLeagues`
and `updateProbabilitiesAfterResult` once after the loop instead of per-match
(`skipSideEffects: true` per match).
## Code review fixes
- **ROUND_CONFIG** (S1): extracted a `RoundScoringConfig` lookup table +
`getRoundConfig()` helper, eliminating three parallel `if/else` chains in
`processPlayoffEvent`, `processMatchResult`, and `getGuaranteedMinimumPosition`.
AFL template overrides live in `TEMPLATE_ROUND_CONFIG` with an explanatory
comment about why the `bracketTemplateId` guard is required.
- **skipSideEffects** (C2): new param on `processMatchResult`; bracket server
uses it to batch standings/probability recalc in `set-round-winners`.
- **eventName** (W1): passed through `processMatchResult` → `recalculateAffectedLeagues`.
- **Round validation** (W2): `set-round-winners` now guards `match.round === round`
before processing each assignment.
- **Comments** (C3/S3/W3): added notes on non-scoring loser assumption,
`isScoring ?? true` default, and AFL Semi-Finals template requirement.
## PlayoffBracket eliminated-teams fix + tests
- Fixed `computeEliminatedByRound` to track participant *appearances* (not just
wins), so AFL QF losers who advance to Semi-Finals via double-chance are
correctly excluded from the QF eliminated list.
- Extracted the logic as an exported pure function for testability.
- Added 4 tests: standard elimination, AFL QF loser → SF win, AFL QF loser →
SF loss, and normal advancement not protecting a later loser.
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 10:50:30 -07:00
|
|
|
teamId: string;
|
|
|
|
|
teamName: string;
|
2026-03-17 14:34:09 -07:00
|
|
|
username?: string;
|
2026-05-15 10:06:54 -07:00
|
|
|
discordUserId?: string;
|
Partial bracket scoring, code review fixes, and double-chance logic (#156)
## Partial bracket scoring
- `processMatchResult`: new exported function that scores a single match
immediately (loser → final placement, winner → provisional floor).
Called from `set-winner` and `set-round-winners` so points are awarded
as soon as a winner is set, before the full round is complete.
- `set-winner`: passes `eventName` to `processMatchResult`.
- `set-round-winners`: batches side effects — calls `recalculateAffectedLeagues`
and `updateProbabilitiesAfterResult` once after the loop instead of per-match
(`skipSideEffects: true` per match).
## Code review fixes
- **ROUND_CONFIG** (S1): extracted a `RoundScoringConfig` lookup table +
`getRoundConfig()` helper, eliminating three parallel `if/else` chains in
`processPlayoffEvent`, `processMatchResult`, and `getGuaranteedMinimumPosition`.
AFL template overrides live in `TEMPLATE_ROUND_CONFIG` with an explanatory
comment about why the `bracketTemplateId` guard is required.
- **skipSideEffects** (C2): new param on `processMatchResult`; bracket server
uses it to batch standings/probability recalc in `set-round-winners`.
- **eventName** (W1): passed through `processMatchResult` → `recalculateAffectedLeagues`.
- **Round validation** (W2): `set-round-winners` now guards `match.round === round`
before processing each assignment.
- **Comments** (C3/S3/W3): added notes on non-scoring loser assumption,
`isScoring ?? true` default, and AFL Semi-Finals template requirement.
## PlayoffBracket eliminated-teams fix + tests
- Fixed `computeEliminatedByRound` to track participant *appearances* (not just
wins), so AFL QF losers who advance to Semi-Finals via double-chance are
correctly excluded from the QF eliminated list.
- Extracted the logic as an exported pure function for testability.
- Added 4 tests: standard elimination, AFL QF loser → SF win, AFL QF loser →
SF loss, and normal advancement not protecting a later loser.
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 10:50:30 -07:00
|
|
|
totalPoints: number;
|
2026-03-17 11:16:36 -07:00
|
|
|
rank: number;
|
Partial bracket scoring, code review fixes, and double-chance logic (#156)
## Partial bracket scoring
- `processMatchResult`: new exported function that scores a single match
immediately (loser → final placement, winner → provisional floor).
Called from `set-winner` and `set-round-winners` so points are awarded
as soon as a winner is set, before the full round is complete.
- `set-winner`: passes `eventName` to `processMatchResult`.
- `set-round-winners`: batches side effects — calls `recalculateAffectedLeagues`
and `updateProbabilitiesAfterResult` once after the loop instead of per-match
(`skipSideEffects: true` per match).
## Code review fixes
- **ROUND_CONFIG** (S1): extracted a `RoundScoringConfig` lookup table +
`getRoundConfig()` helper, eliminating three parallel `if/else` chains in
`processPlayoffEvent`, `processMatchResult`, and `getGuaranteedMinimumPosition`.
AFL template overrides live in `TEMPLATE_ROUND_CONFIG` with an explanatory
comment about why the `bracketTemplateId` guard is required.
- **skipSideEffects** (C2): new param on `processMatchResult`; bracket server
uses it to batch standings/probability recalc in `set-round-winners`.
- **eventName** (W1): passed through `processMatchResult` → `recalculateAffectedLeagues`.
- **Round validation** (W2): `set-round-winners` now guards `match.round === round`
before processing each assignment.
- **Comments** (C3/S3/W3): added notes on non-scoring loser assumption,
`isScoring ?? true` default, and AFL Semi-Finals template requirement.
## PlayoffBracket eliminated-teams fix + tests
- Fixed `computeEliminatedByRound` to track participant *appearances* (not just
wins), so AFL QF losers who advance to Semi-Finals via double-chance are
correctly excluded from the QF eliminated list.
- Extracted the logic as an exported pure function for testability.
- Added 4 tests: standard elimination, AFL QF loser → SF win, AFL QF loser →
SF loss, and normal advancement not protecting a later loser.
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 10:50:30 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-17 11:16:36 -07:00
|
|
|
export interface ScoredMatch {
|
|
|
|
|
winnerName: string;
|
|
|
|
|
loserName: string;
|
2026-03-17 14:34:09 -07:00
|
|
|
winnerUsername?: string;
|
|
|
|
|
loserUsername?: string;
|
2026-05-15 10:06:54 -07:00
|
|
|
winnerDiscordUserId?: string;
|
|
|
|
|
loserDiscordUserId?: string;
|
Partial bracket scoring, code review fixes, and double-chance logic (#156)
## Partial bracket scoring
- `processMatchResult`: new exported function that scores a single match
immediately (loser → final placement, winner → provisional floor).
Called from `set-winner` and `set-round-winners` so points are awarded
as soon as a winner is set, before the full round is complete.
- `set-winner`: passes `eventName` to `processMatchResult`.
- `set-round-winners`: batches side effects — calls `recalculateAffectedLeagues`
and `updateProbabilitiesAfterResult` once after the loop instead of per-match
(`skipSideEffects: true` per match).
## Code review fixes
- **ROUND_CONFIG** (S1): extracted a `RoundScoringConfig` lookup table +
`getRoundConfig()` helper, eliminating three parallel `if/else` chains in
`processPlayoffEvent`, `processMatchResult`, and `getGuaranteedMinimumPosition`.
AFL template overrides live in `TEMPLATE_ROUND_CONFIG` with an explanatory
comment about why the `bracketTemplateId` guard is required.
- **skipSideEffects** (C2): new param on `processMatchResult`; bracket server
uses it to batch standings/probability recalc in `set-round-winners`.
- **eventName** (W1): passed through `processMatchResult` → `recalculateAffectedLeagues`.
- **Round validation** (W2): `set-round-winners` now guards `match.round === round`
before processing each assignment.
- **Comments** (C3/S3/W3): added notes on non-scoring loser assumption,
`isScoring ?? true` default, and AFL Semi-Finals template requirement.
## PlayoffBracket eliminated-teams fix + tests
- Fixed `computeEliminatedByRound` to track participant *appearances* (not just
wins), so AFL QF losers who advance to Semi-Finals via double-chance are
correctly excluded from the QF eliminated list.
- Extracted the logic as an exported pure function for testability.
- Added 4 tests: standard elimination, AFL QF loser → SF win, AFL QF loser →
SF loss, and normal advancement not protecting a later loser.
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 10:50:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function sendStandingsUpdateNotification({
|
|
|
|
|
webhookUrl,
|
|
|
|
|
seasonName,
|
|
|
|
|
standings,
|
|
|
|
|
previousStandings,
|
2026-03-19 15:52:57 -07:00
|
|
|
previousRanks,
|
2026-03-17 11:16:36 -07:00
|
|
|
sportName,
|
Partial bracket scoring, code review fixes, and double-chance logic (#156)
## Partial bracket scoring
- `processMatchResult`: new exported function that scores a single match
immediately (loser → final placement, winner → provisional floor).
Called from `set-winner` and `set-round-winners` so points are awarded
as soon as a winner is set, before the full round is complete.
- `set-winner`: passes `eventName` to `processMatchResult`.
- `set-round-winners`: batches side effects — calls `recalculateAffectedLeagues`
and `updateProbabilitiesAfterResult` once after the loop instead of per-match
(`skipSideEffects: true` per match).
## Code review fixes
- **ROUND_CONFIG** (S1): extracted a `RoundScoringConfig` lookup table +
`getRoundConfig()` helper, eliminating three parallel `if/else` chains in
`processPlayoffEvent`, `processMatchResult`, and `getGuaranteedMinimumPosition`.
AFL template overrides live in `TEMPLATE_ROUND_CONFIG` with an explanatory
comment about why the `bracketTemplateId` guard is required.
- **skipSideEffects** (C2): new param on `processMatchResult`; bracket server
uses it to batch standings/probability recalc in `set-round-winners`.
- **eventName** (W1): passed through `processMatchResult` → `recalculateAffectedLeagues`.
- **Round validation** (W2): `set-round-winners` now guards `match.round === round`
before processing each assignment.
- **Comments** (C3/S3/W3): added notes on non-scoring loser assumption,
`isScoring ?? true` default, and AFL Semi-Finals template requirement.
## PlayoffBracket eliminated-teams fix + tests
- Fixed `computeEliminatedByRound` to track participant *appearances* (not just
wins), so AFL QF losers who advance to Semi-Finals via double-chance are
correctly excluded from the QF eliminated list.
- Extracted the logic as an exported pure function for testability.
- Added 4 tests: standard elimination, AFL QF loser → SF win, AFL QF loser →
SF loss, and normal advancement not protecting a later loser.
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 10:50:30 -07:00
|
|
|
eventName,
|
2026-03-17 11:16:36 -07:00
|
|
|
scoredMatches,
|
|
|
|
|
}: {
|
|
|
|
|
webhookUrl: string;
|
|
|
|
|
seasonName: string;
|
|
|
|
|
standings: StandingEntry[];
|
|
|
|
|
previousStandings: Map<string, number>;
|
2026-03-19 15:52:57 -07:00
|
|
|
previousRanks?: Map<string, number>;
|
2026-03-17 11:16:36 -07:00
|
|
|
sportName?: string;
|
|
|
|
|
eventName?: string;
|
|
|
|
|
scoredMatches?: ScoredMatch[];
|
|
|
|
|
}): Promise<void> {
|
|
|
|
|
const sections: string[] = [];
|
Partial bracket scoring, code review fixes, and double-chance logic (#156)
## Partial bracket scoring
- `processMatchResult`: new exported function that scores a single match
immediately (loser → final placement, winner → provisional floor).
Called from `set-winner` and `set-round-winners` so points are awarded
as soon as a winner is set, before the full round is complete.
- `set-winner`: passes `eventName` to `processMatchResult`.
- `set-round-winners`: batches side effects — calls `recalculateAffectedLeagues`
and `updateProbabilitiesAfterResult` once after the loop instead of per-match
(`skipSideEffects: true` per match).
## Code review fixes
- **ROUND_CONFIG** (S1): extracted a `RoundScoringConfig` lookup table +
`getRoundConfig()` helper, eliminating three parallel `if/else` chains in
`processPlayoffEvent`, `processMatchResult`, and `getGuaranteedMinimumPosition`.
AFL template overrides live in `TEMPLATE_ROUND_CONFIG` with an explanatory
comment about why the `bracketTemplateId` guard is required.
- **skipSideEffects** (C2): new param on `processMatchResult`; bracket server
uses it to batch standings/probability recalc in `set-round-winners`.
- **eventName** (W1): passed through `processMatchResult` → `recalculateAffectedLeagues`.
- **Round validation** (W2): `set-round-winners` now guards `match.round === round`
before processing each assignment.
- **Comments** (C3/S3/W3): added notes on non-scoring loser assumption,
`isScoring ?? true` default, and AFL Semi-Finals template requirement.
## PlayoffBracket eliminated-teams fix + tests
- Fixed `computeEliminatedByRound` to track participant *appearances* (not just
wins), so AFL QF losers who advance to Semi-Finals via double-chance are
correctly excluded from the QF eliminated list.
- Extracted the logic as an exported pure function for testability.
- Added 4 tests: standard elimination, AFL QF loser → SF win, AFL QF loser →
SF loss, and normal advancement not protecting a later loser.
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 10:50:30 -07:00
|
|
|
|
2026-03-17 11:16:36 -07:00
|
|
|
// Header: "Sport Name — Event Name"
|
|
|
|
|
if (sportName || eventName) {
|
|
|
|
|
const parts = [sportName, eventName].filter(Boolean);
|
|
|
|
|
sections.push(`**${parts.join(" — ")}**`);
|
Partial bracket scoring, code review fixes, and double-chance logic (#156)
## Partial bracket scoring
- `processMatchResult`: new exported function that scores a single match
immediately (loser → final placement, winner → provisional floor).
Called from `set-winner` and `set-round-winners` so points are awarded
as soon as a winner is set, before the full round is complete.
- `set-winner`: passes `eventName` to `processMatchResult`.
- `set-round-winners`: batches side effects — calls `recalculateAffectedLeagues`
and `updateProbabilitiesAfterResult` once after the loop instead of per-match
(`skipSideEffects: true` per match).
## Code review fixes
- **ROUND_CONFIG** (S1): extracted a `RoundScoringConfig` lookup table +
`getRoundConfig()` helper, eliminating three parallel `if/else` chains in
`processPlayoffEvent`, `processMatchResult`, and `getGuaranteedMinimumPosition`.
AFL template overrides live in `TEMPLATE_ROUND_CONFIG` with an explanatory
comment about why the `bracketTemplateId` guard is required.
- **skipSideEffects** (C2): new param on `processMatchResult`; bracket server
uses it to batch standings/probability recalc in `set-round-winners`.
- **eventName** (W1): passed through `processMatchResult` → `recalculateAffectedLeagues`.
- **Round validation** (W2): `set-round-winners` now guards `match.round === round`
before processing each assignment.
- **Comments** (C3/S3/W3): added notes on non-scoring loser assumption,
`isScoring ?? true` default, and AFL Semi-Finals template requirement.
## PlayoffBracket eliminated-teams fix + tests
- Fixed `computeEliminatedByRound` to track participant *appearances* (not just
wins), so AFL QF losers who advance to Semi-Finals via double-chance are
correctly excluded from the QF eliminated list.
- Extracted the logic as an exported pure function for testability.
- Added 4 tests: standard elimination, AFL QF loser → SF win, AFL QF loser →
SF loss, and normal advancement not protecting a later loser.
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 10:50:30 -07:00
|
|
|
}
|
2026-03-17 11:16:36 -07:00
|
|
|
|
2026-03-19 15:52:57 -07:00
|
|
|
// Scored matches section — only show matches where at least one manager
|
|
|
|
|
// (fantasy team owner) scored Brackt points or had a team eliminated.
|
|
|
|
|
const relevantMatches = scoredMatches?.filter(
|
|
|
|
|
(m) => m.winnerUsername !== undefined || m.loserUsername !== undefined
|
|
|
|
|
);
|
|
|
|
|
if (relevantMatches && relevantMatches.length > 0) {
|
2026-03-17 12:34:10 -07:00
|
|
|
sections.push("\n**Scored Matches**");
|
2026-03-19 15:52:57 -07:00
|
|
|
for (const match of relevantMatches) {
|
2026-05-15 10:06:54 -07:00
|
|
|
const winnerManagerLabel = match.winnerDiscordUserId
|
|
|
|
|
? `<@${match.winnerDiscordUserId}>`
|
|
|
|
|
: match.winnerUsername
|
|
|
|
|
? escapeMarkdown(match.winnerUsername)
|
|
|
|
|
: undefined;
|
|
|
|
|
const loserManagerLabel = match.loserDiscordUserId
|
|
|
|
|
? `<@${match.loserDiscordUserId}>`
|
|
|
|
|
: match.loserUsername
|
|
|
|
|
? escapeMarkdown(match.loserUsername)
|
|
|
|
|
: undefined;
|
|
|
|
|
const winnerLabel = winnerManagerLabel
|
|
|
|
|
? `${escapeMarkdown(match.winnerName)} (${winnerManagerLabel})`
|
2026-03-19 15:52:57 -07:00
|
|
|
: escapeMarkdown(match.winnerName);
|
2026-05-15 10:06:54 -07:00
|
|
|
const loserLabel = loserManagerLabel
|
|
|
|
|
? `${escapeMarkdown(match.loserName)} (${loserManagerLabel})`
|
2026-03-19 15:52:57 -07:00
|
|
|
: escapeMarkdown(match.loserName);
|
|
|
|
|
sections.push(`• **${winnerLabel}** def. ${loserLabel}`);
|
2026-03-17 11:16:36 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 20:45:15 -07:00
|
|
|
const isTied = buildTiedRankChecker(standings.map((s) => s.rank));
|
|
|
|
|
const rankLabel = (rank: number) => (isTied(rank) ? `T${rank}` : `${rank}`);
|
|
|
|
|
|
2026-03-19 15:52:57 -07:00
|
|
|
// Standings changes section — show teams whose points or rank changed.
|
|
|
|
|
const changedTeams = standings.filter((s) => {
|
|
|
|
|
const prevPoints = previousStandings.get(s.teamId);
|
|
|
|
|
const pointsChanged = prevPoints !== undefined && prevPoints !== s.totalPoints;
|
|
|
|
|
const prevRank = previousRanks?.get(s.teamId);
|
|
|
|
|
const rankChanged = prevRank !== undefined && prevRank !== s.rank;
|
|
|
|
|
return pointsChanged || rankChanged;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (changedTeams.length > 0) {
|
|
|
|
|
sections.push("\n**Standings Changes**");
|
|
|
|
|
for (const s of changedTeams) {
|
2026-03-27 20:45:15 -07:00
|
|
|
const rankPrefix = rankLabel(s.rank);
|
2026-03-19 15:52:57 -07:00
|
|
|
const prevPoints = previousStandings.get(s.teamId);
|
|
|
|
|
let pointDelta = "";
|
|
|
|
|
if (prevPoints !== undefined && prevPoints !== s.totalPoints) {
|
|
|
|
|
const diff = Math.round(s.totalPoints - prevPoints);
|
|
|
|
|
const sign = diff > 0 ? "+" : "";
|
|
|
|
|
pointDelta = ` **(${sign}${diff} pts)**`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let rankDelta = "";
|
|
|
|
|
if (previousRanks) {
|
|
|
|
|
const prevRank = previousRanks.get(s.teamId);
|
|
|
|
|
if (prevRank !== undefined && prevRank !== s.rank) {
|
|
|
|
|
const moved = prevRank - s.rank; // positive = moved up
|
|
|
|
|
rankDelta = moved > 0 ? ` ↑${moved}` : ` ↓${Math.abs(moved)}`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const escapedName = escapeMarkdown(s.teamName);
|
2026-05-15 10:06:54 -07:00
|
|
|
const managerLabel = s.discordUserId
|
|
|
|
|
? `<@${s.discordUserId}>`
|
|
|
|
|
: s.username
|
|
|
|
|
? escapeMarkdown(s.username)
|
|
|
|
|
: undefined;
|
|
|
|
|
const label = managerLabel ? `${escapedName} (${managerLabel})` : escapedName;
|
2026-03-27 20:45:15 -07:00
|
|
|
sections.push(`${rankPrefix}\\. ${label} — ${Math.round(s.totalPoints)} pts${pointDelta}${rankDelta}`);
|
2026-03-17 11:16:36 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const MAX_DESCRIPTION = 4096;
|
|
|
|
|
let description = sections.join("\n");
|
|
|
|
|
if (description.length > MAX_DESCRIPTION) {
|
|
|
|
|
description = description.slice(0, MAX_DESCRIPTION - 3) + "...";
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-15 10:06:54 -07:00
|
|
|
// Collect Discord user IDs of all opted-in managers appearing in this notification.
|
|
|
|
|
const pingUserIds = new Set<string>();
|
|
|
|
|
for (const s of changedTeams) {
|
|
|
|
|
if (s.discordUserId) pingUserIds.add(s.discordUserId);
|
|
|
|
|
}
|
|
|
|
|
for (const m of relevantMatches ?? []) {
|
|
|
|
|
if (m.winnerDiscordUserId) pingUserIds.add(m.winnerDiscordUserId);
|
|
|
|
|
if (m.loserDiscordUserId) pingUserIds.add(m.loserDiscordUserId);
|
|
|
|
|
}
|
|
|
|
|
const pingIds = [...pingUserIds];
|
|
|
|
|
|
|
|
|
|
const payload: DiscordWebhookPayload = {
|
2026-03-17 11:16:36 -07:00
|
|
|
embeds: [
|
|
|
|
|
{
|
|
|
|
|
title: `📊 Standings Update — ${seasonName}`,
|
|
|
|
|
description,
|
|
|
|
|
color: 0x5865f2, // Discord blurple
|
|
|
|
|
footer: { text: "brackt.com" },
|
|
|
|
|
},
|
|
|
|
|
],
|
2026-05-15 10:06:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (pingIds.length > 0) {
|
|
|
|
|
// Discord caps allowed_mentions.users at 100; slice to avoid a rejected payload.
|
|
|
|
|
const cappedIds = pingIds.slice(0, 100);
|
|
|
|
|
payload.content = cappedIds.map((id) => `<@${id}>`).join(" ");
|
|
|
|
|
payload.allowed_mentions = { parse: [], users: cappedIds };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await sendDiscordWebhook(webhookUrl, payload);
|
Partial bracket scoring, code review fixes, and double-chance logic (#156)
## Partial bracket scoring
- `processMatchResult`: new exported function that scores a single match
immediately (loser → final placement, winner → provisional floor).
Called from `set-winner` and `set-round-winners` so points are awarded
as soon as a winner is set, before the full round is complete.
- `set-winner`: passes `eventName` to `processMatchResult`.
- `set-round-winners`: batches side effects — calls `recalculateAffectedLeagues`
and `updateProbabilitiesAfterResult` once after the loop instead of per-match
(`skipSideEffects: true` per match).
## Code review fixes
- **ROUND_CONFIG** (S1): extracted a `RoundScoringConfig` lookup table +
`getRoundConfig()` helper, eliminating three parallel `if/else` chains in
`processPlayoffEvent`, `processMatchResult`, and `getGuaranteedMinimumPosition`.
AFL template overrides live in `TEMPLATE_ROUND_CONFIG` with an explanatory
comment about why the `bracketTemplateId` guard is required.
- **skipSideEffects** (C2): new param on `processMatchResult`; bracket server
uses it to batch standings/probability recalc in `set-round-winners`.
- **eventName** (W1): passed through `processMatchResult` → `recalculateAffectedLeagues`.
- **Round validation** (W2): `set-round-winners` now guards `match.round === round`
before processing each assignment.
- **Comments** (C3/S3/W3): added notes on non-scoring loser assumption,
`isScoring ?? true` default, and AFL Semi-Finals template requirement.
## PlayoffBracket eliminated-teams fix + tests
- Fixed `computeEliminatedByRound` to track participant *appearances* (not just
wins), so AFL QF losers who advance to Semi-Finals via double-chance are
correctly excluded from the QF eliminated list.
- Extracted the logic as an exported pure function for testability.
- Added 4 tests: standard elimination, AFL QF loser → SF win, AFL QF loser →
SF loss, and normal advancement not protecting a later loser.
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 10:50:30 -07:00
|
|
|
}
|