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

This commit is contained in:
2025-06-26 21:01:11 -04:00
parent d9bcdb766c
commit a247bfb35e
10 changed files with 132 additions and 24 deletions

View File

@@ -0,0 +1,33 @@
import { Guild } from "discord.js";
import { SQLCommon } from "../storage/interfaces";
import { SQLResult } from "../storage/enumerations";
export async function doesGuildExist(db: SQLCommon, guild : Guild) : Promise<boolean> {
const queryResult : Object[] = await db.getAllParameterized(
"SELECT * FROM servers WHERE server_snowflake = ?",
[guild.id]
)
return queryResult.length != 0
}
export async function insertGuild(db: SQLCommon, guild: Guild) : Promise<SQLResult> {
const alreadyExists: boolean = await doesGuildExist(db, guild)
if (alreadyExists) {
return SQLResult.ALREADYEXISTS
}
try {
await db.runParameterized(
"INSERT INTO servers VALUES (?, ?, ?)",
[guild.id, guild.name, guild.description]
)
return SQLResult.CREATED
} catch (err) {
console.log("Insert Failed")
//TODO Winston should handle this
console.log(err)
return SQLResult.FAILED
}
}