Skip to content

Commit 8e9e561

Browse files
committed
Refactor ephemeral flag usage across modules
- Replaced repetitive ephemeral flag arrays with a centralized constant (`EPHEMERAL_FLAG`). - Streamlined defer and reply calls across modules to improve consistency and maintainability.
1 parent 8a6cdf9 commit 8e9e561

14 files changed

Lines changed: 151 additions & 137 deletions

src/modules/core/set.command.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import type { Command } from "djs-slash-helper";
1313
import { type DDUser, getOrCreateUserById } from "../../store/models/DDUser.js";
1414
import { createStandardEmbed } from "../../util/embeds.js";
15+
import { EPHEMERAL_FLAG } from "../../util/message.js";
1516
import { mentionIfPingable } from "../../util/users.js";
1617
import { levelForXp } from "../xp/xpRoles.util.js";
1718

@@ -120,7 +121,7 @@ export const SetCommand: Command<ApplicationCommandType.ChatInput> = {
120121
const event = await collector.next;
121122
if (event.customId === "cancel") {
122123
await event.reply({
123-
flags: ["Ephemeral"],
124+
flags: EPHEMERAL_FLAG,
124125
content: "**Cancelled**",
125126
});
126127
} else if (event.customId === "confirm") {

src/modules/faq/faq.command.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { Command, ExecutableSubcommand } from "djs-slash-helper";
88
import { moduleManager } from "../../index.js";
99
import { logger } from "../../logging.js";
1010
import { FAQ } from "../../store/models/FAQ.js";
11+
import { EPHEMERAL_FLAG } from "../../util/message.js";
1112
import createFaqModal from "./faq.modal.js";
1213
import { createFaqEmbed } from "./faq.util.js";
1314

@@ -45,7 +46,7 @@ const GetSubcommand: ExecutableSubcommand = {
4546
});
4647
if (faq == null) {
4748
return await interaction.reply({
48-
flags: ["Ephemeral"],
49+
flags: EPHEMERAL_FLAG,
4950
content: "No FAQ found with this name",
5051
});
5152
}
@@ -69,14 +70,14 @@ const EditSubcommand: ExecutableSubcommand = {
6970
const member = interaction.member as GuildMember;
7071
if (!member.permissions.has(PermissionFlagsBits.ManageMessages)) {
7172
return await interaction.reply({
72-
flags: ["Ephemeral"],
73+
flags: EPHEMERAL_FLAG,
7374
content: "No permission",
7475
});
7576
}
7677
const name = interaction.options.get("name")?.value as string | null;
7778
if (name == null) {
7879
return await interaction.reply({
79-
flags: ["Ephemeral"],
80+
flags: EPHEMERAL_FLAG,
8081
content: "No FAQ name provided",
8182
});
8283
}
@@ -97,7 +98,7 @@ const EditSubcommand: ExecutableSubcommand = {
9798
author: BigInt(interaction.user.id),
9899
});
99100
await response.reply({
100-
flags: ["Ephemeral"],
101+
flags: EPHEMERAL_FLAG,
101102
content: `FAQ named ${name} created`,
102103
});
103104

@@ -123,30 +124,30 @@ const DeleteSubcommand: ExecutableSubcommand = {
123124
const member = interaction.member as GuildMember;
124125
if (!member.permissions.has(PermissionFlagsBits.ManageMessages)) {
125126
return await interaction.reply({
126-
flags: ["Ephemeral"],
127+
flags: EPHEMERAL_FLAG,
127128
content: "No permission",
128129
});
129130
}
130131
const name = interaction.options.get("name")?.value as string | null;
131132
if (name == null) {
132133
return await interaction.reply({
133-
flags: ["Ephemeral"],
134+
flags: EPHEMERAL_FLAG,
134135
content: "No FAQ name provided",
135136
});
136137
}
137138

138139
const faq = await FAQ.findOne({ where: { name } });
139140
if (faq == null) {
140141
return await interaction.reply({
141-
flags: ["Ephemeral"],
142+
flags: EPHEMERAL_FLAG,
142143
content: "No FAQ found with this name",
143144
});
144145
}
145146
await faq.destroy();
146147
await updateChoices();
147148
await moduleManager.refreshCommands();
148149
return await interaction.reply({
149-
flags: ["Ephemeral"],
150+
flags: EPHEMERAL_FLAG,
150151
content: `FAQ named ${name} deleted`,
151152
});
152153
},

src/modules/information/informationMessage.command.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { Command } from "djs-slash-helper";
88
import { config } from "../../Config.js";
99
import { logger } from "../../logging.js";
1010
import { createStandardEmbed } from "../../util/embeds.js";
11+
import { EPHEMERAL_FLAG } from "../../util/message.js";
1112
import type { CustomButton } from "./information.js";
1213

1314
function loadCustomButton(customButton: CustomButton) {
@@ -30,15 +31,15 @@ export const InformationMessageCommand: Command<ApplicationCommandType.Message>
3031
async handle(interaction) {
3132
if (!interaction.targetMessage.editable) {
3233
await interaction.reply({
33-
flags: ["Ephemeral"],
34+
flags: EPHEMERAL_FLAG,
3435
content: "I can't edit that message.",
3536
});
3637
return;
3738
}
3839

3940
if (config.informationMessage == null) {
4041
await interaction.reply({
41-
flags: ["Ephemeral"],
42+
flags: EPHEMERAL_FLAG,
4243
content: "There is no information message configured.",
4344
});
4445
return;
@@ -67,7 +68,7 @@ export const InformationMessageCommand: Command<ApplicationCommandType.Message>
6768
)}`,
6869
);
6970
await interaction.reply({
70-
flags: ["Ephemeral"],
71+
flags: EPHEMERAL_FLAG,
7172
content: "Information message set.",
7273
});
7374
},

src/modules/information/informationMessage.listener.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from "discord.js";
99
import { FAQ } from "../../store/models/FAQ.js";
1010
import { getEmoji, toAPIMessageComponentEmoji } from "../../util/emojis.js";
11+
import { EPHEMERAL_FLAG } from "../../util/message.js";
1112
import { truncateTo } from "../../util/strings.js";
1213
import { createFaqEmbed } from "../faq/faq.util.js";
1314
import { getResourceEmbed } from "../learning/learning.command.js";
@@ -38,7 +39,7 @@ export const InformationButtonListener: EventListener = {
3839

3940
await interaction.followUp({
4041
embeds: [embed],
41-
flags: ["Ephemeral"],
42+
flags: EPHEMERAL_FLAG,
4243
});
4344
return;
4445
}
@@ -71,7 +72,7 @@ export const InformationButtonListener: EventListener = {
7172
(interaction.member as GuildMember) ?? undefined,
7273
);
7374
await interaction.followUp({
74-
flags: ["Ephemeral"],
75+
flags: EPHEMERAL_FLAG,
7576
embeds: [embed],
7677
});
7778
},
@@ -101,7 +102,7 @@ async function sendLearningResourcesPicker(interaction: ButtonInteraction) {
101102
components: [
102103
new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(selectMenu),
103104
],
104-
flags: ["Ephemeral"],
105+
flags: EPHEMERAL_FLAG,
105106
withResponse: false,
106107
});
107108
}

src/modules/learning/learning.command.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { moduleManager } from "../../index.js";
1111
import { logger } from "../../logging.js";
1212
import { createStandardEmbed, standardFooter } from "../../util/embeds.js";
1313
import { getEmoji, stringifyEmoji } from "../../util/emojis.js";
14+
import { EPHEMERAL_FLAG } from "../../util/message.js";
1415
import { fakeMention } from "../../util/users.js";
1516
import type { LearningResource } from "./learningResource.model.js";
1617
import {
@@ -132,7 +133,7 @@ const LearningUpdateSubcommand: ExecutableSubcommand = {
132133
const member = interaction.member as GuildMember;
133134
if (!member.permissions.has(PermissionFlagsBits.ManageMessages)) {
134135
return await interaction.reply({
135-
flags: ["Ephemeral"],
136+
flags: EPHEMERAL_FLAG,
136137
content: "No permission",
137138
});
138139
}
@@ -167,7 +168,7 @@ const LearningListSubcommand: ExecutableSubcommand = {
167168
});
168169

169170
await interaction.reply({
170-
flags: ["Ephemeral"],
171+
flags: EPHEMERAL_FLAG,
171172
embeds: [embed],
172173
});
173174
},

0 commit comments

Comments
 (0)