Codex commited on
Commit
c5d5563
·
1 Parent(s): b87f8d7

Defer heavy matchup commands earlier

Browse files
Files changed (1) hide show
  1. src/index.js +16 -1
src/index.js CHANGED
@@ -159,6 +159,9 @@ async function main() {
159
  userId: interaction.user.id,
160
  guildId: interaction.guildId,
161
  });
 
 
 
162
  await handleChatInput(interaction, store, config);
163
  return;
164
  }
@@ -1324,7 +1327,9 @@ async function handleSharpBoard(interaction, config, commandName) {
1324
  }
1325
 
1326
  async function handleMatchupCommand(interaction, config, commandName) {
1327
- await interaction.deferReply();
 
 
1328
 
1329
  const matchupService = interaction.client.__matchupService;
1330
  if (!config.matchups.enabled || !matchupService) {
@@ -1377,6 +1382,16 @@ async function handleMatchupCommand(interaction, config, commandName) {
1377
  }
1378
  }
1379
 
 
 
 
 
 
 
 
 
 
 
1380
  async function handleMatchupHealth(interaction, config) {
1381
  const isAdmin = await memberHasRoleName(interaction, config.adminRoleName);
1382
  if (!isAdmin) {
 
159
  userId: interaction.user.id,
160
  guildId: interaction.guildId,
161
  });
162
+ if (shouldDeferImmediately(interaction.commandName)) {
163
+ await interaction.deferReply();
164
+ }
165
  await handleChatInput(interaction, store, config);
166
  return;
167
  }
 
1327
  }
1328
 
1329
  async function handleMatchupCommand(interaction, config, commandName) {
1330
+ if (!interaction.deferred && !interaction.replied) {
1331
+ await interaction.deferReply();
1332
+ }
1333
 
1334
  const matchupService = interaction.client.__matchupService;
1335
  if (!config.matchups.enabled || !matchupService) {
 
1382
  }
1383
  }
1384
 
1385
+ function shouldDeferImmediately(commandName) {
1386
+ return [
1387
+ 'matchuphitters',
1388
+ 'matchuppitchers',
1389
+ 'playercontext',
1390
+ 'bestmatchups',
1391
+ 'teambestmatchups',
1392
+ ].includes(commandName);
1393
+ }
1394
+
1395
  async function handleMatchupHealth(interaction, config) {
1396
  const isAdmin = await memberHasRoleName(interaction, config.adminRoleName);
1397
  if (!isAdmin) {