From 47e1f44e8f960d60b5d62769236211d4a7734d4d Mon Sep 17 00:00:00 2001 From: Bradley Bickford Date: Thu, 1 Jan 2026 21:21:54 -0500 Subject: [PATCH] Beginning work on BreadAsleep, need to find an intelligent way to get database access to command callbacks --- src/breadbot.ts | 8 ++- src/commands/breadasleep.ts | 55 +++++++++++++++++++ .../storage/entities/DBBreadAsleep.ts | 23 ++++++++ src/utilties/storage/entities/DBRole.ts | 6 +- 4 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 src/commands/breadasleep.ts create mode 100644 src/utilties/storage/entities/DBBreadAsleep.ts diff --git a/src/breadbot.ts b/src/breadbot.ts index 50fd043..0340c4c 100644 --- a/src/breadbot.ts +++ b/src/breadbot.ts @@ -23,6 +23,7 @@ import { DBCallUsers } from "./utilties/storage/entities/DBCallUsers" import { DBMessageRegex } from "./utilties/storage/entities/DBMessageRegex" import { DBMessageRegexMatches } from "./utilties/storage/entities/DBMessageRegexMatches" import { setupVoice } from "./utilties/events/voice" +import { DBBreadAsleep } from "./utilties/storage/entities/DBBreadAsleep" console.log(__dirname + path.sep + "utilities" + path.sep + "storage" + path.sep + "entities" + path.sep + "*.ts") @@ -41,7 +42,8 @@ export const dataSource = new DataSource({ DBCallTranscriptions, DBCallUsers, DBMessageRegex, - DBMessageRegexMatches + DBMessageRegexMatches, + DBBreadAsleep ], synchronize: true, logging: false @@ -71,8 +73,10 @@ client.once(Events.ClientReady, async () => { const matchesRepo = dataSource.getRepository(DBMessageRegexMatches) const callRepo = dataSource.getRepository(DBCall) const callUserRepo = dataSource.getRepository(DBCallUsers) + const breadAsleepRepo = dataSource.getRepository(DBBreadAsleep) client.guilds.cache.forEach(async (guild: Guild) => { + await utilities.commands.deployCommands(guild.id) const server: DBServer | null = await insertGuild(serverRepo, guild) if (server != null) { @@ -120,7 +124,7 @@ client.once(Events.ClientReady, async () => { setupRoleCapture(client, serverRepo, roleRepo) setupMessageCapture(client, serverRepo, channelRepo, userRepo, messageRepo, mccRepo, maRepo, regexesRepo, matchesRepo) setupVoice(client, callRepo, channelRepo, userRepo, callUserRepo) - + console.log("Breadbot is Ready") }) diff --git a/src/commands/breadasleep.ts b/src/commands/breadasleep.ts new file mode 100644 index 0000000..5ba06ab --- /dev/null +++ b/src/commands/breadasleep.ts @@ -0,0 +1,55 @@ +import { CommandInteraction, SlashCommandBuilder, SlashCommandSubcommandBuilder } from "discord.js"; + +module.exports = { + enabled: true, + data: new SlashCommandBuilder() + .setName('breadasleep') + .setDescription("Set, list, or remove Bread Asleep notification configurations") + .addSubcommand((subcommand) => + subcommand + .setName("list") + .setDescription("Lists any existing Bread Asleep configurations") + ) + .addSubcommand((subcommand) => + subcommand + .setName("set") + .setDescription("Sets the Bread Asleep configuration for a given role") + .addRoleOption((option) => + option + .setName("role") + .setDescription("The role to apply the configuration to") + .setRequired(true) + ) + .addStringOption((option) => + option + .setName("starttime") + .setDescription("The time when Bread Asleep warnings will start in 24 hour HH:MM:SS format") + .setRequired(true) + ) + .addStringOption((option) => + option + .setName("endtime") + .setDescription("The time when Bread Asleep warnings will end in 24 hour HH:MM:SS format") + .setRequired(true) + ) + .addIntegerOption((option) => + option + .setName("timeoutduration") + .setDescription("The amount of time Bread Asleep will wait between sending warnings in minutes, default 5 minutes") + ) + ) + .addSubcommand((subcommand) => + subcommand + .setName("remove") + .setDescription("Removes the Bread Asleep configuration for a given role") + .addRoleOption((option) => + option + .setName("role") + .setDescription("The role to remove the Bread Asleep configuration from") + ) + ), + async execute(interaction: CommandInteraction) { + await interaction.reply("NOT IMPLEMENTED") + } + +} \ No newline at end of file diff --git a/src/utilties/storage/entities/DBBreadAsleep.ts b/src/utilties/storage/entities/DBBreadAsleep.ts new file mode 100644 index 0000000..11fd769 --- /dev/null +++ b/src/utilties/storage/entities/DBBreadAsleep.ts @@ -0,0 +1,23 @@ +import { Column, Entity, OneToOne, PrimaryGeneratedColumn } from "typeorm"; +import { DBRole } from "./DBRole"; + +@Entity() +export class DBBreadAsleep { + @PrimaryGeneratedColumn() + bread_asleep_id: number + + @OneToOne(() => DBRole, (role: DBRole) => role.bread_asleep_config) + role: DBRole + + @Column() + start_time: string + + @Column() + end_time: string + + @Column() + lockout_duration: number + + @Column({nullable: true}) + warning_lockout_until: Date | null +} \ No newline at end of file diff --git a/src/utilties/storage/entities/DBRole.ts b/src/utilties/storage/entities/DBRole.ts index 85696e5..87845ba 100644 --- a/src/utilties/storage/entities/DBRole.ts +++ b/src/utilties/storage/entities/DBRole.ts @@ -1,5 +1,6 @@ -import { Column, Entity, ManyToOne, PrimaryColumn } from "typeorm"; +import { Column, Entity, ManyToOne, OneToOne, PrimaryColumn } from "typeorm"; import { DBServer } from "./DBServer"; +import { DBBreadAsleep } from "./DBBreadAsleep"; @Entity() export class DBRole { @@ -14,4 +15,7 @@ export class DBRole { @Column() is_deleted: boolean + + @OneToOne(() => DBBreadAsleep, (ba: DBBreadAsleep) => ba.role, {nullable: true}) + bread_asleep_config: DBBreadAsleep } \ No newline at end of file