Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GithubCommand: Edit initial reply if successful #34

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions src/commands/githubCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
type TextBasedChannel,
SlashCommandStringOption,
} from "discord.js";
import { MessageFlags } from "discord-api-types/v10";
import githubAPI, { type Repository, LADYBIRD_REPO } from "@/apis/githubAPI";
import { embedFromIssueOrPull } from "@/util/embedFromIssueOrPull";
import { getSadCaret } from "@/util/emoji";
Expand Down Expand Up @@ -131,7 +132,7 @@ export class GithubCommand extends Command {
}

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

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

if (result) {
await interaction.deleteReply();
await interaction.followUp({ embeds: [result] });
await interaction.editReply({ embeds: [result] });
return;
}
}
Expand All @@ -164,8 +164,7 @@ export class GithubCommand extends Command {
const result = await embedFromIssueOrPull(await githubAPI.getIssueOrPull(number, repository));

if (result) {
await interaction.deleteReply();
await interaction.followUp({ embeds: [result] });
await interaction.editReply({ embeds: [result] });
return;
}
}
Expand All @@ -176,15 +175,16 @@ export class GithubCommand extends Command {
);

if (result) {
await interaction.deleteReply();
await interaction.followUp({ embeds: [result] });
await interaction.editReply({ embeds: [result] });
return;
}
}

await interaction.deleteReply();
const sadcaret = await getSadCaret(interaction);
await interaction.editReply({
await interaction.followUp({
content: `No matching issues or pull requests found ${sadcaret ?? ":^("}`,
flags: MessageFlags.Ephemeral,
});
}
}
Expand All @@ -206,7 +206,7 @@ export class ReviewListCommand extends Command {
}

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

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

if (unparsedNumbers === null) {
await interaction.editReply({
await interaction.deleteReply();
await interaction.followUp({
content: `No matching issues or pull requests found ${
(await getSadCaret(interaction)) ?? ":^("
}`,
flags: MessageFlags.Ephemeral,
});
return undefined;
}
Expand All @@ -236,10 +238,12 @@ export class ReviewListCommand extends Command {
);

if (numbers.length === 0) {
await interaction.editReply({
await interaction.deleteReply();
await interaction.followUp({
content: `No numbers found in the PR list text '${unparsedNumbers}' ${
(await getSadCaret(interaction)) ?? ":^("
} `,
flags: MessageFlags.Ephemeral,
});
return undefined;
}
Expand All @@ -252,17 +256,18 @@ export class ReviewListCommand extends Command {
);
const failedDescriptions = descriptions.filter(({ description }) => description === undefined);
if (failedDescriptions.length !== 0) {
await interaction.editReply({
await interaction.deleteReply();
await interaction.followUp({
content: `No matching issues or pull requests found for the numbers ${failedDescriptions
.map(({ number }) => number)
.join(", ")} ${(await getSadCaret(interaction)) ?? ":^("} `,
flags: MessageFlags.Ephemeral,
});
return undefined;
}

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

await interaction.deleteReply();
await interaction.followUp({ content: descriptionList });
await interaction.editReply({ content: descriptionList });
}
}
Loading