functional

This commit is contained in:
2022-05-26 19:54:42 -05:00
parent 94126fe5f9
commit 4c97aa1f88
9 changed files with 605 additions and 550 deletions

46
src/storageclass.ts Normal file
View File

@@ -0,0 +1,46 @@
import { JSONObject } from './util'
import { Guild } from 'discord.js'
export interface StorageValue {
get(): string
set(val: string): void
}
export class StorageBase {
val: StorageValue
constructor(val: StorageValue) {
this.val = val
}
set(val: string | JSONObject) {
if (typeof val !== 'string') {
val = JSON.stringify(val)
}
this.val.set(val)
}
get(): string {
return this.val.get()
}
getJson(): JSONObject {
let val
try {
val = JSON.parse(this.val.get())
} catch (e) {
val = {}
}
return val
}
}
export class GlobalStorage extends StorageBase {}
export class GuildStorage extends StorageBase {
public guild: Guild
constructor(guild: Guild, val: StorageValue) {
super(val)
this.guild = guild
}
}