feat(follow): add host option for notifications and update follow entity

This commit is contained in:
2025-11-03 11:45:42 +01:00
parent d417e7334b
commit a593e05f5c
4 changed files with 37 additions and 18 deletions

View File

@@ -2,6 +2,7 @@ import { ApplicationIntegrationType, ChatInputCommandInteraction, InteractionCon
import { CommandDefinition } from "../../type";
import { AppDataSource } from "../../data-source";
import { Follow } from "../../entity/follow.entity";
import statusService from "../../services/status.service";
const cmd : CommandDefinition = {
data: new SlashCommandBuilder()
@@ -14,25 +15,39 @@ const cmd : CommandDefinition = {
InteractionContextType.BotDM,
InteractionContextType.Guild,
InteractionContextType.PrivateChannel
)
.addStringOption((option) =>
option
.setRequired(true)
.addChoices(...statusService.hosts.filter((v) => v.notify).map((s) => ({name: s.name, value: s.host})))
.setName('host')
.setDescription('Host enable/disable.')
),
async execute(interaction : ChatInputCommandInteraction) {
const userRepo = AppDataSource.getRepository(Follow);
const hostvalue = interaction.options.getString('host');
const realHost = statusService.hosts.filter((v) => v.host == hostvalue);
if(!hostvalue || realHost.length == 0) {
await interaction.reply({content: '⚠️ Host not found !', flags: [MessageFlags.Ephemeral]});
}else{
let follow = await userRepo.findOne({where: {user_discord: interaction.user.id, host: hostvalue}});
if(!follow) {
follow = new Follow();
follow.user_discord = interaction.user.id;
follow.host = hostvalue;
await userRepo.save(follow);
}
follow.enable = !follow.enable;
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 🔕'} for ${realHost[0]?.name}!`, flags: [MessageFlags.Ephemeral]});
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'})
if(follow.enable) {
await interaction.user.send({content: `🔔 Notifications have been successfully enabled for ${realHost[0]?.name} ! To disable: /follow host:${realHost[0]?.name}`})
}
}
}
}