mirror of
https://github.com/thedrewen/protojx-manager.git
synced 2026-03-21 09:48:56 +01:00
feat(follow): implement follow command for service status notifications
refactor(data-source): update entity and migration paths for consistency fix(readme): update status feature notification system icon delete(guilds): remove unused Guild entity add(follow): create Follow entity for managing user notification preferences
This commit is contained in:
41
src/commands/utility/follow.command.ts
Normal file
41
src/commands/utility/follow.command.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { ApplicationIntegrationType, ChatInputCommandInteraction, InteractionContextType, MessageFlags, SlashCommandBuilder } from "discord.js";
|
||||
import { CommandDefinition } from "../../type";
|
||||
import { AppDataSource } from "../../data-source";
|
||||
import { Follow } from "../../entity/follow.entity";
|
||||
|
||||
const cmd : CommandDefinition = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('follow')
|
||||
.setDescription('Enables/disables the receipt of service status notifications.')
|
||||
.setIntegrationTypes(
|
||||
ApplicationIntegrationType.GuildInstall,
|
||||
ApplicationIntegrationType.UserInstall
|
||||
)
|
||||
.setContexts(
|
||||
InteractionContextType.BotDM,
|
||||
InteractionContextType.Guild,
|
||||
InteractionContextType.PrivateChannel
|
||||
),
|
||||
async execute(interaction : ChatInputCommandInteraction) {
|
||||
const userRepo = AppDataSource.getRepository(Follow);
|
||||
|
||||
let follow = await userRepo.findOne({where: {user_discord: interaction.user.id}});
|
||||
if(!follow) {
|
||||
follow = new Follow();
|
||||
follow.user_discord = interaction.user.id;
|
||||
await userRepo.save(follow);
|
||||
}
|
||||
|
||||
follow.enable = !follow.enable;
|
||||
|
||||
await userRepo.save(follow);
|
||||
|
||||
await interaction.reply({content: `✅ Notification successfully ${follow.enable ? 'enabled 🔔' : 'disabled 🔕'}!`, flags: [MessageFlags.Ephemeral]});
|
||||
|
||||
if(follow.enable) {
|
||||
await interaction.user.send({content: '🔔 Notifications have been successfully enabled! To disable: /follow'})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default cmd;
|
||||
Reference in New Issue
Block a user