aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/discord.js/BushGuild.ts
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-09-06 15:20:46 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-09-06 15:20:46 -0400
commit13306f17accea5d3653dd4b8670ba0d6ab69c7c5 (patch)
tree7075dcca19ed1164a166efac19c49311e93ffeee /src/lib/extensions/discord.js/BushGuild.ts
parenta8386e756758f243b75e5df4886224d2bf9f241c (diff)
downloadtanzanite-13306f17accea5d3653dd4b8670ba0d6ab69c7c5.tar.gz
tanzanite-13306f17accea5d3653dd4b8670ba0d6ab69c7c5.tar.bz2
tanzanite-13306f17accea5d3653dd4b8670ba0d6ab69c7c5.zip
evidence command and more logging
Diffstat (limited to 'src/lib/extensions/discord.js/BushGuild.ts')
-rw-r--r--src/lib/extensions/discord.js/BushGuild.ts22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts
index 18f6542..256b9dc 100644
--- a/src/lib/extensions/discord.js/BushGuild.ts
+++ b/src/lib/extensions/discord.js/BushGuild.ts
@@ -21,20 +21,22 @@ export class BushGuild extends Guild {
return features.includes(feature);
}
- public async addFeature(feature: GuildFeatures): Promise<GuildModel['enabledFeatures']> {
+ public async addFeature(feature: GuildFeatures, moderator?: BushGuildMember): Promise<GuildModel['enabledFeatures']> {
const features = await this.getSetting('enabledFeatures');
const newFeatures = util.addOrRemoveFromArray('add', features, feature);
- return (await this.setSetting('enabledFeatures', newFeatures)).enabledFeatures;
+ return (await this.setSetting('enabledFeatures', newFeatures, moderator)).enabledFeatures;
}
- public async removeFeature(feature: GuildFeatures): Promise<GuildModel['enabledFeatures']> {
+ public async removeFeature(feature: GuildFeatures, moderator?: BushGuildMember): Promise<GuildModel['enabledFeatures']> {
const features = await this.getSetting('enabledFeatures');
const newFeatures = util.addOrRemoveFromArray('remove', features, feature);
- return (await this.setSetting('enabledFeatures', newFeatures)).enabledFeatures;
+ return (await this.setSetting('enabledFeatures', newFeatures, moderator)).enabledFeatures;
}
- public async toggleFeature(feature: GuildFeatures): Promise<GuildModel['enabledFeatures']> {
- return (await this.hasFeature(feature)) ? await this.removeFeature(feature) : await this.addFeature(feature);
+ public async toggleFeature(feature: GuildFeatures, moderator?: BushGuildMember): Promise<GuildModel['enabledFeatures']> {
+ return (await this.hasFeature(feature))
+ ? await this.removeFeature(feature, moderator)
+ : await this.addFeature(feature, moderator);
}
public async getSetting<K extends keyof GuildModel>(setting: K): Promise<GuildModel[K]> {
@@ -44,10 +46,16 @@ export class BushGuild extends Guild {
);
}
- public async setSetting<K extends keyof GuildModel>(setting: K, value: GuildDB[K]): Promise<GuildDB> {
+ public async setSetting<K extends Exclude<keyof GuildModel, 'id'>>(
+ setting: K,
+ value: GuildDB[K],
+ moderator?: BushGuildMember
+ ): Promise<GuildDB> {
const row = (await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id });
+ const oldValue = row[setting] as GuildDB[K];
row[setting] = value;
client.cache.guilds.set(this.id, row.toJSON() as GuildDB);
+ client.emit('bushUpdateSettings', setting, this, oldValue, row[setting], moderator);
return await row.save();
}