blob: 85c2721301241be9ede3d9571dc28a58b3fa38f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
import {
TextChannel,
NewsChannel,
DMChannel,
Message,
Structures
} from 'discord.js';
import { BotClient } from './BotClient';
import { Guild as GuildModel } from '../types/Models';
import { BotGuild } from './BotGuild';
export class GuildSettings {
private message: BotMessage;
constructor(message: BotMessage) {
this.message = message;
}
public async getPrefix(): Promise<string> {
return await GuildModel.findByPk(this.message.guild.id).then(
(gm) => gm?.prefix || this.message.client.config.prefix
);
}
public async setPrefix(value: string): Promise<void> {
let entry = await GuildModel.findByPk(this.message.guild.id);
if (!entry) {
entry = GuildModel.build({
id: this.message.guild.id,
prefix: value
});
} else {
entry.prefix = value;
}
await entry.save();
}
}
export class BotMessage extends Message {
constructor(
client: BotClient,
data: Record<string, unknown>,
channel: TextChannel | DMChannel | NewsChannel
) {
super(client, data, channel);
}
public guild: BotGuild;
public client: BotClient;
static install(): void {
Structures.extend('Message', () => BotMessage);
}
public settings = new GuildSettings(this);
}
|