aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/BushGuild.ts
blob: 3c04bd647cf7a64f1441b650da44cf46e7263b27 (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<K extends keyof GuildModel>(setting: K): Promise<GuildModel[K]> {
		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]): Promise<GuildDB> {
		const row = (await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id });
		row[setting] = value;
		return await row.save();
	}
}