Skip to content

feat: add ephemeral to bot message #67

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

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
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
14 changes: 10 additions & 4 deletions src/modules/quoiFeur/quoiFeur.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ export const addQuoiFeurToChannel = async (interaction: ChatInputCommandInteract

const channels = await cache.get('quoiFeurChannels', []);
if (channels.includes(channel.id)) {
await interaction.reply('Quoi-feur is already enabled in this channel');
await interaction.reply({
content: 'Quoi-feur is already enabled in this channel',
ephemeral: true,
});
return;
}

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

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

const channels = await cache.get('quoiFeurChannels', []);
if (!channels.includes(channel.id)) {
await interaction.reply('Quoi-feur is not enabled in this channel');
await interaction.reply({
content: 'Quoi-feur is not enabled in this channel',
ephemeral: true,
});
return;
}

await cache.set(
'quoiFeurChannels',
channels.filter((channelId) => channelId !== channel.id),
);
await interaction.reply('Quoi-feur disabled in this channel');
await interaction.reply({ content: 'Quoi-feur disabled in this channel', ephemeral: true });
};

export const cleanCacheOnChannelDelete = async (
Expand Down
4 changes: 2 additions & 2 deletions src/modules/quoiFeur/quoiFeur.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export const quoiFeur: BotModule = {
.setName('quoi-feur')
.setDescription('Manage quoi-feur game in the channel')
.addSubcommand((subcommand) =>
subcommand.setName('add').setDescription('Add the quoi-feur game to the channel'),
subcommand.setName('enable').setDescription('Enable the quoi-feur game in the channel'),
)
.addSubcommand((subcommand) =>
subcommand.setName('remove').setDescription('Remove the quoi-feur game from the channel'),
subcommand.setName('disable').setDescription('Disable the quoi-feur game in the channel'),
)
.toJSON(),
handler: {
Expand Down
31 changes: 16 additions & 15 deletions src/modules/recurringMessage/recurringMessage.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const isFrequency = (frequency: string): frequency is Frequency => {

export const hasPermission = (interaction: ChatInputCommandInteraction) => {
if (!isModo(interaction.member)) {
void interaction.reply('You are not allowed to use this command');
void interaction.reply({ content: 'You are not allowed to use this command', ephemeral: true });
return false;
}
return true;
Expand Down Expand Up @@ -67,22 +67,20 @@ export const addRecurringMessage = async (interaction: ChatInputCommandInteracti
const channelId = interaction.channelId;
const frequency = interaction.options.getString('frequency', true);
if (!isFrequency(frequency)) {
await interaction.reply(`${frequency} is not a valid frequency`);
await interaction.reply({ content: `${frequency} is not a valid frequency`, ephemeral: true });
return;
}
const message = interaction.options.getString('message', true);

const displayIdInMessage = `\n (id: ${jobId})`;
const jobMessage = message + displayIdInMessage;

if (jobMessage.length > MAX_MESSAGE_LENGTH) {
await interaction.reply(
`Message is too long (max ${MAX_MESSAGE_LENGTH - displayIdInMessage.length} characters)`,
);
if (message.length > MAX_MESSAGE_LENGTH) {
await interaction.reply({
content: `Message is too long (max ${MAX_MESSAGE_LENGTH} characters)`,
ephemeral: true,
});
return;
}

const job = createRecurringMessage(interaction.client, channelId, frequency, jobMessage);
const job = createRecurringMessage(interaction.client, channelId, frequency, message);
job.start();

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

await interaction.reply(`Recurring message added ${frequencyDisplay[frequency]}`);
await interaction.reply({
content: `Recurring message added ${frequencyDisplay[frequency]}`,
ephemeral: true,
});
};

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

const job = inMemoryJobList.find(({ id }) => id === jobId)?.job;
if (!job) {
await interaction.reply('Recurring message not found');
await interaction.reply({ content: 'Recurring message not found', ephemeral: true });
return;
}

job.stop();

await interaction.reply('Recurring message removed');
await interaction.reply({ content: 'Recurring message removed', ephemeral: true });
};

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

if (recurringMessages.length === 0) {
await interaction.reply('No recurring message found');
await interaction.reply({ content: 'No recurring message found', ephemeral: true });
return;
}

Expand Down Expand Up @@ -159,7 +160,7 @@ export const listRecurringMessages = async (interaction: ChatInputCommandInterac
};
});

await interaction.reply({ embeds });
await interaction.reply({ embeds, ephemeral: true });
};

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