From 0e05e0131a67f5c476b90c30931cb5da271761d7 Mon Sep 17 00:00:00 2001 From: TheUntraceable Date: Mon, 27 Dec 2021 15:28:41 +0000 Subject: [PATCH] Add support for individual guilds having seperate options --- index.js | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 6a1adf7..cf40bfa 100644 --- a/index.js +++ b/index.js @@ -200,6 +200,8 @@ class AntiSpamClient extends EventEmitter { kickedUsers: [], bannedUsers: [] } + + this.guildOptions = {} } /** @@ -439,6 +441,17 @@ class AntiSpamClient extends EventEmitter { return true } + /** + * Returns the options for a Guild + * @ignore + * @param {Discord.Guild} guild The guild to get the options for. + * @returns {Object} The options for the guild. + */ + + getOptions (guild) { + return this.guildOptions[guild.id] || this.options + } + /** * Checks a message. * @param {Discord.Message} message The message to check. @@ -449,7 +462,8 @@ class AntiSpamClient extends EventEmitter { * }); */ async message (message) { - const { options } = this + const options = this.getOptions() + if ( !message.guild || message.author.id === message.client.user.id || @@ -571,10 +585,30 @@ class AntiSpamClient extends EventEmitter { } /** - * Removes the muted role from member after specefic time - * @param {Discord.GuildMember} member The member to the role from - * @returns {Promise} Whether the role has been removed + * Add GuildOptions for a guild to use instead of the default options. + * @param {Discord.Guild} guild The guild to add the options for. + * @param {AntiSpamClientOptions} options The options to use for the guild. + * @returns {boolean} Whether the options have been added. */ + addGuildOptions (guild, options) { + const guildId = guild.id + + if (this.guildOptions.has(guildId)) { // Check if the guild already has options + + for (setting, value of options.entries()) { // If they do iterate over the settings and their values + this.guildOptions.guildId[setting] = value // And now write them, this avoids overwriting the value set for options not mentioned. + + } + + return true + + } else { + + this.guildOptions.set(guildId, options) + return true + + } + } /** * Reset the cache of this AntiSpam client instance.