@@ -8,17 +8,7 @@ import {
88 makeEventExtensionPoint ,
99} from "#extensionPoint.ts" ;
1010import { onBotEvent } from "#plugins/core/public/extensionPoints.ts" ;
11- import {
12- cancelGuildInfoDeletion ,
13- deleteExpiredGuildInfo ,
14- getAllGuildInfo ,
15- insertGuildInfo ,
16- markGuildAllowed ,
17- markGuildNotAllowed ,
18- markUnknownGuildAllowed ,
19- scheduleGuildInfoDeletion ,
20- updateGuildInfo ,
21- } from "#plugins/core/storage/guildInfo.ts" ;
11+ import { guildInfoTable } from "#plugins/core/storage/guildInfo.ts" ;
2212import type { Guild , JSONGuild } from "oceanic.js" ;
2313import type { Pool } from "pg" ;
2414
@@ -50,7 +40,7 @@ export default [
5040async function init ( ctx : BackendDiscordContext ) : Promise < void > {
5141 logger . debug ?.( "Initializing guild info" ) ;
5242
53- const guildsInfo = await getAllGuildInfo ( ctx . db ) ;
43+ const guildsInfo = await guildInfoTable . all ( ctx . db ) ;
5444 // guilds from env var, remove those which are already present
5545 const missing = [ ...BOT_ALLOWED_GUILDS ] ;
5646
@@ -61,12 +51,12 @@ async function init(ctx: BackendDiscordContext): Promise<void> {
6151 missing . splice ( missingIndex , 1 ) ;
6252
6353 if ( guildInfo . deleteAt !== null ) {
64- await cancelGuildInfoDeletion ( ctx . db , guildInfo . id ) ;
54+ await guildInfoTable . cancelDeletion ( ctx . db , guildInfo . id ) ;
6555 }
6656 } else if ( ! guildInfo . allowed ) {
6757 // was removed from env var
6858 if ( guildInfo . deleteAt === null ) {
69- await scheduleGuildInfoDeletion ( ctx . db , guildInfo . id ) ;
59+ await guildInfoTable . scheduleDeletion ( ctx . db , guildInfo . id ) ;
7060 }
7161
7262 continue ;
@@ -90,7 +80,7 @@ async function init(ctx: BackendDiscordContext): Promise<void> {
9080 continue ;
9181 }
9282
93- await updateGuildInfo (
83+ await guildInfoTable . update (
9484 ctx . db ,
9585 guildInfo . id ,
9686 realGuild . name ,
@@ -102,7 +92,7 @@ async function init(ctx: BackendDiscordContext): Promise<void> {
10292 for ( const missingGuildID of missing ) {
10393 const realGuild = ctx . bot . guilds . get ( missingGuildID ) ;
10494
105- await insertGuildInfo (
95+ await guildInfoTable . insert (
10696 ctx . db ,
10797 missingGuildID ,
10898 realGuild ?. name ?? null ,
@@ -122,7 +112,7 @@ export async function beginDeleteGuildInfoLoop(db: Pool): Promise<void> {
122112 try {
123113 logger . debug ?.( "Deleting expired guild info" ) ;
124114
125- const deletedCount = await deleteExpiredGuildInfo ( db ) ;
115+ const deletedCount = await guildInfoTable . deleteExpired ( db ) ;
126116
127117 logger . debug ?.( `Deleted ${ deletedCount } guilds` ) ;
128118 } finally {
@@ -132,7 +122,7 @@ export async function beginDeleteGuildInfoLoop(db: Pool): Promise<void> {
132122
133123async function handleCreate ( db : Pool , guild : Guild ) : Promise < void > {
134124 if ( isGuildAllowed ( guild . id ) ) {
135- await updateGuildInfo (
125+ await guildInfoTable . update (
136126 db ,
137127 guild . id ,
138128 guild . name ,
@@ -163,7 +153,13 @@ async function handleUpdate(
163153 return ;
164154 }
165155
166- await updateGuildInfo ( db , guild . id , guild . name , guild . icon , guild . ownerID ) ;
156+ await guildInfoTable . update (
157+ db ,
158+ guild . id ,
159+ guild . name ,
160+ guild . icon ,
161+ guild . ownerID ,
162+ ) ;
167163}
168164
169165export function isGuildAllowed ( id : string ) : boolean {
@@ -193,15 +189,15 @@ export async function grantAccess(
193189 const realGuild = ctx . bot . guilds . get ( id ) ;
194190
195191 if ( realGuild !== undefined ) {
196- await markGuildAllowed (
192+ await guildInfoTable . markAllowed (
197193 ctx . db ,
198194 id ,
199195 realGuild ?. name ?? null ,
200196 realGuild ?. icon ?? null ,
201197 realGuild ?. ownerID ?? null ,
202198 ) ;
203199 } else {
204- await markUnknownGuildAllowed ( ctx . db , id ) ;
200+ await guildInfoTable . markUnknownAllowed ( ctx . db , id ) ;
205201 }
206202
207203 allowedGuilds . add ( id ) ;
@@ -222,11 +218,11 @@ export async function revokeAccess(
222218 }
223219
224220 if ( BOT_ALLOWED_GUILDS . includes ( id ) ) {
225- await markGuildNotAllowed ( ctx . db , id ) ;
221+ await guildInfoTable . markNotAllowed ( ctx . db , id ) ;
226222 allowedGuilds . delete ( id ) ;
227223 return true ;
228224 } else {
229- const date = await scheduleGuildInfoDeletion ( ctx . db , id ) ;
225+ const date = await guildInfoTable . scheduleDeletion ( ctx . db , id ) ;
230226 allowedGuilds . delete ( id ) ;
231227
232228 await onGuildAccessRevoked . fire ( ctx , id ) ;
0 commit comments