Adding preliminary table work and breadalert framing

This commit is contained in:
Bradley Bickford 2025-06-24 21:45:45 -04:00
parent d9561d9179
commit 617a49bb16
7 changed files with 86 additions and 3 deletions

BIN
breadbot_test.db Normal file

Binary file not shown.

View File

@ -13,11 +13,20 @@ const client : Client = new Client({
if (config.DB_MODE == "sqlite") { if (config.DB_MODE == "sqlite") {
const db = new utilities.sqlite.SqliteDB("breadbot_test.db") const db = new utilities.sqlite.SqliteDB("breadbot_test.db")
db.run("PRAGMA foreign_keys = ON")
utilities.tables.makeTables(db)
} }
client.once(Events.ClientReady, () => { client.once(Events.ClientReady, () => {
// TODO Winston should handle this // TODO Winston should handle this
console.log("Breadbot is ready") 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) => { client.on(Events.GuildCreate, async (guild : Guild) => {

View File

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

View File

@ -1,5 +1,7 @@
import * as ping from "./ping"; import * as ping from "./ping";
import * as breadalert from "./breadalert"
export const commands = { export const commands = {
ping ping,
breadalert
} }

View File

@ -1,7 +1,9 @@
import * as command from "./discord/command_utils" import * as command from "./discord/command_utils"
import * as sqlite from "./storage/sqlite" import * as sqlite from "./storage/sqlite"
import * as tables from "./storage/tables"
export const utilities = { export const utilities = {
command, command,
sqlite sqlite,
tables
} }

View File

@ -17,7 +17,11 @@ export class SqliteDB implements sql_common {
console.log(err) console.log(err)
throw err throw err
} else { } else {
if (result != null) {
return result.changes return result.changes
} else {
return 0
}
} }
}) })
}) })

View File

@ -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<number[]> {
return Promise.all(tables.map((statement) => db.run(statement)))
}