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:
2025-10-30 08:41:21 +01:00
parent 0449654edd
commit 2822908ea0
5 changed files with 59 additions and 5 deletions

View File

@@ -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. | |

View 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;

View File

@@ -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"],
})

View File

@@ -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;
}