A ton of fixes and it's now possible to track servers and channels in the DB

This commit is contained in:
Bradley committed 2025-06-26 21:01:11 -04:00
1 parent d9bcdb766c
commit a247bfb35e
10 files changed
+132 -24

No files matched your search

+21 -6
View File
@@ -1,9 +1,10 @@
import { Client, Events, GatewayIntentBits, Guild, Interaction } from "discord.js"
import { Client, Events, GatewayIntentBits, Guild, GuildBasedChannel, Interaction } from "discord.js"
import { utilities } from "./utilties"
import { commands } from "./commands"
import { config } from "./config"
import { SQLCommon } from "./utilties/storage/interfaces"
const client : Client = new Client({
export const client : Client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
@@ -11,12 +12,15 @@ const client : Client = new Client({
]
})
let db: SQLCommon
if (config.DB_MODE == "sqlite") {
const db = new utilities.sqlite.SqliteDB("breadbot_test.db")
db = new utilities.sqlite.SqliteDB("breadbot_test.db")
db.run("PRAGMA foreign_keys = ON")
utilities.tables.makeTables(db)
utilities.tables.makeConstraints(db)
}
client.once(Events.ClientReady, () => {
@@ -24,13 +28,24 @@ client.once(Events.ClientReady, () => {
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)
await utilities.commands.deployCommands(guild.id)
// TODO handle failures?
await utilities.guilds.insertGuild(db, guild)
guild.channels.cache.forEach(async (channel: GuildBasedChannel) => {
await utilities.channels.insertChannel(db, channel)
})
})
})
client.on(Events.GuildCreate, async (guild : Guild) => {
await utilities.command.deployCommands(guild.id)
await utilities.commands.deployCommands(guild.id)
await utilities.guilds.insertGuild(db, guild)
guild.channels.cache.forEach(async (channel: GuildBasedChannel) => {
await utilities.channels.insertChannel(db, channel)
})
})
client.on(Events.InteractionCreate, async (interaction: Interaction) => {