From 617a49bb16f2772f51b445e9bc040abbe402dc0d Mon Sep 17 00:00:00 2001 From: Bradley Bickford Date: Tue, 24 Jun 2025 21:45:45 -0400 Subject: [PATCH] Adding preliminary table work and breadalert framing --- breadbot_test.db | Bin 0 -> 20480 bytes src/breadbot.ts | 9 ++++++ src/commands/breadalert.ts | 55 +++++++++++++++++++++++++++++++++ src/commands/index.ts | 4 ++- src/utilties/index.ts | 4 ++- src/utilties/storage/sqlite.ts | 6 +++- src/utilties/storage/tables.ts | 11 +++++++ 7 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 breadbot_test.db create mode 100644 src/commands/breadalert.ts create mode 100644 src/utilties/storage/tables.ts diff --git a/breadbot_test.db b/breadbot_test.db new file mode 100644 index 0000000000000000000000000000000000000000..f15a818035e62fed9676ae0d46d1242b2658c92b GIT binary patch literal 20480 zcmeI%%TB^T7>3~~2QelbR(3%!vxEc>#2XL^3nQW;F4)i%7_(rFb{qkvna% zjT$AcC2x~<{+UeL`JT?E>D6V!@{}A-oU!T2Ly;4jCXS>OLd5(t>7UUN^b=9XZ?!M= zsxl__oac1*RU|T9kv+)1WV)HRRg)P<009ILKmY**5I_I{1Q7VI0`r}CN-q?&MbXBPo9P&^G?a0bz|9{Y@WAe^SaTH7p;@C zYO5np>z%TzoJZxXo?MP@XPaXsJvIBhPia4~q1OtUu8+<18X`CB9(Sy z8+tXrDoMB&qY@Tze@ATwyDA-Aa>0cI0R#|0009ILKmY**5I_I{1lCnxD+tE-|GK_j zav^{K0tg_000IagfB*srAg~nR|34c60R#|0009ILKmY**5I_Kd^%vm(|N6gU5+Z;A S0tg_000IagfB*srAn*=sy_e { // TODO Winston should handle this console.log("Breadbot is ready") + + client.guilds.cache.forEach(async (guild: Guild) => { + console.log(`ID: ${guild.id}, Name: ${guild.name}, Desc: ${guild.description}`) + await utilities.command.deployCommands(guild.id) + }) }) client.on(Events.GuildCreate, async (guild : Guild) => { diff --git a/src/commands/breadalert.ts b/src/commands/breadalert.ts new file mode 100644 index 0000000..4238811 --- /dev/null +++ b/src/commands/breadalert.ts @@ -0,0 +1,55 @@ +import { CommandInteraction, SlashCommandBuilder } from "discord.js"; + +export const enabled: boolean = true + +export const data = new SlashCommandBuilder() + .setName("breadalert") + .setDescription("Controls event alerting using the Bread Alert subsystem") + .addSubcommand((subcommand) => + subcommand + .setName("list") + .setDescription("List the current Bread Alert active alerts") + .addNumberOption(option => + option + .setName("count") + .setDescription("The number of future alerts to return, default 5") + .setRequired(false) + ) + ) + .addSubcommand(subcommand => + subcommand + .setName("add") + .setDescription("Add a new Bread Alert") + .addStringOption(option => + option + .setName("name") + .setDescription("The name of the event, must be unique") + .setRequired(true) + ) + .addStringOption(option => + option + .setName("date") + .setDescription("The date and time of the event in YYYY-MM-DD HH:MM:SS format") + .setRequired(true) + ) + .addStringOption(option => + option + .setName("notifications") + .setDescription("A comma separated list of time offsets that determine when to alert prior to the event") + .setRequired(false) + ) + ) + .addSubcommand(subcommand => + subcommand + .setName("delete") + .setDescription("Delete a Bread Alert") + .addStringOption(option => + option + .setName("name") + .setDescription("The name of the event to remove") + ) + ) + +export async function execute(interaction: CommandInteraction) { + return interaction.reply("NOT IMPLEMENTED!") +} \ No newline at end of file diff --git a/src/commands/index.ts b/src/commands/index.ts index 6333e84..03ea096 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,5 +1,7 @@ import * as ping from "./ping"; +import * as breadalert from "./breadalert" export const commands = { - ping + ping, + breadalert } \ No newline at end of file diff --git a/src/utilties/index.ts b/src/utilties/index.ts index ac206e9..cce9d11 100644 --- a/src/utilties/index.ts +++ b/src/utilties/index.ts @@ -1,7 +1,9 @@ import * as command from "./discord/command_utils" import * as sqlite from "./storage/sqlite" +import * as tables from "./storage/tables" export const utilities = { command, - sqlite + sqlite, + tables } \ No newline at end of file diff --git a/src/utilties/storage/sqlite.ts b/src/utilties/storage/sqlite.ts index dfea9d4..2102604 100644 --- a/src/utilties/storage/sqlite.ts +++ b/src/utilties/storage/sqlite.ts @@ -17,7 +17,11 @@ export class SqliteDB implements sql_common { console.log(err) throw err } else { - return result.changes + if (result != null) { + return result.changes + } else { + return 0 + } } }) }) diff --git a/src/utilties/storage/tables.ts b/src/utilties/storage/tables.ts new file mode 100644 index 0000000..4304f56 --- /dev/null +++ b/src/utilties/storage/tables.ts @@ -0,0 +1,11 @@ +import { sql_common } from "./interfaces"; + +const tables: string[] = [ + "CREATE TABLE IF NOT EXISTS servers (server_snowflake bigint NOT NULL PRIMARY KEY,server_name text NOT NULL,server_description mediumtext);", + "CREATE TABLE IF NOT EXISTS channels (channel_snowflake bigint NOT NULL PRIMARY KEY,server_snowflake bigint NOT NULL,channel_name text NOT NULL);" +] + +export async function makeTables(db: sql_common): Promise { + return Promise.all(tables.map((statement) => db.run(statement))) +} +