Create guild_active table instead of column

This commit is contained in:
Cadence Ember 2024-09-24 16:31:47 +12:00
parent 06f502dd89
commit dbbb8281e6
6 changed files with 87 additions and 7 deletions

View file

@ -0,0 +1,11 @@
BEGIN TRANSACTION;
CREATE TABLE "guild_active" (
"guild_id" TEXT NOT NULL,
"autocreate" INTEGER NOT NULL,
PRIMARY KEY("guild_id")
) WITHOUT ROWID;
INSERT INTO guild_active (guild_id, autocreate) SELECT guild_id, 1 FROM guild_space;
COMMIT;

View file

@ -1,5 +0,0 @@
BEGIN TRANSACTION;
ALTER TABLE guild_space ADD COLUMN autocreate INTEGER NOT NULL DEFAULT 1;
COMMIT;

View file

@ -31,6 +31,10 @@ export type Models = {
guild_id: string
space_id: string
privacy_level: number
}
guild_active: {
guild_id: string
autocreate: number
}

View file

@ -137,7 +137,7 @@ block body
label.s-label.fl-grow1(for="autocreate")
| Create new Matrix rooms automatically
p.s-description If you want, OOYE can automatically create new Matrix rooms and link them when a new Discord channel is spoken in.
- let value = select("guild_space", "autocreate", {guild_id}).pluck().get()
- let value = select("guild_active", "autocreate", {guild_id}).pluck().get()
input(type="hidden" name="guild_id" value=guild_id)
input.s-toggle-switch.order-last#autocreate(name="autocreate" type="checkbox" hx-post="/api/autocreate" hx-indicator="#autocreate-loading" hx-disabled-elt="this" checked=value)
.is-loading#autocreate-loading

View file

@ -18,6 +18,6 @@ as.router.post("/api/autocreate", defineEventHandler(async event => {
const session = await useSession(event, {password: reg.as_token})
if (!(session.data.managedGuilds || []).includes(parsedBody.guild_id)) throw createError({status: 403, message: "Forbidden", data: "Can't change settings for a guild you don't have Manage Server permissions in"})
db.prepare("UPDATE guild_space SET autocreate = ? WHERE guild_id = ?").run(+!!parsedBody.autocreate, parsedBody.guild_id)
db.prepare("UPDATE guild_active SET autocreate = ? WHERE guild_id = ?").run(+!!parsedBody.autocreate, parsedBody.guild_id)
return sendRedirect(event, `/guild?guild_id=${parsedBody.guild_id}`, 302)
}))