Skip to content

Commit 2ceed7c

Browse files
feat: add ephemeral to bot message (#67)
1 parent f5dbfcf commit 2ceed7c

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

src/modules/quoiFeur/quoiFeur.helpers.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@ export const addQuoiFeurToChannel = async (interaction: ChatInputCommandInteract
5252

5353
const channels = await cache.get('quoiFeurChannels', []);
5454
if (channels.includes(channel.id)) {
55-
await interaction.reply('Quoi-feur is already enabled in this channel');
55+
await interaction.reply({
56+
content: 'Quoi-feur is already enabled in this channel',
57+
ephemeral: true,
58+
});
5659
return;
5760
}
5861

5962
await cache.set('quoiFeurChannels', [...channels, channel.id]);
60-
await interaction.reply('Quoi-feur enabled in this channel');
63+
await interaction.reply({ content: 'Quoi-feur enabled in this channel', ephemeral: true });
6164
};
6265

6366
export const removeQuoiFeurFromChannel = async (interaction: ChatInputCommandInteraction) => {
@@ -66,15 +69,18 @@ export const removeQuoiFeurFromChannel = async (interaction: ChatInputCommandInt
6669

6770
const channels = await cache.get('quoiFeurChannels', []);
6871
if (!channels.includes(channel.id)) {
69-
await interaction.reply('Quoi-feur is not enabled in this channel');
72+
await interaction.reply({
73+
content: 'Quoi-feur is not enabled in this channel',
74+
ephemeral: true,
75+
});
7076
return;
7177
}
7278

7379
await cache.set(
7480
'quoiFeurChannels',
7581
channels.filter((channelId) => channelId !== channel.id),
7682
);
77-
await interaction.reply('Quoi-feur disabled in this channel');
83+
await interaction.reply({ content: 'Quoi-feur disabled in this channel', ephemeral: true });
7884
};
7985

8086
export const cleanCacheOnChannelDelete = async (

src/modules/quoiFeur/quoiFeur.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export const quoiFeur: BotModule = {
1515
.setName('quoi-feur')
1616
.setDescription('Manage quoi-feur game in the channel')
1717
.addSubcommand((subcommand) =>
18-
subcommand.setName('add').setDescription('Add the quoi-feur game to the channel'),
18+
subcommand.setName('enable').setDescription('Enable the quoi-feur game in the channel'),
1919
)
2020
.addSubcommand((subcommand) =>
21-
subcommand.setName('remove').setDescription('Remove the quoi-feur game from the channel'),
21+
subcommand.setName('disable').setDescription('Disable the quoi-feur game in the channel'),
2222
)
2323
.toJSON(),
2424
handler: {

src/modules/recurringMessage/recurringMessage.helpers.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const isFrequency = (frequency: string): frequency is Frequency => {
3434

3535
export const hasPermission = (interaction: ChatInputCommandInteraction) => {
3636
if (!isModo(interaction.member)) {
37-
void interaction.reply('You are not allowed to use this command');
37+
void interaction.reply({ content: 'You are not allowed to use this command', ephemeral: true });
3838
return false;
3939
}
4040
return true;
@@ -67,22 +67,20 @@ export const addRecurringMessage = async (interaction: ChatInputCommandInteracti
6767
const channelId = interaction.channelId;
6868
const frequency = interaction.options.getString('frequency', true);
6969
if (!isFrequency(frequency)) {
70-
await interaction.reply(`${frequency} is not a valid frequency`);
70+
await interaction.reply({ content: `${frequency} is not a valid frequency`, ephemeral: true });
7171
return;
7272
}
7373
const message = interaction.options.getString('message', true);
7474

75-
const displayIdInMessage = `\n (id: ${jobId})`;
76-
const jobMessage = message + displayIdInMessage;
77-
78-
if (jobMessage.length > MAX_MESSAGE_LENGTH) {
79-
await interaction.reply(
80-
`Message is too long (max ${MAX_MESSAGE_LENGTH - displayIdInMessage.length} characters)`,
81-
);
75+
if (message.length > MAX_MESSAGE_LENGTH) {
76+
await interaction.reply({
77+
content: `Message is too long (max ${MAX_MESSAGE_LENGTH} characters)`,
78+
ephemeral: true,
79+
});
8280
return;
8381
}
8482

85-
const job = createRecurringMessage(interaction.client, channelId, frequency, jobMessage);
83+
const job = createRecurringMessage(interaction.client, channelId, frequency, message);
8684
job.start();
8785

8886
inMemoryJobList.push({ id: jobId, job });
@@ -93,7 +91,10 @@ export const addRecurringMessage = async (interaction: ChatInputCommandInteracti
9391
{ id: jobId, channelId, frequency, message },
9492
]);
9593

96-
await interaction.reply(`Recurring message added ${frequencyDisplay[frequency]}`);
94+
await interaction.reply({
95+
content: `Recurring message added ${frequencyDisplay[frequency]}`,
96+
ephemeral: true,
97+
});
9798
};
9899

99100
export const removeRecurringMessage = async (interaction: ChatInputCommandInteraction) => {
@@ -107,20 +108,20 @@ export const removeRecurringMessage = async (interaction: ChatInputCommandIntera
107108

108109
const job = inMemoryJobList.find(({ id }) => id === jobId)?.job;
109110
if (!job) {
110-
await interaction.reply('Recurring message not found');
111+
await interaction.reply({ content: 'Recurring message not found', ephemeral: true });
111112
return;
112113
}
113114

114115
job.stop();
115116

116-
await interaction.reply('Recurring message removed');
117+
await interaction.reply({ content: 'Recurring message removed', ephemeral: true });
117118
};
118119

119120
export const listRecurringMessages = async (interaction: ChatInputCommandInteraction) => {
120121
const recurringMessages = await cache.get('recurringMessages', []);
121122

122123
if (recurringMessages.length === 0) {
123-
await interaction.reply('No recurring message found');
124+
await interaction.reply({ content: 'No recurring message found', ephemeral: true });
124125
return;
125126
}
126127

@@ -159,7 +160,7 @@ export const listRecurringMessages = async (interaction: ChatInputCommandInterac
159160
};
160161
});
161162

162-
await interaction.reply({ embeds });
163+
await interaction.reply({ embeds, ephemeral: true });
163164
};
164165

165166
export const relaunchRecurringMessages = async (client: Client<true>) => {

0 commit comments

Comments
 (0)