aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/BushGuild.ts
blob: 470e93a0f58b4ed01572c16aacbb5d7d87c1e1d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { Guild } from 'discord.js';
import { Guild as GuildDB, GuildModel } from '../models/Guild';
import { BushClient } from './BushClient';

export class BushGuild extends Guild {
	public declare client: BushClient;
	public constructor(client: BushClient, data: unknown) {
		super(client, data);
	}

	public async getSetting(setting: keyof GuildModel) {
		return ((await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id })).get(setting);
	}

	public async setSetting<K extends keyof GuildModel>(setting: K, value: GuildDB[K]) {
		const row = (await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id });
		row[setting] = value;
		return await row.save();
	}
}