A ton of fixes and it's now possible to track servers and channels in the DB
This commit is contained in:
33
src/utilties/discord/guilds.ts
Normal file
33
src/utilties/discord/guilds.ts
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user