Basic message collection is working again

This commit is contained in:
2025-06-27 22:49:09 -04:00
parent a247bfb35e
commit ac2dd9983e
8 changed files with 134 additions and 12 deletions

View File

@@ -1,17 +1,26 @@
import { SQLCommon } from "../storage/interfaces";
import { GuildBasedChannel } from "discord.js";
import { DMChannel, GuildBasedChannel, PartialDMChannel } from "discord.js";
import { SQLResult } from "../storage/enumerations";
export async function doesChannelExist(db: SQLCommon, channel : GuildBasedChannel) : Promise<boolean> {
export async function doesChannelExistByID(db: SQLCommon, channelID: string) : Promise<boolean> {
const queryResult : Object[] = await db.getAllParameterized(
"SELECT * FROM channels WHERE server_snowflake = ? AND channel_snowflake = ?",
[channel.guild.id, channel.id]
"SELECT * FROM channels WHERE channel_snowflake = ?",
[channelID]
)
return queryResult.length != 0
}
export async function insertChannel(db: SQLCommon, channel: GuildBasedChannel) : Promise<SQLResult> {
export async function doesChannelExist(db: SQLCommon, channel : GuildBasedChannel | DMChannel | PartialDMChannel) : Promise<boolean> {
const queryResult : Object[] = await db.getAllParameterized(
"SELECT * FROM channels WHERE channel_snowflake = ?",
[channel.id]
)
return queryResult.length != 0
}
export async function insertChannel(db: SQLCommon, channel: GuildBasedChannel | DMChannel | PartialDMChannel) : Promise<SQLResult> {
const alreadyExists: boolean = await doesChannelExist(db, channel)
if(alreadyExists) {
@@ -19,10 +28,18 @@ export async function insertChannel(db: SQLCommon, channel: GuildBasedChannel) :
}
try {
await db.runParameterized(
"INSERT INTO channels VALUES (?, ?, ?, ?)",
[channel.id, channel.guild.id, channel.name, channel.isThread()]
)
if (channel.isDMBased()) {
await db.runParameterized(
"INSERT INTO channels VALUES (?, ?, ?, ?, ?)",
[channel.id, null, channel.recipient?.username, channel.isThread(), channel.isDMBased()]
)
} else {
await db.runParameterized(
"INSERT INTO channels VALUES (?, ?, ?, ?, ?)",
[channel.id, channel.guild.id, channel.name, channel.isThread(), channel.isDMBased()]
)
}
return SQLResult.CREATED
} catch (err) {