Skip to content

Commit 6e3af34

Browse files
committed
GithubCommand: Defer all initial replies
We need to respond to Discord's chat interaction request within 3 seconds. If we don't do so, we sometimes end up in a perpetual broken state where chat commands simply stop working. This changes GithubCommand to always send out an ephemeral initial deferred reply, which then either gets deleted and replaced with the actual reply or edited when something goes wrong. We need to delete the initial deferred reply, since the ephemeral status of a message cannot be changed with `.editReply()`.
1 parent 0cf0992 commit 6e3af34

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/commands/githubCommand.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ export class GithubCommand extends Command {
131131
}
132132

133133
override async handleCommand(interaction: ChatInputCommandInteraction): Promise<void> {
134+
await interaction.deferReply({ ephemeral: true });
135+
134136
const url = interaction.options.getString("url");
135137
const repositoryName = interaction.options.getString("repository");
136138
const number = interaction.options.getNumber("number");
@@ -148,6 +150,7 @@ export class GithubCommand extends Command {
148150
);
149151

150152
if (result) {
153+
await interaction.deleteReply();
151154
await interaction.reply({ embeds: [result] });
152155
return;
153156
}
@@ -161,6 +164,7 @@ export class GithubCommand extends Command {
161164
const result = await embedFromIssueOrPull(await githubAPI.getIssueOrPull(number, repository));
162165

163166
if (result) {
167+
await interaction.deleteReply();
164168
await interaction.reply({ embeds: [result] });
165169
return;
166170
}
@@ -172,15 +176,15 @@ export class GithubCommand extends Command {
172176
);
173177

174178
if (result) {
179+
await interaction.deleteReply();
175180
await interaction.reply({ embeds: [result] });
176181
return;
177182
}
178183
}
179184

180185
const sadcaret = await getSadCaret(interaction);
181-
await interaction.reply({
186+
await interaction.editReply({
182187
content: `No matching issues or pull requests found ${sadcaret ?? ":^("}`,
183-
ephemeral: true,
184188
});
185189
}
186190
}
@@ -202,6 +206,8 @@ export class ReviewListCommand extends Command {
202206
}
203207

204208
override async handleCommand(interaction: ChatInputCommandInteraction): Promise<void> {
209+
await interaction.deferReply({ ephemeral: true });
210+
205211
const repositoryName = interaction.options.getString("repository");
206212
const unparsedNumbers = interaction.options.getString("numbers");
207213

@@ -217,11 +223,10 @@ export class ReviewListCommand extends Command {
217223
}
218224

219225
if (unparsedNumbers === null) {
220-
await interaction.reply({
226+
await interaction.editReply({
221227
content: `No matching issues or pull requests found ${
222228
(await getSadCaret(interaction)) ?? ":^("
223229
}`,
224-
ephemeral: true,
225230
});
226231
return undefined;
227232
}
@@ -231,11 +236,10 @@ export class ReviewListCommand extends Command {
231236
);
232237

233238
if (numbers.length === 0) {
234-
await interaction.reply({
239+
await interaction.editReply({
235240
content: `No numbers found in the PR list text '${unparsedNumbers}' ${
236241
(await getSadCaret(interaction)) ?? ":^("
237242
} `,
238-
ephemeral: true,
239243
});
240244
return undefined;
241245
}
@@ -248,19 +252,17 @@ export class ReviewListCommand extends Command {
248252
);
249253
const failedDescriptions = descriptions.filter(({ description }) => description === undefined);
250254
if (failedDescriptions.length !== 0) {
251-
await interaction.reply({
255+
await interaction.editReply({
252256
content: `No matching issues or pull requests found for the numbers ${failedDescriptions
253257
.map(({ number }) => number)
254258
.join(", ")} ${(await getSadCaret(interaction)) ?? ":^("} `,
255-
ephemeral: true,
256259
});
257260
return undefined;
258261
}
259262

260263
const descriptionList = descriptions.map(({ description }) => description).join("\n");
261264

262-
await interaction.reply({
263-
content: descriptionList,
264-
});
265+
await interaction.deleteReply();
266+
await interaction.reply({ content: descriptionList });
265267
}
266268
}

0 commit comments

Comments
 (0)