Skip to content

Commit bd1aa26

Browse files
committed
GithubCommand: Edit initial reply if successful
Making the initial deferred reply ephemeral caused the follow-up messages to show an ugly "Message could not be loaded" at the top, since the ephemeral message was deleted. And even if we didn't delete it, other users would not be able to load it. This changes the initial reply to be visible to everyone and get edited on success. On failure, the initial reply is deleted again and a follow-up ephemeral message is posted to the user.
1 parent e8e50a6 commit bd1aa26

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/commands/githubCommand.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
type TextBasedChannel,
1313
SlashCommandStringOption,
1414
} from "discord.js";
15+
import { MessageFlags } from "discord-api-types/v10";
1516
import githubAPI, { type Repository, LADYBIRD_REPO } from "@/apis/githubAPI";
1617
import { embedFromIssueOrPull } from "@/util/embedFromIssueOrPull";
1718
import { getSadCaret } from "@/util/emoji";
@@ -131,7 +132,7 @@ export class GithubCommand extends Command {
131132
}
132133

133134
override async handleCommand(interaction: ChatInputCommandInteraction): Promise<void> {
134-
await interaction.deferReply({ ephemeral: true });
135+
await interaction.deferReply();
135136

136137
const url = interaction.options.getString("url");
137138
const repositoryName = interaction.options.getString("repository");
@@ -150,8 +151,7 @@ export class GithubCommand extends Command {
150151
);
151152

152153
if (result) {
153-
await interaction.deleteReply();
154-
await interaction.followUp({ embeds: [result] });
154+
await interaction.editReply({ embeds: [result] });
155155
return;
156156
}
157157
}
@@ -164,8 +164,7 @@ export class GithubCommand extends Command {
164164
const result = await embedFromIssueOrPull(await githubAPI.getIssueOrPull(number, repository));
165165

166166
if (result) {
167-
await interaction.deleteReply();
168-
await interaction.followUp({ embeds: [result] });
167+
await interaction.editReply({ embeds: [result] });
169168
return;
170169
}
171170
}
@@ -176,15 +175,16 @@ export class GithubCommand extends Command {
176175
);
177176

178177
if (result) {
179-
await interaction.deleteReply();
180-
await interaction.followUp({ embeds: [result] });
178+
await interaction.editReply({ embeds: [result] });
181179
return;
182180
}
183181
}
184182

183+
await interaction.deleteReply();
185184
const sadcaret = await getSadCaret(interaction);
186-
await interaction.editReply({
185+
await interaction.followUp({
187186
content: `No matching issues or pull requests found ${sadcaret ?? ":^("}`,
187+
flags: MessageFlags.Ephemeral,
188188
});
189189
}
190190
}
@@ -206,7 +206,7 @@ export class ReviewListCommand extends Command {
206206
}
207207

208208
override async handleCommand(interaction: ChatInputCommandInteraction): Promise<void> {
209-
await interaction.deferReply({ ephemeral: true });
209+
await interaction.deferReply();
210210

211211
const repositoryName = interaction.options.getString("repository");
212212
const unparsedNumbers = interaction.options.getString("numbers");
@@ -223,10 +223,12 @@ export class ReviewListCommand extends Command {
223223
}
224224

225225
if (unparsedNumbers === null) {
226-
await interaction.editReply({
226+
await interaction.deleteReply();
227+
await interaction.followUp({
227228
content: `No matching issues or pull requests found ${
228229
(await getSadCaret(interaction)) ?? ":^("
229230
}`,
231+
flags: MessageFlags.Ephemeral,
230232
});
231233
return undefined;
232234
}
@@ -236,10 +238,12 @@ export class ReviewListCommand extends Command {
236238
);
237239

238240
if (numbers.length === 0) {
239-
await interaction.editReply({
241+
await interaction.deleteReply();
242+
await interaction.followUp({
240243
content: `No numbers found in the PR list text '${unparsedNumbers}' ${
241244
(await getSadCaret(interaction)) ?? ":^("
242245
} `,
246+
flags: MessageFlags.Ephemeral,
243247
});
244248
return undefined;
245249
}
@@ -252,17 +256,18 @@ export class ReviewListCommand extends Command {
252256
);
253257
const failedDescriptions = descriptions.filter(({ description }) => description === undefined);
254258
if (failedDescriptions.length !== 0) {
255-
await interaction.editReply({
259+
await interaction.deleteReply();
260+
await interaction.followUp({
256261
content: `No matching issues or pull requests found for the numbers ${failedDescriptions
257262
.map(({ number }) => number)
258263
.join(", ")} ${(await getSadCaret(interaction)) ?? ":^("} `,
264+
flags: MessageFlags.Ephemeral,
259265
});
260266
return undefined;
261267
}
262268

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

265-
await interaction.deleteReply();
266-
await interaction.followUp({ content: descriptionList });
271+
await interaction.editReply({ content: descriptionList });
267272
}
268273
}

0 commit comments

Comments
 (0)