aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/BushGuild.ts
blob: 1d7b3c8e9dca9519f792ebeff0eea24da827d7d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { Guild, Structures } 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();
	}
}

Structures.extend('Guild', () => BushGuild);