From 246e93abe92bcecf292ff9dc96b6ce40babfb09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Dr=C3=B6ge?= Date: Tue, 12 Dec 2023 09:26:41 +0100 Subject: [PATCH 1/3] QuoteCommand: Fetch the message through the interaction's channel Instead of trying to fetch a message with the ID of the application command (?) just to then use it to get to its channel, we can just use the channel on our interaction --- src/commands/quoteCommand.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/commands/quoteCommand.ts b/src/commands/quoteCommand.ts index c875576f..c6b32497 100644 --- a/src/commands/quoteCommand.ts +++ b/src/commands/quoteCommand.ts @@ -159,13 +159,10 @@ export class QuoteCommand extends Command { }; } - const originalMessage = await interaction.channel?.messages.fetch(interaction.commandId); - if (!originalMessage) return; - // Option 3b: The quote's message ID was given try { - const message = await originalMessage.channel.messages.fetch(argument); - if (message.guild == null) return; + const message = await interaction.channel?.messages.fetch(argument); + if (message?.guild == null) return; return { guildId: message.guild.id, channelId: message.channel.id, From 73b91a03d5a7916ee7830407e44614fdb6d26853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Dr=C3=B6ge?= Date: Tue, 12 Dec 2023 09:33:01 +0100 Subject: [PATCH 2/3] QuoteCommand: Don't limit the length of guild/channel/message IDs New message IDs can be 19 characters long, and they may grow up to 2^64-1 (20 characters) in the future. --- src/commands/quoteCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/quoteCommand.ts b/src/commands/quoteCommand.ts index c6b32497..bba28e88 100644 --- a/src/commands/quoteCommand.ts +++ b/src/commands/quoteCommand.ts @@ -24,7 +24,7 @@ import Command from "./command"; export class QuoteCommand extends Command { private readonly messageLinkRegex: RegExp = - /https:\/\/(?:(?:ptb|canary)\.)?discord\.com\/channels\/(?[0-9]{17,18})\/(?[0-9]{17,18})\/(?[0-9]{17,18})/; + /https:\/\/(?:(?:ptb|canary)\.)?discord\.com\/channels\/(?\d*)\/(?\d*)\/(?\d*)$/; override data() { if (!QUOTE_ROLE_ID) return []; From 3ecf72c200450f5fa05b1ec1be6b8940b9cb782a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Dr=C3=B6ge?= Date: Fri, 15 Dec 2023 13:17:58 +0100 Subject: [PATCH 3/3] QuoteCommand: Wrap pull request creation in a try-catch The plugin will actually throw `Error`s for a lot of failure states, which weren't caught before --- src/commands/quoteCommand.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/commands/quoteCommand.ts b/src/commands/quoteCommand.ts index bba28e88..15d64167 100644 --- a/src/commands/quoteCommand.ts +++ b/src/commands/quoteCommand.ts @@ -100,11 +100,16 @@ export class QuoteCommand extends Command { }); const commandIssuerNick = await this.getAuthorNick(guild, interaction.user); - const pullRequestNumber = await githubAPI.openFortunesPullRequest( - fortunes, - commandIssuerNick, - nickname - ); + let pullRequestNumber; + try { + pullRequestNumber = await githubAPI.openFortunesPullRequest( + fortunes, + commandIssuerNick, + nickname + ); + } catch (e) { + console.trace(e); + } if (pullRequestNumber == undefined) { const sadcaret = await getSadCaret(interaction);