feat: automod

#8886 djs
This commit is contained in:
March 7th
2022-12-20 22:46:50 +07:00
parent ef2deb64f7
commit 294005bac7
22 changed files with 1191 additions and 4 deletions

View File

@@ -329,6 +329,10 @@ exports.Opcodes = {
* * APPLICATION_COMMAND_CREATE: applicationCommandCreate (deprecated)
* * APPLICATION_COMMAND_DELETE: applicationCommandDelete (deprecated)
* * APPLICATION_COMMAND_UPDATE: applicationCommandUpdate (deprecated)
* * AUTO_MODERATION_ACTION_EXECUTION: autoModerationActionExecution
* * AUTO_MODERATION_RULE_CREATE: autoModerationRuleCreate
* * AUTO_MODERATION_RULE_DELETE: autoModerationRuleDelete
* * AUTO_MODERATION_RULE_UPDATE: autoModerationRuleUpdate
* * CALL_CREATE: callCreate
* * CALL_DELETE: callDelete
* * CALL_UPDATE: callUpdate
@@ -414,6 +418,10 @@ exports.Events = {
APPLICATION_COMMAND_CREATE: 'applicationCommandCreate',
APPLICATION_COMMAND_DELETE: 'applicationCommandDelete',
APPLICATION_COMMAND_UPDATE: 'applicationCommandUpdate',
AUTO_MODERATION_ACTION_EXECUTION: 'autoModerationActionExecution',
AUTO_MODERATION_RULE_CREATE: 'autoModerationRuleCreate',
AUTO_MODERATION_RULE_DELETE: 'autoModerationRuleDelete',
AUTO_MODERATION_RULE_UPDATE: 'autoModerationRuleUpdate',
CALL_CREATE: 'callCreate',
CALL_DELETE: 'callDelete',
CALL_UPDATE: 'callUpdate',
@@ -753,6 +761,7 @@ exports.MessageTypes = [
/**
* The name of an item to be swept in Sweepers
* * `applicationCommands` - both global and guild commands
* * `autoModerationRules`
* * `bans`
* * `emojis`
* * `invites` - accepts the `lifetime` property, using it will sweep based on expires timestamp
@@ -770,6 +779,7 @@ exports.MessageTypes = [
*/
exports.SweeperKeys = [
'applicationCommands',
'autoModerationRules',
'bans',
'emojis',
'invites',
@@ -1462,6 +1472,46 @@ exports.ApplicationCommandOptionTypes = createEnum([
*/
exports.ApplicationCommandPermissionTypes = createEnum([null, 'ROLE', 'USER']);
/**
* The type of an {@link AutoModerationRuleTriggerTypes} object:
* * KEYWORD
* * SPAM
* * KEYWORD_PRESET
* * MENTION_SPAM
* @typedef {string} AutoModerationRuleTriggerType
* @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types}
*/
exports.AutoModerationRuleTriggerTypes = createEnum([null, 'KEYWORD', null, 'SPAM', 'KEYWORD_PRESET', 'MENTION_SPAM']);
/**
* The type of an {@link AutoModerationRuleKeywordPresetTypes} object:
* * KEYWORD
* * SPAM
* * KEYWORD_PRESET
* * MENTION_SPAM
* @typedef {string} AutoModerationRuleKeywordPresetType
* @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-preset-types}
*/
exports.AutoModerationRuleKeywordPresetTypes = createEnum([null, 'PROFANITY', 'SEXUAL_CONTENT', 'SLURS']);
/**
* The type of an {@link AutoModerationActionTypes} object:
* * BLOCK_MESSAGE
* * SEND_ALERT_MESSAGE
* * TIMEOUT
* @typedef {string} AutoModerationActionType
* @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types}
*/
exports.AutoModerationActionTypes = createEnum([null, 'BLOCK_MESSAGE', 'SEND_ALERT_MESSAGE', 'TIMEOUT']);
/**
* The type of an {@link AutoModerationRuleEventTypes} object:
* * MESSAGE_SEND
* @typedef {string} AutoModerationRuleEventType
* @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types}
*/
exports.AutoModerationRuleEventTypes = createEnum([null, 'MESSAGE_SEND']);
/**
* The type of an {@link Interaction} object:
* * PING
@@ -1709,6 +1759,11 @@ function createEnum(keys) {
* The type of an {@link ApplicationCommandPermissions} object.
* @property {Object<ApplicationCommandType, number>} ApplicationCommandTypes
* The type of an {@link ApplicationCommand} object.
* @property {Object<AutoModerationRuleTriggerType, number>} AutoModerationRuleTriggerTypes Characterizes the type
* of contentwhich can trigger the rule.
* @property {Object<AutoModerationActionType, number>} AutoModerationActionTypes
* @property {Object<AutoModerationRuleKeywordPresetType, number>} AutoModerationRuleKeywordPresetTypes
* @property {Object<AutoModerationRuleEventType, number>} AutoModerationRuleEventTypes
* @property {Object<ChannelType, number>} ChannelTypes All available channel types.
* @property {ClientApplicationAssetTypes} ClientApplicationAssetTypes The types of an {@link ApplicationAsset} object.
* @property {Object<Color, number>} Colors An object with regularly used colors.

View File

@@ -42,6 +42,8 @@ class Intents extends BitField {}
* * `DIRECT_MESSAGE_TYPING`
* * `MESSAGE_CONTENT`
* * `GUILD_SCHEDULED_EVENTS`
* * `AUTO_MODERATION_CONFIGURATION`
* * `AUTO_MODERATION_EXECUTION`
* @type {Object}
* @see {@link https://discord.com/developers/docs/topics/gateway#list-of-intents}
*/
@@ -63,6 +65,8 @@ Intents.FLAGS = {
DIRECT_MESSAGE_TYPING: 1 << 14,
MESSAGE_CONTENT: 1 << 15,
GUILD_SCHEDULED_EVENTS: 1 << 16,
AUTO_MODERATION_CONFIGURATION: 1 << 20,
AUTO_MODERATION_EXECUTION: 1 << 21,
};
module.exports = Intents;

View File

@@ -77,6 +77,16 @@ class Sweepers {
return guildCommands + globalCommands;
}
/**
* Sweeps all auto moderation rules and removes the ones which are indicated by the filter.
* @param {Function} filter The function used to determine
* which auto moderation rules will be removed from the caches
* @returns {number} Amount of auto moderation rules that were removed from the caches
*/
sweepAutoModerationRules(filter) {
return this._sweepGuildDirectProp('autoModerationRules', filter).items;
}
/**
* Sweeps all guild bans and removes the ones which are indicated by the filter.
* @param {Function} filter The function used to determine which bans will be removed from the caches.