Skip to content

Commit

Permalink
/rush-duel art: match deferReply implementation with /art
Browse files Browse the repository at this point in the history
Fix #328 command timeouts
  • Loading branch information
kevinlul committed Mar 7, 2024
1 parent 22d5cda commit 6ee4fb0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/commands/rush-duel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,15 @@ export class RushDuelCommand extends AutocompletableCommand {
});
return replyLatency(reply, interaction);
}
await interaction.deferReply();
const url = videoGameIllustrationURL(card);
const hasVideoGameIllustration = await this.checkYugipediaRedirect(url, interaction);
const switcher = new ArtSwitcher(card.images, hasVideoGameIllustration ? url : null);
const reply = await switcher.reply(interaction, resultLanguage);
return replyLatency(reply, interaction);
const end = Date.now();
await switcher.editReply(interaction, resultLanguage);
// When using deferReply, editedTimestamp is null, as if the reply was never edited, so provide a best estimate
const latency = end - interaction.createdTimestamp;
return latency;
}
}

Expand Down Expand Up @@ -484,8 +488,8 @@ class ArtSwitcher {
this.labelButton.setLabel(this.label);
}

async reply(parentInteraction: ChatInputCommandInteraction, resultLanguage: Locale): Promise<Message> {
const reply = await parentInteraction.reply({ ...this.replyOptions, fetchReply: true });
async editReply(parentInteraction: ChatInputCommandInteraction, resultLanguage: Locale): Promise<Message> {
const reply = await parentInteraction.editReply(this.replyOptions);
const filter = (childInteraction: ButtonInteraction): boolean => {
this.logger.info(serialiseInteraction(parentInteraction), `click: ${childInteraction.user.id}`);
if (childInteraction.user.id === parentInteraction.user.id) {
Expand Down
2 changes: 1 addition & 1 deletion test/contract/link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe("Healthcheck for /link URLs", () => {

// Skip Discord CDN links as they are no longer accessible outside Discord after the Authenticated Attachment URL change
test.each(
Object.values(LinkCommand.links).filter(({ result }) => !result.startsWith("https://cdn.discordapp.com"))
Object.values(LinkCommand.links).filter(({ result }) => !result.startsWith("https://cdn.discordapp.com/"))
)("$name", async ({ result }) => {
for (const url of result.split("\n")) {
const response = await got(url);
Expand Down

0 comments on commit 6ee4fb0

Please sign in to comment.