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:
@@ -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. | ➖ |
|
||||
|
||||
|
||||
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;
|
||||
@@ -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"],
|
||||
})
|
||||
13
src/entity/follow.entity.ts
Normal file
13
src/entity/follow.entity.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user