Skip to content

Commit 49ca3e0

Browse files
committed
Replace EPHEMERAL_FLAG constant with MessageFlags.Ephemeral across modules
- Refactored all occurrences of `EPHEMERAL_FLAG` to use `MessageFlags.Ephemeral` for better consistency with Discord.js standards. - Removed redundant `EPHEMERAL_FLAG` constant and adjusted related import statements. - Improved maintainability by directly referencing Discord.js enum for ephemeral message flags.
1 parent 8e9e561 commit 49ca3e0

16 files changed

Lines changed: 171 additions & 160 deletions

src/modules/core/set.command.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import {
88
Colors,
99
type ComponentType,
1010
GuildMember,
11+
MessageFlags,
1112
} from "discord.js";
1213
import type { Command } from "djs-slash-helper";
1314
import { type DDUser, getOrCreateUserById } from "../../store/models/DDUser.js";
1415
import { createStandardEmbed } from "../../util/embeds.js";
15-
import { EPHEMERAL_FLAG } from "../../util/message.js";
16+
1617
import { mentionIfPingable } from "../../util/users.js";
1718
import { levelForXp } from "../xp/xpRoles.util.js";
1819

@@ -121,12 +122,12 @@ export const SetCommand: Command<ApplicationCommandType.ChatInput> = {
121122
const event = await collector.next;
122123
if (event.customId === "cancel") {
123124
await event.reply({
124-
flags: EPHEMERAL_FLAG,
125+
flags: MessageFlags.Ephemeral,
125126
content: "**Cancelled**",
126127
});
127128
} else if (event.customId === "confirm") {
128129
await event.deferReply({
129-
flags: "Ephemeral",
130+
flags: MessageFlags.Ephemeral,
130131
});
131132
setter(user, value);
132133
await user.save();
@@ -142,7 +143,7 @@ export const SetCommand: Command<ApplicationCommandType.ChatInput> = {
142143
],
143144
});
144145
await event.followUp({
145-
flags: "Ephemeral",
146+
flags: MessageFlags.Ephemeral,
146147
content: "Success!",
147148
});
148149
}

src/modules/faq/faq.command.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import {
22
ApplicationCommandOptionType,
33
ApplicationCommandType,
44
type GuildMember,
5+
MessageFlags,
56
PermissionFlagsBits,
67
} from "discord.js";
78
import type { Command, ExecutableSubcommand } from "djs-slash-helper";
89
import { moduleManager } from "../../index.js";
910
import { logger } from "../../logging.js";
1011
import { FAQ } from "../../store/models/FAQ.js";
11-
import { EPHEMERAL_FLAG } from "../../util/message.js";
12+
1213
import createFaqModal from "./faq.modal.js";
1314
import { createFaqEmbed } from "./faq.util.js";
1415

@@ -46,7 +47,7 @@ const GetSubcommand: ExecutableSubcommand = {
4647
});
4748
if (faq == null) {
4849
return await interaction.reply({
49-
flags: EPHEMERAL_FLAG,
50+
flags: MessageFlags.Ephemeral,
5051
content: "No FAQ found with this name",
5152
});
5253
}
@@ -70,14 +71,14 @@ const EditSubcommand: ExecutableSubcommand = {
7071
const member = interaction.member as GuildMember;
7172
if (!member.permissions.has(PermissionFlagsBits.ManageMessages)) {
7273
return await interaction.reply({
73-
flags: EPHEMERAL_FLAG,
74+
flags: MessageFlags.Ephemeral,
7475
content: "No permission",
7576
});
7677
}
7778
const name = interaction.options.get("name")?.value as string | null;
7879
if (name == null) {
7980
return await interaction.reply({
80-
flags: EPHEMERAL_FLAG,
81+
flags: MessageFlags.Ephemeral,
8182
content: "No FAQ name provided",
8283
});
8384
}
@@ -98,7 +99,7 @@ const EditSubcommand: ExecutableSubcommand = {
9899
author: BigInt(interaction.user.id),
99100
});
100101
await response.reply({
101-
flags: EPHEMERAL_FLAG,
102+
flags: MessageFlags.Ephemeral,
102103
content: `FAQ named ${name} created`,
103104
});
104105

@@ -124,30 +125,30 @@ const DeleteSubcommand: ExecutableSubcommand = {
124125
const member = interaction.member as GuildMember;
125126
if (!member.permissions.has(PermissionFlagsBits.ManageMessages)) {
126127
return await interaction.reply({
127-
flags: EPHEMERAL_FLAG,
128+
flags: MessageFlags.Ephemeral,
128129
content: "No permission",
129130
});
130131
}
131132
const name = interaction.options.get("name")?.value as string | null;
132133
if (name == null) {
133134
return await interaction.reply({
134-
flags: EPHEMERAL_FLAG,
135+
flags: MessageFlags.Ephemeral,
135136
content: "No FAQ name provided",
136137
});
137138
}
138139

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

src/modules/information/informationMessage.command.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import {
33
type APIEmbed,
44
ApplicationCommandType,
55
ButtonBuilder,
6+
MessageFlags,
67
} from "discord.js";
78
import type { Command } from "djs-slash-helper";
89
import { config } from "../../Config.js";
910
import { logger } from "../../logging.js";
1011
import { createStandardEmbed } from "../../util/embeds.js";
11-
import { EPHEMERAL_FLAG } from "../../util/message.js";
1212
import type { CustomButton } from "./information.js";
1313

1414
function loadCustomButton(customButton: CustomButton) {
@@ -31,15 +31,15 @@ export const InformationMessageCommand: Command<ApplicationCommandType.Message>
3131
async handle(interaction) {
3232
if (!interaction.targetMessage.editable) {
3333
await interaction.reply({
34-
flags: EPHEMERAL_FLAG,
34+
flags: MessageFlags.Ephemeral,
3535
content: "I can't edit that message.",
3636
});
3737
return;
3838
}
3939

4040
if (config.informationMessage == null) {
4141
await interaction.reply({
42-
flags: EPHEMERAL_FLAG,
42+
flags: MessageFlags.Ephemeral,
4343
content: "There is no information message configured.",
4444
});
4545
return;
@@ -68,7 +68,7 @@ export const InformationMessageCommand: Command<ApplicationCommandType.Message>
6868
)}`,
6969
);
7070
await interaction.reply({
71-
flags: EPHEMERAL_FLAG,
71+
flags: MessageFlags.Ephemeral,
7272
content: "Information message set.",
7373
});
7474
},

src/modules/information/informationMessage.listener.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import {
33
type ButtonInteraction,
44
type GuildMember,
55
type Interaction,
6+
MessageFlags,
67
StringSelectMenuBuilder,
78
StringSelectMenuOptionBuilder,
89
} from "discord.js";
910
import { FAQ } from "../../store/models/FAQ.js";
1011
import { getEmoji, toAPIMessageComponentEmoji } from "../../util/emojis.js";
11-
import { EPHEMERAL_FLAG } from "../../util/message.js";
12+
1213
import { truncateTo } from "../../util/strings.js";
1314
import { createFaqEmbed } from "../faq/faq.util.js";
1415
import { getResourceEmbed } from "../learning/learning.command.js";
@@ -25,7 +26,7 @@ export const InformationButtonListener: EventListener = {
2526
interaction.customId === "learningResourcePicker"
2627
) {
2728
const resourceName = interaction.values[0];
28-
await interaction.deferReply({ flags: "Ephemeral" });
29+
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
2930
const resource = await getResource(resourceName);
3031
if (resource == null) {
3132
return; // shouldn't ever happen
@@ -39,7 +40,7 @@ export const InformationButtonListener: EventListener = {
3940

4041
await interaction.followUp({
4142
embeds: [embed],
42-
flags: EPHEMERAL_FLAG,
43+
flags: MessageFlags.Ephemeral,
4344
});
4445
return;
4546
}
@@ -72,7 +73,7 @@ export const InformationButtonListener: EventListener = {
7273
(interaction.member as GuildMember) ?? undefined,
7374
);
7475
await interaction.followUp({
75-
flags: EPHEMERAL_FLAG,
76+
flags: MessageFlags.Ephemeral,
7677
embeds: [embed],
7778
});
7879
},
@@ -102,7 +103,7 @@ async function sendLearningResourcesPicker(interaction: ButtonInteraction) {
102103
components: [
103104
new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(selectMenu),
104105
],
105-
flags: EPHEMERAL_FLAG,
106+
flags: MessageFlags.Ephemeral,
106107
withResponse: false,
107108
});
108109
}

src/modules/learning/learning.command.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
ApplicationCommandType,
44
type Client,
55
type GuildMember,
6+
MessageFlags,
67
PermissionFlagsBits,
78
type User,
89
} from "discord.js";
@@ -11,7 +12,7 @@ import { moduleManager } from "../../index.js";
1112
import { logger } from "../../logging.js";
1213
import { createStandardEmbed, standardFooter } from "../../util/embeds.js";
1314
import { getEmoji, stringifyEmoji } from "../../util/emojis.js";
14-
import { EPHEMERAL_FLAG } from "../../util/message.js";
15+
1516
import { fakeMention } from "../../util/users.js";
1617
import type { LearningResource } from "./learningResource.model.js";
1718
import {
@@ -133,12 +134,14 @@ const LearningUpdateSubcommand: ExecutableSubcommand = {
133134
const member = interaction.member as GuildMember;
134135
if (!member.permissions.has(PermissionFlagsBits.ManageMessages)) {
135136
return await interaction.reply({
136-
flags: EPHEMERAL_FLAG,
137+
flags: MessageFlags.Ephemeral,
137138
content: "No permission",
138139
});
139140
}
140141

141-
await interaction.deferReply({ flags: "Ephemeral" });
142+
await interaction.deferReply({
143+
flags: MessageFlags.Ephemeral,
144+
});
142145
await updateResourcesForCommands();
143146
await moduleManager.refreshCommands();
144147
await interaction.followUp("Updated learning resources cache");
@@ -168,7 +171,7 @@ const LearningListSubcommand: ExecutableSubcommand = {
168171
});
169172

170173
await interaction.reply({
171-
flags: EPHEMERAL_FLAG,
174+
flags: MessageFlags.Ephemeral,
172175
embeds: [embed],
173176
});
174177
},

src/modules/moderation/kick.command.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
ApplicationCommandOptionType,
33
ApplicationCommandType,
4+
MessageFlags,
45
} from "discord.js";
56
import type { Command } from "djs-slash-helper";
67
import { logger } from "../../logging.js";
@@ -68,7 +69,7 @@ export const KickCommand: Command<ApplicationCommandType.ChatInput> = {
6869
await interaction.editReply("Something went wrong!");
6970
} else {
7071
await interaction.followUp({
71-
flags: "Ephemeral",
72+
flags: MessageFlags.Ephemeral,
7273
content: "Failed to kick member!",
7374
});
7475
}

0 commit comments

Comments
 (0)