diff --git a/breadbot_test.db b/breadbot_test.db new file mode 100644 index 0000000..f15a818 Binary files /dev/null and b/breadbot_test.db differ diff --git a/src/breadbot.ts b/src/breadbot.ts index 09e583d..27e884c 100644 --- a/src/breadbot.ts +++ b/src/breadbot.ts @@ -13,11 +13,20 @@ const client : Client = new Client({ if (config.DB_MODE == "sqlite") { const db = new utilities.sqlite.SqliteDB("breadbot_test.db") + + db.run("PRAGMA foreign_keys = ON") + + utilities.tables.makeTables(db) } client.once(Events.ClientReady, () => { // 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))) +} +