Skip to content

Commit

Permalink
Add support for individual guilds having seperate options
Browse files Browse the repository at this point in the history
  • Loading branch information
TheUntraceable committed Dec 27, 2021
1 parent 0fc056a commit 0e05e01
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ class AntiSpamClient extends EventEmitter {
kickedUsers: [],
bannedUsers: []
}

this.guildOptions = {}
}

/**
Expand Down Expand Up @@ -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.
Expand All @@ -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 ||
Expand Down Expand Up @@ -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<boolean>} 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.
Expand Down

2 comments on commit 0e05e01

@anselal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the settings be updated without restarting the bot?

@Scraayp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the settings be updated without restarting the bot?

Please create issues for questions next time, and not sadly.

Please sign in to comment.