jillo-bot/src/commands/subscribe.ts

38 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-11-16 11:33:11 +01:00
import { CommandInteraction, SlashCommandBuilder } from 'discord.js';
import { isSubscribed, subscribe, timeAnnouncements, unsubscribe } from '../lib/subscriptions';
2023-11-16 11:33:11 +01:00
import { Command } from '../types/index';
2023-03-22 11:50:13 +01:00
2023-11-16 11:33:11 +01:00
export default {
2023-03-22 11:50:13 +01:00
data: new SlashCommandBuilder()
.setName('subscribe')
2023-11-11 00:01:38 +01:00
.setDescription('[ADMIN] Subscribe/unsubscribe to a time announcement')
2023-03-22 11:50:13 +01:00
.addStringOption(option =>
option
.setName('type')
.setChoices(...Object.keys(timeAnnouncements).map(l => ({name: l, value: l})))
.setDescription('The name of the time announcement')
2023-11-11 00:01:38 +01:00
.setRequired(true)
2023-03-22 11:50:13 +01:00
)
.setDefaultMemberPermissions('0'),
2023-03-22 11:50:13 +01:00
2023-11-16 11:33:11 +01:00
execute: async (interaction: CommandInteraction) => {
if (!interaction.isChatInputCommand()) return;
2023-03-22 11:50:13 +01:00
await interaction.deferReply({ephemeral: true});
const announcementType = interaction.options.getString('type', true);
const channel = interaction.channelId;
2023-03-22 11:50:13 +01:00
if (await isSubscribed(announcementType, channel)) {
await unsubscribe(announcementType, channel);
2023-03-22 11:50:13 +01:00
await interaction.followUp({
content: `<#${interaction.channelId}> has been unsubscribed from \`${announcementType}\``
});
} else {
await subscribe(announcementType, interaction.guildId || undefined, channel);
2023-03-22 11:50:13 +01:00
await interaction.followUp({
content: `<#${interaction.channelId}> has been subscribed to \`${announcementType}\``
});
}
}
2023-11-16 11:33:11 +01:00
} satisfies Command;