From 2822908ea0de0f4f7fd2f46a1cb688eaef0c3288 Mon Sep 17 00:00:00 2001 From: CL TheDreWen Date: Thu, 30 Oct 2025 08:41:21 +0100 Subject: [PATCH] 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 --- README.md | 2 +- src/commands/utility/follow.command.ts | 41 ++++++++++++++++++++++ src/data-source.ts | 8 ++--- src/entity/follow.entity.ts | 13 +++++++ src/entity/{Guilds.ts => guilds.entity.ts} | 0 5 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 src/commands/utility/follow.command.ts create mode 100644 src/entity/follow.entity.ts rename src/entity/{Guilds.ts => guilds.entity.ts} (100%) diff --git a/README.md b/README.md index 4dac9df..caf390a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A status bot and other features for protojx. |-------------|--------| | /status command | 🌐 | | Number of services down in the bot's status. | 🌐 | -| Notification system in case of downtime. | ➖ | +| Notification system in case of downtime. | 🚧 | | Ability to create persistent status messages that update automatically. | ➖ | | Deployment workflow on Raspberry Pi. | ➖ | diff --git a/src/commands/utility/follow.command.ts b/src/commands/utility/follow.command.ts new file mode 100644 index 0000000..b2183de --- /dev/null +++ b/src/commands/utility/follow.command.ts @@ -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; \ No newline at end of file diff --git a/src/data-source.ts b/src/data-source.ts index eff918b..8159cd4 100644 --- a/src/data-source.ts +++ b/src/data-source.ts @@ -11,9 +11,9 @@ export const AppDataSource = new DataSource({ username: process.env.DB_USERNAME || "postgres", password: process.env.DB_PASSWORD, database: process.env.DB_DATABASE, - synchronize: process.env.NODE_ENV !== "production", // false en production + synchronize: process.env.NODE_ENV !== "production", logging: process.env.DB_LOGGING === "true", - entities: ["./entity/**/*.js"], - migrations: ["./migration/**/*.js"], - subscribers: ["./subscriber/**/*.js"], + entities: [__dirname + '/**/*.entity.js'], + migrations: [__dirname + "/**/*.migration.js"], + subscribers: [__dirname + "/**/*.subscriber.js"], }) \ No newline at end of file diff --git a/src/entity/follow.entity.ts b/src/entity/follow.entity.ts new file mode 100644 index 0000000..2e62f3e --- /dev/null +++ b/src/entity/follow.entity.ts @@ -0,0 +1,13 @@ +import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"; + +@Entity() +export class Follow { + @PrimaryGeneratedColumn() + id: number; + + @Column() + user_discord: string; + + @Column({default: false}) + enable: boolean; +} \ No newline at end of file diff --git a/src/entity/Guilds.ts b/src/entity/guilds.entity.ts similarity index 100% rename from src/entity/Guilds.ts rename to src/entity/guilds.entity.ts