36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { Interaction, SlashCommandBuilder } from 'discord.js';
|
|
import { isSubscribed, subscribe, timeAnnouncements, unsubscribe } from '../lib/subscriptions';
|
|
|
|
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')
|
|
)
|
|
.setDefaultMemberPermissions('0'),
|
|
|
|
execute: async (interaction: Interaction) => {
|
|
if (!interaction.isChatInputCommand()) return;
|
|
|
|
await interaction.deferReply({ephemeral: true});
|
|
|
|
const announcementType = interaction.options.getString('type', true);
|
|
const channel = interaction.channelId;
|
|
|
|
if (await isSubscribed(announcementType, channel)) {
|
|
await unsubscribe(announcementType, channel);
|
|
await interaction.followUp({
|
|
content: `<#${interaction.channelId}> has been unsubscribed from \`${announcementType}\``
|
|
});
|
|
} else {
|
|
await subscribe(announcementType, interaction.guildId || undefined, channel);
|
|
await interaction.followUp({
|
|
content: `<#${interaction.channelId}> has been subscribed to \`${announcementType}\``
|
|
});
|
|
}
|
|
}
|
|
}; |