Large swathes of re-engineering

This commit is contained in:
2025-11-12 20:41:13 -05:00
parent 6f868dff1e
commit 34f57b96dc
20 changed files with 1567 additions and 196 deletions

View File

@@ -1,23 +1,24 @@
import { Client, Events } from "discord.js";
import { SQLCommon } from "../storage/interfaces";
import { SQLResult } from "../storage/enumerations";
import { insertRole, markRoleDeleted, updateRole } from "../discord/roles";
import { insertGuild } from "../discord/guilds";
import { Repository } from "typeorm";
import { DBServer } from "../storage/entities/DBServer";
import { DBRole } from "../storage/entities/DBRole";
export function setupRoleCapture(client: Client, db: SQLCommon) {
export function setupRoleCapture(client: Client, guildDB: Repository<DBServer>, roleDB: Repository<DBRole>) {
client.on(Events.GuildRoleCreate, async (role) => {
const serverOk: SQLResult = await insertGuild(db, role.guild)
const serverOk: DBServer | null = await insertGuild(guildDB, role.guild)
if (serverOk == SQLResult.ALREADYEXISTS || serverOk == SQLResult.CREATED) {
await insertRole(db, role)
if (serverOk != null) {
await insertRole(roleDB, role)
}
})
client.on(Events.GuildRoleUpdate, async (role) => {
await updateRole(db, role)
await updateRole(roleDB, role)
})
client.on(Events.GuildRoleDelete, async (role) => {
await markRoleDeleted(db, role)
await markRoleDeleted(roleDB, role)
})
}