Codex commited on
Commit ·
61312e4
1
Parent(s): 240ab85
Harden baseball chart interaction fallback
Browse files- src/index.js +20 -2
- src/matchups.js +25 -6
src/index.js
CHANGED
|
@@ -180,7 +180,15 @@ async function main() {
|
|
| 180 |
try {
|
| 181 |
if (interaction.isChatInputCommand()) {
|
| 182 |
if (shouldDeferImmediately(interaction.commandName)) {
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
}
|
| 185 |
auditLog('command_start', {
|
| 186 |
command: interaction.commandName,
|
|
@@ -1595,7 +1603,7 @@ async function handleMatchupCommand(interaction, config, commandName) {
|
|
| 1595 |
}
|
| 1596 |
|
| 1597 |
async function handleBaseballChartCommand(interaction, config, commandName) {
|
| 1598 |
-
if (!interaction.deferred && !interaction.replied) {
|
| 1599 |
await interaction.deferReply();
|
| 1600 |
}
|
| 1601 |
|
|
@@ -1799,6 +1807,16 @@ async function handleBaseballChartCommand(interaction, config, commandName) {
|
|
| 1799 |
}
|
| 1800 |
|
| 1801 |
async function finalizeDeferredInteraction(interaction, payload) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1802 |
try {
|
| 1803 |
await interaction.editReply(payload);
|
| 1804 |
} catch (error) {
|
|
|
|
| 180 |
try {
|
| 181 |
if (interaction.isChatInputCommand()) {
|
| 182 |
if (shouldDeferImmediately(interaction.commandName)) {
|
| 183 |
+
try {
|
| 184 |
+
await interaction.deferReply();
|
| 185 |
+
} catch (error) {
|
| 186 |
+
if (error?.code === 10062 || error?.code === 10008) {
|
| 187 |
+
interaction.__ackFailed = true;
|
| 188 |
+
} else {
|
| 189 |
+
throw error;
|
| 190 |
+
}
|
| 191 |
+
}
|
| 192 |
}
|
| 193 |
auditLog('command_start', {
|
| 194 |
command: interaction.commandName,
|
|
|
|
| 1603 |
}
|
| 1604 |
|
| 1605 |
async function handleBaseballChartCommand(interaction, config, commandName) {
|
| 1606 |
+
if (!interaction.__ackFailed && !interaction.deferred && !interaction.replied) {
|
| 1607 |
await interaction.deferReply();
|
| 1608 |
}
|
| 1609 |
|
|
|
|
| 1807 |
}
|
| 1808 |
|
| 1809 |
async function finalizeDeferredInteraction(interaction, payload) {
|
| 1810 |
+
if (interaction.__ackFailed) {
|
| 1811 |
+
const channelPayload = {
|
| 1812 |
+
...payload,
|
| 1813 |
+
content: payload.content ?? `<@${interaction.user?.id}>`,
|
| 1814 |
+
flags: undefined,
|
| 1815 |
+
};
|
| 1816 |
+
await interaction.channel?.send?.(channelPayload).catch(() => null);
|
| 1817 |
+
return;
|
| 1818 |
+
}
|
| 1819 |
+
|
| 1820 |
try {
|
| 1821 |
await interaction.editReply(payload);
|
| 1822 |
} catch (error) {
|
src/matchups.js
CHANGED
|
@@ -724,20 +724,32 @@ function mapSlateTeams(slateRows) {
|
|
| 724 |
continue;
|
| 725 |
}
|
| 726 |
|
| 727 |
-
|
| 728 |
gamePk: row.game_pk ?? null,
|
| 729 |
opponentTeam: homeTeam,
|
| 730 |
opposingPitcherId: row.home_probable_pitcher_id ?? null,
|
| 731 |
opposingPitcherName: row.home_probable_pitcher ?? null,
|
| 732 |
opposingPitcherHand: row.home_probable_hand ?? null,
|
| 733 |
-
}
|
| 734 |
-
|
| 735 |
gamePk: row.game_pk ?? null,
|
| 736 |
opponentTeam: awayTeam,
|
| 737 |
opposingPitcherId: row.away_probable_pitcher_id ?? null,
|
| 738 |
opposingPitcherName: row.away_probable_pitcher ?? null,
|
| 739 |
opposingPitcherHand: row.away_probable_hand ?? null,
|
| 740 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 741 |
}
|
| 742 |
return lookup;
|
| 743 |
}
|
|
@@ -850,7 +862,7 @@ function firstNonBlankValue(...values) {
|
|
| 850 |
|
| 851 |
function withDefaults(row, slateLookup, options = {}) {
|
| 852 |
const team = String(row.team ?? '').trim();
|
| 853 |
-
const slate = slateLookup.get(team) ?? {};
|
| 854 |
const rosterLookup = options.rosterLookup ?? new Map();
|
| 855 |
const playerType = options.playerType ?? 'hitter';
|
| 856 |
return {
|
|
@@ -2331,13 +2343,20 @@ export class MatchupService {
|
|
| 2331 |
throw new Error(`No hitter matchup profile matched "${options.player}".`);
|
| 2332 |
}
|
| 2333 |
|
| 2334 |
-
const hitterSlate = slateLookup.get(String(hitterMatch.team ?? '').trim())
|
|
|
|
|
|
|
| 2335 |
const opposingPitcherId = String(
|
| 2336 |
firstNonBlankValue(hitterMatch.opposing_pitcher_id, hitterSlate.opposingPitcherId) ?? ''
|
| 2337 |
).trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2338 |
const opposingPitcherName = firstNonBlankValue(
|
| 2339 |
hitterMatch.opposing_pitcher_name,
|
| 2340 |
hitterSlate.opposingPitcherName,
|
|
|
|
| 2341 |
);
|
| 2342 |
const opposingPitcherHand = firstNonBlankValue(
|
| 2343 |
hitterMatch.opposing_pitcher_hand,
|
|
|
|
| 724 |
continue;
|
| 725 |
}
|
| 726 |
|
| 727 |
+
const awayEntry = {
|
| 728 |
gamePk: row.game_pk ?? null,
|
| 729 |
opponentTeam: homeTeam,
|
| 730 |
opposingPitcherId: row.home_probable_pitcher_id ?? null,
|
| 731 |
opposingPitcherName: row.home_probable_pitcher ?? null,
|
| 732 |
opposingPitcherHand: row.home_probable_hand ?? null,
|
| 733 |
+
};
|
| 734 |
+
const homeEntry = {
|
| 735 |
gamePk: row.game_pk ?? null,
|
| 736 |
opponentTeam: awayTeam,
|
| 737 |
opposingPitcherId: row.away_probable_pitcher_id ?? null,
|
| 738 |
opposingPitcherName: row.away_probable_pitcher ?? null,
|
| 739 |
opposingPitcherHand: row.away_probable_hand ?? null,
|
| 740 |
+
};
|
| 741 |
+
|
| 742 |
+
lookup.set(awayTeam, awayEntry);
|
| 743 |
+
lookup.set(homeTeam, homeEntry);
|
| 744 |
+
|
| 745 |
+
const normalizedAwayTeam = normalizeTeam(awayTeam);
|
| 746 |
+
const normalizedHomeTeam = normalizeTeam(homeTeam);
|
| 747 |
+
if (normalizedAwayTeam) {
|
| 748 |
+
lookup.set(normalizedAwayTeam, awayEntry);
|
| 749 |
+
}
|
| 750 |
+
if (normalizedHomeTeam) {
|
| 751 |
+
lookup.set(normalizedHomeTeam, homeEntry);
|
| 752 |
+
}
|
| 753 |
}
|
| 754 |
return lookup;
|
| 755 |
}
|
|
|
|
| 862 |
|
| 863 |
function withDefaults(row, slateLookup, options = {}) {
|
| 864 |
const team = String(row.team ?? '').trim();
|
| 865 |
+
const slate = slateLookup.get(team) ?? slateLookup.get(normalizeTeam(team)) ?? {};
|
| 866 |
const rosterLookup = options.rosterLookup ?? new Map();
|
| 867 |
const playerType = options.playerType ?? 'hitter';
|
| 868 |
return {
|
|
|
|
| 2343 |
throw new Error(`No hitter matchup profile matched "${options.player}".`);
|
| 2344 |
}
|
| 2345 |
|
| 2346 |
+
const hitterSlate = slateLookup.get(String(hitterMatch.team ?? '').trim())
|
| 2347 |
+
?? slateLookup.get(normalizeTeam(hitterMatch.team))
|
| 2348 |
+
?? {};
|
| 2349 |
const opposingPitcherId = String(
|
| 2350 |
firstNonBlankValue(hitterMatch.opposing_pitcher_id, hitterSlate.opposingPitcherId) ?? ''
|
| 2351 |
).trim();
|
| 2352 |
+
const opposingPitcherRow = pitcherLookup.get(opposingPitcherId) ?? null;
|
| 2353 |
+
const opposingPitcherRowName = opposingPitcherRow
|
| 2354 |
+
? resolveHostedPlayerName(opposingPitcherRow, rosterLookup, 'pitcher')
|
| 2355 |
+
: null;
|
| 2356 |
const opposingPitcherName = firstNonBlankValue(
|
| 2357 |
hitterMatch.opposing_pitcher_name,
|
| 2358 |
hitterSlate.opposingPitcherName,
|
| 2359 |
+
opposingPitcherRowName,
|
| 2360 |
);
|
| 2361 |
const opposingPitcherHand = firstNonBlankValue(
|
| 2362 |
hitterMatch.opposing_pitcher_hand,
|