mirror of
https://github.com/thedrewen/protojx-manager.git
synced 2026-03-21 09:48:56 +01:00
feat(database): refactor entities and relationships for service management
This commit is contained in:
@@ -1,55 +1,50 @@
|
||||
import { ApplicationIntegrationType, ChatInputCommandInteraction, InteractionContextType, MessageFlags, SlashCommandBuilder } from "discord.js";
|
||||
import { CommandDefinition } from "../../type";
|
||||
import { AppDataSource } from "../../data-source";
|
||||
import { Follow } from "../../entity/follow.entity";
|
||||
import statusService from "../../services/status.service";
|
||||
// import { ApplicationIntegrationType, ChatInputCommandInteraction, InteractionContextType, MessageFlags, SlashCommandBuilder } from "discord.js";
|
||||
// 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()
|
||||
.setName('follow')
|
||||
.setDescription('Enables/disables the receipt of service status notifications.')
|
||||
.setIntegrationTypes(
|
||||
ApplicationIntegrationType.UserInstall
|
||||
)
|
||||
.setContexts(
|
||||
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 cmd: CommandDefinition = {
|
||||
// data: new SlashCommandBuilder()
|
||||
// .setName('follow')
|
||||
// .setDescription('Enables/disables the receipt of service status notifications.')
|
||||
// .setIntegrationTypes(
|
||||
// ApplicationIntegrationType.UserInstall
|
||||
// )
|
||||
// .setContexts(
|
||||
// InteractionContextType.BotDM,
|
||||
// InteractionContextType.Guild,
|
||||
// InteractionContextType.PrivateChannel
|
||||
// ),
|
||||
// async execute(interaction: ChatInputCommandInteraction) {
|
||||
// const userRepo = AppDataSource.getRepository(Follow);
|
||||
// const hostvalue = interaction.options.getString('host');
|
||||
|
||||
// const services = await statusService.serviceRepo.find();
|
||||
// const realHost = services.find((v) => v.notify && v.host == hostvalue);
|
||||
|
||||
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;
|
||||
// if (!hostvalue || !realHost) {
|
||||
// await interaction.reply({ content: '⚠️ Host not found !', flags: [MessageFlags.Ephemeral] });
|
||||
// } else {
|
||||
// let follow = await userRepo.findOne({ where: { user_discord: interaction.user.id, service: { id: realHost.id } } });
|
||||
// if (!follow) {
|
||||
// follow = new Follow();
|
||||
// follow.user_discord = interaction.user.id;
|
||||
// follow.service = realHost;
|
||||
// await userRepo.save(follow);
|
||||
// }
|
||||
|
||||
await userRepo.save(follow);
|
||||
// follow.enable = !follow.enable;
|
||||
|
||||
await interaction.reply({content: `✅ Notification successfully ${follow.enable ? 'enabled 🔔' : 'disabled 🔕'} for ${realHost[0]?.name}!`, flags: [MessageFlags.Ephemeral]});
|
||||
// await userRepo.save(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}`})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// await interaction.reply({ content: `✅ Notification successfully ${follow.enable ? 'enabled 🔔' : 'disabled 🔕'} for ${realHost.name}!`, flags: [MessageFlags.Ephemeral] });
|
||||
|
||||
export default cmd;
|
||||
// if (follow.enable) {
|
||||
// await interaction.user.send({ content: `🔔 Notifications have been successfully enabled for ${realHost.name} ! To disable: /follow host:${realHost.name}` })
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// export default cmd;
|
||||
Reference in New Issue
Block a user