2021-12-09 03:56:11 +00:00
|
|
|
import {db} from "../modules/database";
|
|
|
|
import {Collection} from "discord.js";
|
|
|
|
|
|
|
|
class Config {
|
|
|
|
private _systemLogsChannel: string | null;
|
|
|
|
private _webhooks: Collection<string, string>; // id-token pairs
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
const {SystemLogsChannel} = db.prepare("SELECT * FROM Settings WHERE Tag = 'Main'").get();
|
|
|
|
const webhooks = db.prepare("SELECT * FROM Webhooks").all();
|
|
|
|
this._systemLogsChannel = SystemLogsChannel;
|
|
|
|
this._webhooks = new Collection();
|
|
|
|
|
|
|
|
for (const {ID, Token} of webhooks) {
|
|
|
|
this._webhooks.set(ID, Token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get systemLogsChannel() {
|
|
|
|
return this._systemLogsChannel;
|
|
|
|
}
|
|
|
|
set systemLogsChannel(systemLogsChannel) {
|
|
|
|
this._systemLogsChannel = systemLogsChannel;
|
|
|
|
db.prepare("UPDATE Settings SET SystemLogsChannel = ? WHERE Tag = 'Main'").run(systemLogsChannel);
|
|
|
|
}
|
2021-12-09 07:06:55 +00:00
|
|
|
|
|
|
|
getWebhook(id: string) {
|
|
|
|
return this._webhooks.get(id);
|
|
|
|
}
|
|
|
|
getWebhookEntries() {
|
|
|
|
return this._webhooks.entries();
|
|
|
|
}
|
|
|
|
hasWebhook(id: string) {
|
|
|
|
return this._webhooks.has(id);
|
2021-12-09 03:56:11 +00:00
|
|
|
}
|
|
|
|
setWebhook(id: string, token: string) {
|
2021-12-09 07:06:55 +00:00
|
|
|
db.prepare("INSERT INTO Webhooks VALUES (?, ?)").run(id, token);
|
2021-12-09 03:56:11 +00:00
|
|
|
this._webhooks.set(id, token);
|
2021-12-09 07:06:55 +00:00
|
|
|
}
|
|
|
|
removeWebhook(id: string) {
|
|
|
|
db.prepare("DELETE FROM Webhooks WHERE ID = ?").run(id);
|
|
|
|
return this._webhooks.delete(id);
|
2021-12-09 03:56:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// There'll only be one instance of the config.
|
|
|
|
export const config = new Config();
|