Skip to content

Commit f6a69eb

Browse files
committed
move suggestion management to a context action
1 parent f208cb6 commit f6a69eb

4 files changed

Lines changed: 29 additions & 20 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { ApplicationCommandType } from "discord.js";
2+
import type { Command } from "djs-slash-helper";
3+
import { createSuggestionManageButtons } from "./suggest.js";
4+
5+
export const ManageSuggestionCommand: Command<ApplicationCommandType.Message> =
6+
{
7+
name: "Manage Suggestion",
8+
default_permission: false,
9+
type: ApplicationCommandType.Message,
10+
async handle(interaction) {
11+
const row = createSuggestionManageButtons();
12+
13+
await interaction.reply({
14+
content: "Manage Suggestion",
15+
components: [row],
16+
flags: ["Ephemeral"],
17+
});
18+
},
19+
};

src/modules/suggest/suggest.command.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,7 @@ export const SuggestCommand: Command<ApplicationCommandType.ChatInput> = {
8787
new ButtonBuilder()
8888
.setCustomId(SUGGESTION_VIEW_VOTES_ID)
8989
.setStyle(ButtonStyle.Secondary)
90-
.setEmoji("👁")
9190
.setLabel("View Votes"),
92-
new ButtonBuilder()
93-
.setStyle(ButtonStyle.Secondary)
94-
.setCustomId(SUGGESTION_MANAGE_ID)
95-
.setEmoji("🎛"),
9691
);
9792
const response = await suggestionChannel.send({
9893
embeds: [embed],

src/modules/suggest/suggest.listener.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,8 @@ export const SuggestionButtonListener: EventListener = {
159159
embeds: [embed],
160160
flags: ["Ephemeral"],
161161
});
162-
} else if (interaction.customId === SUGGESTION_MANAGE_ID) {
163-
const row = createSuggestionManageButtons();
164-
165-
await interaction.reply({
166-
content: "Manage Suggestion",
167-
components: [row],
168-
flags: ["Ephemeral"],
169-
});
170162
} else if (interaction.customId === SUGGESTION_MANAGE_APPROVE_ID) {
171-
await interaction.deferReply({ flags: ["Ephemeral"] });
163+
await interaction.deferUpdate();
172164
const initialMessage = await interaction.message.fetchReference();
173165
const suggestion = await getSuggestionByMessageId(
174166
BigInt(initialMessage.id),
@@ -208,9 +200,8 @@ export const SuggestionButtonListener: EventListener = {
208200
suggestionArchive,
209201
initialMessage,
210202
);
211-
await interaction.followUp({
203+
await interaction.editReply({
212204
content: "Suggestion approved!",
213-
flags: ["Ephemeral"],
214205
});
215206
} catch (e) {
216207
console.error(e);
@@ -222,8 +213,12 @@ export const SuggestionButtonListener: EventListener = {
222213
}
223214
}
224215
} else if (interaction.customId === SUGGESTION_MANAGE_REJECT_ID) {
216+
console.debug(
217+
interaction.message.id,
218+
await interaction.message.fetchReference().then((i) => i.id),
219+
);
225220
const initialMessage = await interaction.message.fetchReference();
226-
await interaction.deferReply({ flags: ["Ephemeral"] });
221+
await interaction.deferUpdate();
227222
const suggestion = await getSuggestionByMessageId(
228223
BigInt(initialMessage.id),
229224
);
@@ -262,9 +257,8 @@ export const SuggestionButtonListener: EventListener = {
262257
suggestionArchive,
263258
initialMessage,
264259
);
265-
await interaction.followUp({
260+
await interaction.editReply({
266261
content: "Suggestion rejected!",
267-
flags: ["Ephemeral"],
268262
});
269263
} catch (e) {
270264
console.error(e);

src/modules/suggest/suggest.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import type Module from "../module.js";
2+
import { ManageSuggestionCommand } from "./manageSuggestion.command.js";
23
import { SuggestCommand } from "./suggest.command.js";
34
import { SuggestionButtonListener } from "./suggest.listener.js";
45

56
export const SuggestModule: Module = {
67
name: "suggest",
7-
commands: [SuggestCommand],
8+
commands: [SuggestCommand, ManageSuggestionCommand],
89
listeners: [SuggestionButtonListener],
910
};
1011

0 commit comments

Comments
 (0)