2023-06-11 17:23:57 +02:00
|
|
|
import { Interaction, SlashCommandBuilder } from 'discord.js';
|
2023-03-22 12:00:59 +01:00
|
|
|
import { saveSubscriptions, subscriptions, timeAnnouncements } from '../lib/subscriptions';
|
2023-03-22 11:50:13 +01:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
.setName('subscribe')
|
|
|
|
.setDescription('Subscribe/unsubscribe to a time announcement')
|
|
|
|
.addStringOption(option =>
|
|
|
|
option
|
|
|
|
.setName('type')
|
|
|
|
.setChoices(...Object.keys(timeAnnouncements).map(l => ({name: l, value: l})))
|
|
|
|
.setDescription('The name of the time announcement')
|
|
|
|
)
|
2023-06-11 17:23:57 +02:00
|
|
|
.setDefaultMemberPermissions('0'),
|
2023-03-22 11:50:13 +01:00
|
|
|
|
2023-06-11 17:23:57 +02:00
|
|
|
execute: async (interaction: Interaction) => {
|
|
|
|
if (!interaction.isChatInputCommand()) return;
|
|
|
|
|
2023-03-22 11:50:13 +01:00
|
|
|
await interaction.deferReply({ephemeral: true});
|
2023-06-11 17:23:57 +02:00
|
|
|
|
|
|
|
const announcementType = interaction.options.getString('type', true);
|
2023-03-22 11:50:13 +01:00
|
|
|
|
2023-03-22 11:53:54 +01:00
|
|
|
if (subscriptions[announcementType] && subscriptions[announcementType].includes(interaction.channelId)) {
|
2023-03-22 11:50:13 +01:00
|
|
|
subscriptions[announcementType] = subscriptions[announcementType].filter(id => id !== interaction.channelId);
|
|
|
|
await interaction.followUp({
|
|
|
|
content: `<#${interaction.channelId}> has been unsubscribed from \`${announcementType}\``
|
|
|
|
});
|
|
|
|
} else {
|
2023-03-22 11:53:54 +01:00
|
|
|
subscriptions[announcementType] = subscriptions[announcementType] || [];
|
2023-03-22 11:50:13 +01:00
|
|
|
subscriptions[announcementType].push(interaction.channelId);
|
|
|
|
await interaction.followUp({
|
|
|
|
content: `<#${interaction.channelId}> has been subscribed to \`${announcementType}\``
|
|
|
|
});
|
|
|
|
}
|
2023-03-22 12:00:59 +01:00
|
|
|
saveSubscriptions();
|
2023-03-22 11:50:13 +01:00
|
|
|
}
|
|
|
|
};
|