Codex commited on
Commit ·
9a27dc9
1
Parent(s): 3bbd6f4
Fallback to follow-up for chart replies
Browse files- src/index.js +30 -12
src/index.js
CHANGED
|
@@ -1458,7 +1458,7 @@ async function handleBaseballChartCommand(interaction, config, commandName) {
|
|
| 1458 |
rows: result.rows,
|
| 1459 |
});
|
| 1460 |
const fileName = 'hr-board-chart.png';
|
| 1461 |
-
await
|
| 1462 |
embeds: [buildHrBoardChartEmbed(result, filters, fileName)],
|
| 1463 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1464 |
});
|
|
@@ -1475,7 +1475,7 @@ async function handleBaseballChartCommand(interaction, config, commandName) {
|
|
| 1475 |
overlays: result.overlays,
|
| 1476 |
});
|
| 1477 |
const fileName = 'hr-trend-chart.png';
|
| 1478 |
-
await
|
| 1479 |
embeds: [buildHrTrendEmbed(result, fileName)],
|
| 1480 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1481 |
});
|
|
@@ -1492,7 +1492,7 @@ async function handleBaseballChartCommand(interaction, config, commandName) {
|
|
| 1492 |
seriesLabel: 'HR Profile',
|
| 1493 |
});
|
| 1494 |
const fileName = 'hr-profile-radar.png';
|
| 1495 |
-
await
|
| 1496 |
embeds: [buildHrProfileEmbed(result, fileName)],
|
| 1497 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1498 |
});
|
|
@@ -1507,7 +1507,7 @@ async function handleBaseballChartCommand(interaction, config, commandName) {
|
|
| 1507 |
points: result.points,
|
| 1508 |
});
|
| 1509 |
const fileName = 'hr-value-chart.png';
|
| 1510 |
-
await
|
| 1511 |
embeds: [buildHrValueChartEmbed(result, filters, fileName)],
|
| 1512 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1513 |
});
|
|
@@ -1530,7 +1530,7 @@ async function handleBaseballChartCommand(interaction, config, commandName) {
|
|
| 1530 |
read: result.read,
|
| 1531 |
});
|
| 1532 |
const fileName = 'hr-zone-card.png';
|
| 1533 |
-
await
|
| 1534 |
embeds: [buildHrZoneEmbed(result, fileName)],
|
| 1535 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1536 |
});
|
|
@@ -1547,7 +1547,7 @@ async function handleBaseballChartCommand(interaction, config, commandName) {
|
|
| 1547 |
overlays: result.overlays,
|
| 1548 |
});
|
| 1549 |
const fileName = 'k-trend-chart.png';
|
| 1550 |
-
await
|
| 1551 |
embeds: [buildKTrendEmbed(result, fileName)],
|
| 1552 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1553 |
});
|
|
@@ -1562,7 +1562,7 @@ async function handleBaseballChartCommand(interaction, config, commandName) {
|
|
| 1562 |
rows: result.rows,
|
| 1563 |
});
|
| 1564 |
const fileName = 'k-ladder-chart.png';
|
| 1565 |
-
await
|
| 1566 |
embeds: [buildKLadderEmbed(result, fileName)],
|
| 1567 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1568 |
});
|
|
@@ -1579,7 +1579,7 @@ async function handleBaseballChartCommand(interaction, config, commandName) {
|
|
| 1579 |
seriesLabel: 'Strikeout Profile',
|
| 1580 |
});
|
| 1581 |
const fileName = 'k-profile-radar.png';
|
| 1582 |
-
await
|
| 1583 |
embeds: [buildKProfileEmbed(result, fileName)],
|
| 1584 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1585 |
});
|
|
@@ -1599,7 +1599,7 @@ async function handleBaseballChartCommand(interaction, config, commandName) {
|
|
| 1599 |
read: result.read,
|
| 1600 |
});
|
| 1601 |
const fileName = 'k-matchup-card.png';
|
| 1602 |
-
await
|
| 1603 |
embeds: [buildKMatchupEmbed(result, fileName)],
|
| 1604 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1605 |
});
|
|
@@ -1615,23 +1615,41 @@ async function handleBaseballChartCommand(interaction, config, commandName) {
|
|
| 1615 |
datasets: result.datasets,
|
| 1616 |
});
|
| 1617 |
const fileName = 'k-count-chart.png';
|
| 1618 |
-
await
|
| 1619 |
embeds: [buildKCountEmbed(result, fileName)],
|
| 1620 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1621 |
});
|
| 1622 |
return;
|
| 1623 |
}
|
| 1624 |
|
| 1625 |
-
await
|
| 1626 |
embeds: [buildErrorEmbed('Command unavailable', 'That baseball chart command is not wired up yet.')],
|
| 1627 |
});
|
| 1628 |
} catch (error) {
|
| 1629 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1630 |
embeds: [buildErrorEmbed('Chart unavailable', error.message || 'The baseball chart lookup hit an unexpected error.')],
|
| 1631 |
});
|
| 1632 |
}
|
| 1633 |
}
|
| 1634 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1635 |
function shouldDeferImmediately(commandName) {
|
| 1636 |
return [
|
| 1637 |
'matchuphitters',
|
|
|
|
| 1458 |
rows: result.rows,
|
| 1459 |
});
|
| 1460 |
const fileName = 'hr-board-chart.png';
|
| 1461 |
+
await finalizeDeferredInteraction(interaction, {
|
| 1462 |
embeds: [buildHrBoardChartEmbed(result, filters, fileName)],
|
| 1463 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1464 |
});
|
|
|
|
| 1475 |
overlays: result.overlays,
|
| 1476 |
});
|
| 1477 |
const fileName = 'hr-trend-chart.png';
|
| 1478 |
+
await finalizeDeferredInteraction(interaction, {
|
| 1479 |
embeds: [buildHrTrendEmbed(result, fileName)],
|
| 1480 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1481 |
});
|
|
|
|
| 1492 |
seriesLabel: 'HR Profile',
|
| 1493 |
});
|
| 1494 |
const fileName = 'hr-profile-radar.png';
|
| 1495 |
+
await finalizeDeferredInteraction(interaction, {
|
| 1496 |
embeds: [buildHrProfileEmbed(result, fileName)],
|
| 1497 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1498 |
});
|
|
|
|
| 1507 |
points: result.points,
|
| 1508 |
});
|
| 1509 |
const fileName = 'hr-value-chart.png';
|
| 1510 |
+
await finalizeDeferredInteraction(interaction, {
|
| 1511 |
embeds: [buildHrValueChartEmbed(result, filters, fileName)],
|
| 1512 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1513 |
});
|
|
|
|
| 1530 |
read: result.read,
|
| 1531 |
});
|
| 1532 |
const fileName = 'hr-zone-card.png';
|
| 1533 |
+
await finalizeDeferredInteraction(interaction, {
|
| 1534 |
embeds: [buildHrZoneEmbed(result, fileName)],
|
| 1535 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1536 |
});
|
|
|
|
| 1547 |
overlays: result.overlays,
|
| 1548 |
});
|
| 1549 |
const fileName = 'k-trend-chart.png';
|
| 1550 |
+
await finalizeDeferredInteraction(interaction, {
|
| 1551 |
embeds: [buildKTrendEmbed(result, fileName)],
|
| 1552 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1553 |
});
|
|
|
|
| 1562 |
rows: result.rows,
|
| 1563 |
});
|
| 1564 |
const fileName = 'k-ladder-chart.png';
|
| 1565 |
+
await finalizeDeferredInteraction(interaction, {
|
| 1566 |
embeds: [buildKLadderEmbed(result, fileName)],
|
| 1567 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1568 |
});
|
|
|
|
| 1579 |
seriesLabel: 'Strikeout Profile',
|
| 1580 |
});
|
| 1581 |
const fileName = 'k-profile-radar.png';
|
| 1582 |
+
await finalizeDeferredInteraction(interaction, {
|
| 1583 |
embeds: [buildKProfileEmbed(result, fileName)],
|
| 1584 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1585 |
});
|
|
|
|
| 1599 |
read: result.read,
|
| 1600 |
});
|
| 1601 |
const fileName = 'k-matchup-card.png';
|
| 1602 |
+
await finalizeDeferredInteraction(interaction, {
|
| 1603 |
embeds: [buildKMatchupEmbed(result, fileName)],
|
| 1604 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1605 |
});
|
|
|
|
| 1615 |
datasets: result.datasets,
|
| 1616 |
});
|
| 1617 |
const fileName = 'k-count-chart.png';
|
| 1618 |
+
await finalizeDeferredInteraction(interaction, {
|
| 1619 |
embeds: [buildKCountEmbed(result, fileName)],
|
| 1620 |
files: [buildBaseballChartAttachment(png, fileName)],
|
| 1621 |
});
|
| 1622 |
return;
|
| 1623 |
}
|
| 1624 |
|
| 1625 |
+
await finalizeDeferredInteraction(interaction, {
|
| 1626 |
embeds: [buildErrorEmbed('Command unavailable', 'That baseball chart command is not wired up yet.')],
|
| 1627 |
});
|
| 1628 |
} catch (error) {
|
| 1629 |
+
console.error('Baseball chart command failed', {
|
| 1630 |
+
command: commandName,
|
| 1631 |
+
userId: interaction.user?.id,
|
| 1632 |
+
guildId: interaction.guildId,
|
| 1633 |
+
error: serializeError(error),
|
| 1634 |
+
});
|
| 1635 |
+
await finalizeDeferredInteraction(interaction, {
|
| 1636 |
embeds: [buildErrorEmbed('Chart unavailable', error.message || 'The baseball chart lookup hit an unexpected error.')],
|
| 1637 |
});
|
| 1638 |
}
|
| 1639 |
}
|
| 1640 |
|
| 1641 |
+
async function finalizeDeferredInteraction(interaction, payload) {
|
| 1642 |
+
try {
|
| 1643 |
+
await interaction.editReply(payload);
|
| 1644 |
+
} catch (error) {
|
| 1645 |
+
if (error?.code === 10008 || error?.code === 10062) {
|
| 1646 |
+
await interaction.followUp(payload).catch(() => null);
|
| 1647 |
+
return;
|
| 1648 |
+
}
|
| 1649 |
+
throw error;
|
| 1650 |
+
}
|
| 1651 |
+
}
|
| 1652 |
+
|
| 1653 |
function shouldDeferImmediately(commandName) {
|
| 1654 |
return [
|
| 1655 |
'matchuphitters',
|