From b216f7a8bee2c02fe0e75189fe31f95973bfbe2e Mon Sep 17 00:00:00 2001 From: Vitor Date: Fri, 14 Oct 2022 17:56:21 +0100 Subject: [PATCH] feat(APIAutoModeration): add support for auto moderation (#418) --- deno/gateway/v10.ts | 124 ++++++++++++++++++ deno/gateway/v9.ts | 124 ++++++++++++++++++ deno/payloads/v10/auditLog.ts | 88 ++++++++++++- deno/payloads/v10/autoModeration.ts | 195 ++++++++++++++++++++++++++++ deno/payloads/v10/channel.ts | 7 + deno/payloads/v10/guild.ts | 4 + deno/payloads/v10/mod.ts | 1 + deno/payloads/v9/auditLog.ts | 88 ++++++++++++- deno/payloads/v9/autoModeration.ts | 195 ++++++++++++++++++++++++++++ deno/payloads/v9/channel.ts | 7 + deno/payloads/v9/guild.ts | 4 + deno/payloads/v9/mod.ts | 1 + deno/rest/v10/autoModeration.ts | 84 ++++++++++++ deno/rest/v10/mod.ts | 19 +++ deno/rest/v9/autoModeration.ts | 84 ++++++++++++ deno/rest/v9/mod.ts | 20 +++ gateway/v10.ts | 124 ++++++++++++++++++ gateway/v9.ts | 124 ++++++++++++++++++ payloads/v10/auditLog.ts | 88 ++++++++++++- payloads/v10/autoModeration.ts | 195 ++++++++++++++++++++++++++++ payloads/v10/channel.ts | 7 + payloads/v10/guild.ts | 4 + payloads/v10/index.ts | 1 + payloads/v9/auditLog.ts | 88 ++++++++++++- payloads/v9/autoModeration.ts | 195 ++++++++++++++++++++++++++++ payloads/v9/channel.ts | 7 + payloads/v9/guild.ts | 4 + payloads/v9/index.ts | 1 + rest/v10/autoModeration.ts | 84 ++++++++++++ rest/v10/index.ts | 19 +++ rest/v9/autoModeration.ts | 84 ++++++++++++ rest/v9/index.ts | 20 +++ 32 files changed, 2086 insertions(+), 4 deletions(-) create mode 100644 deno/payloads/v10/autoModeration.ts create mode 100644 deno/payloads/v9/autoModeration.ts create mode 100644 deno/rest/v10/autoModeration.ts create mode 100644 deno/rest/v9/autoModeration.ts create mode 100644 payloads/v10/autoModeration.ts create mode 100644 payloads/v9/autoModeration.ts create mode 100644 rest/v10/autoModeration.ts create mode 100644 rest/v9/autoModeration.ts diff --git a/deno/gateway/v10.ts b/deno/gateway/v10.ts index db0497500..13f44e79f 100644 --- a/deno/gateway/v10.ts +++ b/deno/gateway/v10.ts @@ -6,6 +6,8 @@ import type { Snowflake } from '../globals.ts'; import type { GatewayPresenceUpdate } from '../payloads/v10/gateway.ts'; import type { APIApplication, + APIAutoModerationRule, + APIAutoModerationAction, APIChannel, APIEmoji, APIGuild, @@ -28,6 +30,7 @@ import type { GatewayVoiceState, InviteTargetType, PresenceUpdateStatus, + AutoModerationRuleTriggerType, } from '../payloads/v10/mod.ts'; import type { Nullable } from '../utils/internals.ts'; @@ -190,6 +193,8 @@ export enum GatewayIntentBits { DirectMessageTyping = 1 << 14, MessageContent = 1 << 15, GuildScheduledEvents = 1 << 16, + AutoModerationConfiguration = 1 << 20, + AutoModerationExecution = 1 << 21, } /** @@ -252,6 +257,10 @@ export enum GatewayDispatchEvents { GuildScheduledEventDelete = 'GUILD_SCHEDULED_EVENT_DELETE', GuildScheduledEventUserAdd = 'GUILD_SCHEDULED_EVENT_USER_ADD', GuildScheduledEventUserRemove = 'GUILD_SCHEDULED_EVENT_USER_REMOVE', + AutoModerationRuleCreate = 'AUTO_MODERATION_RULE_CREATE', + AutoModerationRuleUpdate = 'AUTO_MODERATION_RULE_UPDATE', + AutoModerationRuleDelete = 'AUTO_MODERATION_RULE_DELETE', + AutoModerationActionExecution = 'AUTO_MODERATION_ACTION_EXECUTION', } export type GatewaySendPayload = @@ -432,6 +441,121 @@ export interface GatewayReadyDispatchData { */ export type GatewayResumedDispatch = DataPayload; +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-create + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-update + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-delete + */ +export type GatewayAutoModerationRuleModifyDispatch = DataPayload< + | GatewayDispatchEvents.AutoModerationRuleCreate + | GatewayDispatchEvents.AutoModerationRuleUpdate + | GatewayDispatchEvents.AutoModerationRuleDelete, + GatewayAutoModerationRuleModifyDispatchData +>; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-create + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-update + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-delete + */ +export type GatewayAutoModerationRuleModifyDispatchData = APIAutoModerationRule; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-create + */ +export type GatewayAutoModerationRuleCreateDispatch = GatewayAutoModerationRuleModifyDispatch; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-create + */ +export type GatewayAutoModerationRuleCreateDispatchData = GatewayAutoModerationRuleModifyDispatchData; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-update + */ +export type GatewayAutoModerationRuleUpdateDispatch = GatewayAutoModerationRuleModifyDispatch; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-update + */ +export type GatewayAutoModerationRuleUpdateDispatchData = GatewayAutoModerationRuleModifyDispatchData; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-delete + */ +export type GatewayAutoModerationRuleDeleteDispatch = GatewayAutoModerationRuleModifyDispatch; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-delete + */ +export type GatewayAutoModerationRuleDeleteDispatchData = GatewayAutoModerationRuleModifyDispatchData; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-action-execution + */ +export type GatewayAutoModerationActionExecutionDispatch = DataPayload< + GatewayDispatchEvents.AutoModerationActionExecution, + GatewayAutoModerationActionExecutionDispatchData +>; + +/** + * https://discord.com/developers/docs/topics/gateway-events#auto-moderation-action-execution + */ +export interface GatewayAutoModerationActionExecutionDispatchData { + /** + * The id of the guild in which action was executed + */ + guild_id: Snowflake; + /** + * The action which was executed + */ + action: APIAutoModerationAction; + /** + * The id of the rule which action belongs to + */ + rule_id: Snowflake; + /** + * The trigger type of rule which was triggered + */ + rule_trigger_type: AutoModerationRuleTriggerType; + /** + * The id of the user which generated the content which triggered the rule + */ + user_id: Snowflake; + /** + * The id of the channel in which user content was posted + */ + channel_id?: Snowflake; + /** + * The id of any user message which content belongs to + * + * This field will not be present if message was blocked by AutoMod or content was not part of any message + */ + message_id?: Snowflake; + /** + * The id of any system auto moderation messages posted as a result of this action + * + * This field will not be present if this event does not correspond to an action with type {@link AutoModerationActionType.SendAlertMessage} + */ + alert_system_message_id?: Snowflake; + /** + * The user generated text content + * + * `MESSAGE_CONTENT` (`1 << 15`) gateway intent is required to receive non-empty values from this field + */ + content: string; + /** + * The word or phrase configured in the rule that triggered the rule + */ + matched_keyword: string | null; + /** + * The substring in content that triggered the rule + * + * `MESSAGE_CONTENT` (`1 << 15`) gateway intent is required to receive non-empty values from this field + */ + matched_content: string | null; +} + /** * https://discord.com/developers/docs/topics/gateway#channel-create * https://discord.com/developers/docs/topics/gateway#channel-update diff --git a/deno/gateway/v9.ts b/deno/gateway/v9.ts index 1c6e71796..28d4a1eb4 100644 --- a/deno/gateway/v9.ts +++ b/deno/gateway/v9.ts @@ -6,6 +6,8 @@ import type { Snowflake } from '../globals.ts'; import type { GatewayPresenceUpdate } from '../payloads/v9/gateway.ts'; import type { APIApplication, + APIAutoModerationRule, + APIAutoModerationAction, APIChannel, APIEmoji, APIGuild, @@ -28,6 +30,7 @@ import type { GatewayVoiceState, InviteTargetType, PresenceUpdateStatus, + AutoModerationRuleTriggerType, } from '../payloads/v9/mod.ts'; import type { Nullable } from '../utils/internals.ts'; @@ -189,6 +192,8 @@ export enum GatewayIntentBits { DirectMessageReactions = 1 << 13, DirectMessageTyping = 1 << 14, GuildScheduledEvents = 1 << 16, + AutoModerationConfiguration = 1 << 20, + AutoModerationExecution = 1 << 21, } /** @@ -251,6 +256,10 @@ export enum GatewayDispatchEvents { GuildScheduledEventDelete = 'GUILD_SCHEDULED_EVENT_DELETE', GuildScheduledEventUserAdd = 'GUILD_SCHEDULED_EVENT_USER_ADD', GuildScheduledEventUserRemove = 'GUILD_SCHEDULED_EVENT_USER_REMOVE', + AutoModerationRuleCreate = 'AUTO_MODERATION_RULE_CREATE', + AutoModerationRuleUpdate = 'AUTO_MODERATION_RULE_UPDATE', + AutoModerationRuleDelete = 'AUTO_MODERATION_RULE_DELETE', + AutoModerationActionExecution = 'AUTO_MODERATION_ACTION_EXECUTION', } export type GatewaySendPayload = @@ -431,6 +440,121 @@ export interface GatewayReadyDispatchData { */ export type GatewayResumedDispatch = DataPayload; +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-create + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-update + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-delete + */ +export type GatewayAutoModerationRuleModifyDispatch = DataPayload< + | GatewayDispatchEvents.AutoModerationRuleCreate + | GatewayDispatchEvents.AutoModerationRuleUpdate + | GatewayDispatchEvents.AutoModerationRuleDelete, + GatewayAutoModerationRuleModifyDispatchData +>; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-create + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-update + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-delete + */ +export type GatewayAutoModerationRuleModifyDispatchData = APIAutoModerationRule; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-create + */ +export type GatewayAutoModerationRuleCreateDispatch = GatewayAutoModerationRuleModifyDispatch; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-create + */ +export type GatewayAutoModerationRuleCreateDispatchData = GatewayAutoModerationRuleModifyDispatchData; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-update + */ +export type GatewayAutoModerationRuleUpdateDispatch = GatewayAutoModerationRuleModifyDispatch; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-update + */ +export type GatewayAutoModerationRuleUpdateDispatchData = GatewayAutoModerationRuleModifyDispatchData; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-delete + */ +export type GatewayAutoModerationRuleDeleteDispatch = GatewayAutoModerationRuleModifyDispatch; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-delete + */ +export type GatewayAutoModerationRuleDeleteDispatchData = GatewayAutoModerationRuleModifyDispatchData; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-action-execution + */ +export type GatewayAutoModerationActionExecutionDispatch = DataPayload< + GatewayDispatchEvents.AutoModerationActionExecution, + GatewayAutoModerationActionExecutionDispatchData +>; + +/** + * https://discord.com/developers/docs/topics/gateway-events#auto-moderation-action-execution + */ +export interface GatewayAutoModerationActionExecutionDispatchData { + /** + * The id of the guild in which action was executed + */ + guild_id: Snowflake; + /** + * The action which was executed + */ + action: APIAutoModerationAction; + /** + * The id of the rule which action belongs to + */ + rule_id: Snowflake; + /** + * The trigger type of rule which was triggered + */ + rule_trigger_type: AutoModerationRuleTriggerType; + /** + * The id of the user which generated the content which triggered the rule + */ + user_id: Snowflake; + /** + * The id of the channel in which user content was posted + */ + channel_id?: Snowflake; + /** + * The id of any user message which content belongs to + * + * This field will not be present if message was blocked by AutoMod or content was not part of any message + */ + message_id?: Snowflake; + /** + * The id of any system auto moderation messages posted as a result of this action + * + * This field will not be present if this event does not correspond to an action with type {@link AutoModerationActionType.SendAlertMessage} + */ + alert_system_message_id?: Snowflake; + /** + * The user generated text content + * + * `MESSAGE_CONTENT` (`1 << 15`) gateway intent is required to receive non-empty values from this field + */ + content: string; + /** + * The word or phrase configured in the rule that triggered the rule + */ + matched_keyword: string | null; + /** + * The substring in content that triggered the rule + * + * `MESSAGE_CONTENT` (`1 << 15`) gateway intent is required to receive non-empty values from this field + */ + matched_content: string | null; +} + /** * https://discord.com/developers/docs/topics/gateway#channel-create * https://discord.com/developers/docs/topics/gateway#channel-update diff --git a/deno/payloads/v10/auditLog.ts b/deno/payloads/v10/auditLog.ts index 6acca34ef..b610cd169 100644 --- a/deno/payloads/v10/auditLog.ts +++ b/deno/payloads/v10/auditLog.ts @@ -2,6 +2,13 @@ * Types extracted from https://discord.com/developers/docs/resources/audit-log */ +import type { + APIAutoModerationAction, + APIAutoModerationRule, + APIAutoModerationRuleTriggerMetadata, + AutoModerationRuleEventType, + AutoModerationRuleTriggerType, +} from './autoModeration.ts'; import type { APIChannel, APIOverwrite } from './channel.ts'; import type { APIGuildIntegration, @@ -52,6 +59,12 @@ export interface APIAuditLog { * See https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object */ audit_log_entries: APIAuditLogEntry[]; + /** + * List of auto moderation rules referenced in the audit log + * + * See https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object + */ + auto_moderation_rules: APIAutoModerationRule[]; /** * Partial integration objects * @@ -180,12 +193,37 @@ export enum AuditLogEvent { ThreadDelete, ApplicationCommandPermissionUpdate = 121, + + AutoModerationRuleCreate = 140, + AutoModerationRuleUpdate, + AutoModerationRuleDelete, + AutoModerationBlockMessage, + AutoModerationFlagToChannel, + AutoModerationUserCommunicationDisabled, } /** * https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info */ export interface APIAuditLogOptions { + /** + * Name of the Auto Moderation rule that was triggered + * + * Present from: + * - AUTO_MODERATION_BLOCK_MESSAGE + * - AUTO_MODERATION_FLAG_TO_CHANNEL + * - AUTO_MODERATION_USER_COMMUNICATION_DISABLED + */ + auto_moderation_rule_name?: string; + /** + * Trigger type of the Auto Moderation rule that was triggered + * + * Present from: + * - AUTO_MODERATION_BLOCK_MESSAGE + * - AUTO_MODERATION_FLAG_TO_CHANNEL + * - AUTO_MODERATION_USER_COMMUNICATION_DISABLED + */ + auto_moderation_rule_trigger_type?: string; /** * Number of days after which inactive members were kicked * @@ -212,6 +250,9 @@ export interface APIAuditLogOptions { * - STAGE_INSTANCE_CREATE * - STAGE_INSTANCE_UPDATE * - STAGE_INSTANCE_DELETE + * - AUTO_MODERATION_BLOCK_MESSAGE + * - AUTO_MODERATION_FLAG_TO_CHANNEL + * - AUTO_MODERATION_USER_COMMUNICATION_DISABLED */ channel_id?: Snowflake; @@ -347,7 +388,14 @@ export type APIAuditLogChange = | APIAuditLogChangeKeyEntityType | APIAuditLogChangeKeyStatus | APIAuditLogChangeKeyLocation - | APIAuditLogChangeKeyCommunicationDisabledUntil; + | APIAuditLogChangeKeyCommunicationDisabledUntil + | APIAuditLogChangeKeyTriggerType + | APIAuditLogChangeKeyEventType + | APIAuditLogChangeKeyTriggerMetadata + | APIAuditLogChangeKeyActions + | APIAuditLogChangeKeyEnabled + | APIAuditLogChangeKeyExemptRoles + | APIAuditLogChangeKeyExemptChannels; /** * Returned when an entity's name is changed @@ -710,6 +758,44 @@ export type APIAuditLogChangeKeyLocation = AuditLogChangeData<'location', string */ export type APIAuditLogChangeKeyCommunicationDisabledUntil = AuditLogChangeData<'communication_disabled_until', string>; +/** + * Returned when an auto moderation rule's trigger type is changed (only in rule creation or deletion) + */ +export type APIAuditLogChangeKeyTriggerType = AuditLogChangeData<'trigger_type', AutoModerationRuleTriggerType>; + +/** + * Returned when an auto moderation rule's event type is changed + */ +export type APIAuditLogChangeKeyEventType = AuditLogChangeData<'event_type', AutoModerationRuleEventType>; + +/** + * Returned when an auto moderation rule's trigger metadata is changed + */ +export type APIAuditLogChangeKeyTriggerMetadata = AuditLogChangeData< + 'trigger_metadata', + APIAutoModerationRuleTriggerMetadata +>; + +/** + * Returned when an auto moderation rule's actions is changed + */ +export type APIAuditLogChangeKeyActions = AuditLogChangeData<'actions', APIAutoModerationAction[]>; + +/** + * Returned when an auto moderation rule's enabled status is changed + */ +export type APIAuditLogChangeKeyEnabled = AuditLogChangeData<'enabled', boolean>; + +/** + * Returned when an auto moderation rule's exempt roles is changed + */ +export type APIAuditLogChangeKeyExemptRoles = AuditLogChangeData<'exempt_roles', Snowflake[]>; + +/** + * Returned when an auto moderation rule's exempt channels is changed + */ +export type APIAuditLogChangeKeyExemptChannels = AuditLogChangeData<'exempt_channels', Snowflake[]>; + interface AuditLogChangeData { key: K; /** diff --git a/deno/payloads/v10/autoModeration.ts b/deno/payloads/v10/autoModeration.ts new file mode 100644 index 000000000..e36bd15eb --- /dev/null +++ b/deno/payloads/v10/autoModeration.ts @@ -0,0 +1,195 @@ +/** + * Types extracted from https://discord.com/developers/docs/resources/auto-moderation + */ + +import type { Snowflake } from '../../globals.ts'; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-auto-moderation-rule-structure + */ +export interface APIAutoModerationRule { + /** + * The id of this rule + */ + id: Snowflake; + /** + * The guild which this rule belongs to + */ + guild_id: Snowflake; + /** + * The rule name + */ + name: string; + /** + * The user id who created this rule + */ + creator_id: Snowflake; + /** + * The rule event type + */ + event_type: AutoModerationRuleEventType; + /** + * The rule trigger type + */ + trigger_type: AutoModerationRuleTriggerType; + /** + * The rule trigger metadata + */ + trigger_metadata: APIAutoModerationRuleTriggerMetadata; + /** + * The actions which will execute when this rule is triggered + */ + actions: APIAutoModerationAction[]; + /** + * Whether this rule is enabled + */ + enabled: boolean; + /** + * The role ids that shouldn't be affected by this rule (Maximum of 20) + */ + exempt_roles: Snowflake[]; + /** + * The channel ids that shouldn't be affected by this rule (Maximum of 50) + */ + exempt_channels: Snowflake[]; +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types + */ +export enum AutoModerationRuleTriggerType { + /** + * Check if content contains words from a user defined list of keywords (Maximum of 3 per guild) + */ + Keyword = 1, + /** + * Check if content represents generic spam (Maximum of 1 per guild) + */ + Spam = 3, + /** + * Check if content contains words from internal pre-defined wordsets (Maximum of 1 per guild) + */ + KeywordPreset, + /** + * Check if content contains more mentions than allowed (Maximum of 1 per guild) + */ + MentionSpam, +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata + */ +export interface APIAutoModerationRuleTriggerMetadata { + /** + * Substrings which will be searched for in content (Maximum of 1000) + * + * A keyword can be a phrase which contains multiple words. Wildcard symbols can be used to customize how each string will be matched. Each keyword must be 30 characters or less + * See [keyword matching strategies](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies) + * + * Associated trigger type: {@link AutoModerationRuleTriggerType.Keyword} + */ + keyword_filter?: string[]; + /** + * The internally pre-defined wordsets which will be searched for in content + * + * Associated trigger type: {@link AutoModerationRuleTriggerType.KeywordPreset} + */ + presets?: AutoModerationRuleKeywordPresetType[]; + /** + * Substrings which will be exempt from triggering the preset trigger type (Maximum of 1000) + * + * A allowed-word can be a phrase which contains multiple words. Wildcard symbols can be used to customize how each string will be matched. Each keyword must be 30 characters or less + * See [keyword matching strategies](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies) + * + * Associated trigger type: {@link AutoModerationRuleTriggerType.KeywordPreset} + */ + allow_list?: string[]; + /** + * Total number of mentions (role & user) allowed per message (Maximum of 50) + * + * Associated trigger type: {@link AutoModerationRuleTriggerType.MentionSpam} + */ + mention_total_limit?: number; +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-preset-types + */ +export enum AutoModerationRuleKeywordPresetType { + /** + * Words that may be considered forms of swearing or cursing + */ + Profanity = 1, + /** + * Words that refer to sexually explicit behavior or activity + */ + SexualContent, + /** + * Personal insults or words that may be considered hate speech + */ + Slurs, +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types + */ +export enum AutoModerationRuleEventType { + /** + * When a member sends or edits a message in the guild + */ + MessageSend = 1, +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-auto-moderation-action-structure + */ +export interface APIAutoModerationAction { + /** + * The action type + */ + type: AutoModerationActionType; + /** + * Additional metadata needed during execution for this specific action type + * + * Will only be omitted if the action type is {@link AutoModerationActionType.BlockMessage} + */ + metadata?: APIAutoModerationActionMetadata; +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types + */ +export enum AutoModerationActionType { + /** + * Blocks the content of a message according to the rule + */ + BlockMessage = 1, + /** + * Logs user content to a specified channel + */ + SendAlertMessage, + /** + * Timeout user for specified duration, this action type can be set if the bot has `MODERATE_MEMBERS` permission + */ + Timeout, +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-metadata + */ +export interface APIAutoModerationActionMetadata { + /** + * Channel to which user content should be logged + * + * Associated action type: {@link AutoModerationActionType.SendAlertMessage} + */ + channel_id?: Snowflake; + /** + * Timeout duration in seconds (Maximum of 4 weeks - 2419200 seconds) + * + * Only available if using {@link AutoModerationRuleTriggerType.Keyword} + * + * Associated action type: {@link AutoModerationActionType.Timeout} + */ + duration_seconds?: number; +} diff --git a/deno/payloads/v10/channel.ts b/deno/payloads/v10/channel.ts index 40cfaedfe..222ae3112 100644 --- a/deno/payloads/v10/channel.ts +++ b/deno/payloads/v10/channel.ts @@ -667,6 +667,7 @@ export enum MessageType { ThreadStarterMessage, GuildInviteReminder, ContextMenuCommand, + AutoModerationAction, } /** @@ -1019,6 +1020,12 @@ export enum EmbedType { * Link embed */ Link = 'link', + /** + * Auto moderation alert embed + * + * @unstable This embed type is currently not documented by Discord, but it is returned in the auto moderation system messages. + */ + AutoModerationMessage = 'auto_moderation_message', } /** diff --git a/deno/payloads/v10/guild.ts b/deno/payloads/v10/guild.ts index c0d60aa85..b425da3f7 100644 --- a/deno/payloads/v10/guild.ts +++ b/deno/payloads/v10/guild.ts @@ -382,6 +382,10 @@ export enum GuildFeature { * Guild has access to set an animated guild icon */ AnimatedIcon = 'ANIMATED_ICON', + /** + * Guild has set up auto moderation rules + */ + AutoModeration = 'AUTO_MODERATION', /** * Guild has access to set a guild banner image */ diff --git a/deno/payloads/v10/mod.ts b/deno/payloads/v10/mod.ts index 809966d7d..9143395b3 100644 --- a/deno/payloads/v10/mod.ts +++ b/deno/payloads/v10/mod.ts @@ -1,6 +1,7 @@ export * from '../common.ts'; export * from './application.ts'; export * from './auditLog.ts'; +export * from './autoModeration.ts'; export * from './channel.ts'; export * from './emoji.ts'; export * from './gateway.ts'; diff --git a/deno/payloads/v9/auditLog.ts b/deno/payloads/v9/auditLog.ts index 6acca34ef..b610cd169 100644 --- a/deno/payloads/v9/auditLog.ts +++ b/deno/payloads/v9/auditLog.ts @@ -2,6 +2,13 @@ * Types extracted from https://discord.com/developers/docs/resources/audit-log */ +import type { + APIAutoModerationAction, + APIAutoModerationRule, + APIAutoModerationRuleTriggerMetadata, + AutoModerationRuleEventType, + AutoModerationRuleTriggerType, +} from './autoModeration.ts'; import type { APIChannel, APIOverwrite } from './channel.ts'; import type { APIGuildIntegration, @@ -52,6 +59,12 @@ export interface APIAuditLog { * See https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object */ audit_log_entries: APIAuditLogEntry[]; + /** + * List of auto moderation rules referenced in the audit log + * + * See https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object + */ + auto_moderation_rules: APIAutoModerationRule[]; /** * Partial integration objects * @@ -180,12 +193,37 @@ export enum AuditLogEvent { ThreadDelete, ApplicationCommandPermissionUpdate = 121, + + AutoModerationRuleCreate = 140, + AutoModerationRuleUpdate, + AutoModerationRuleDelete, + AutoModerationBlockMessage, + AutoModerationFlagToChannel, + AutoModerationUserCommunicationDisabled, } /** * https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info */ export interface APIAuditLogOptions { + /** + * Name of the Auto Moderation rule that was triggered + * + * Present from: + * - AUTO_MODERATION_BLOCK_MESSAGE + * - AUTO_MODERATION_FLAG_TO_CHANNEL + * - AUTO_MODERATION_USER_COMMUNICATION_DISABLED + */ + auto_moderation_rule_name?: string; + /** + * Trigger type of the Auto Moderation rule that was triggered + * + * Present from: + * - AUTO_MODERATION_BLOCK_MESSAGE + * - AUTO_MODERATION_FLAG_TO_CHANNEL + * - AUTO_MODERATION_USER_COMMUNICATION_DISABLED + */ + auto_moderation_rule_trigger_type?: string; /** * Number of days after which inactive members were kicked * @@ -212,6 +250,9 @@ export interface APIAuditLogOptions { * - STAGE_INSTANCE_CREATE * - STAGE_INSTANCE_UPDATE * - STAGE_INSTANCE_DELETE + * - AUTO_MODERATION_BLOCK_MESSAGE + * - AUTO_MODERATION_FLAG_TO_CHANNEL + * - AUTO_MODERATION_USER_COMMUNICATION_DISABLED */ channel_id?: Snowflake; @@ -347,7 +388,14 @@ export type APIAuditLogChange = | APIAuditLogChangeKeyEntityType | APIAuditLogChangeKeyStatus | APIAuditLogChangeKeyLocation - | APIAuditLogChangeKeyCommunicationDisabledUntil; + | APIAuditLogChangeKeyCommunicationDisabledUntil + | APIAuditLogChangeKeyTriggerType + | APIAuditLogChangeKeyEventType + | APIAuditLogChangeKeyTriggerMetadata + | APIAuditLogChangeKeyActions + | APIAuditLogChangeKeyEnabled + | APIAuditLogChangeKeyExemptRoles + | APIAuditLogChangeKeyExemptChannels; /** * Returned when an entity's name is changed @@ -710,6 +758,44 @@ export type APIAuditLogChangeKeyLocation = AuditLogChangeData<'location', string */ export type APIAuditLogChangeKeyCommunicationDisabledUntil = AuditLogChangeData<'communication_disabled_until', string>; +/** + * Returned when an auto moderation rule's trigger type is changed (only in rule creation or deletion) + */ +export type APIAuditLogChangeKeyTriggerType = AuditLogChangeData<'trigger_type', AutoModerationRuleTriggerType>; + +/** + * Returned when an auto moderation rule's event type is changed + */ +export type APIAuditLogChangeKeyEventType = AuditLogChangeData<'event_type', AutoModerationRuleEventType>; + +/** + * Returned when an auto moderation rule's trigger metadata is changed + */ +export type APIAuditLogChangeKeyTriggerMetadata = AuditLogChangeData< + 'trigger_metadata', + APIAutoModerationRuleTriggerMetadata +>; + +/** + * Returned when an auto moderation rule's actions is changed + */ +export type APIAuditLogChangeKeyActions = AuditLogChangeData<'actions', APIAutoModerationAction[]>; + +/** + * Returned when an auto moderation rule's enabled status is changed + */ +export type APIAuditLogChangeKeyEnabled = AuditLogChangeData<'enabled', boolean>; + +/** + * Returned when an auto moderation rule's exempt roles is changed + */ +export type APIAuditLogChangeKeyExemptRoles = AuditLogChangeData<'exempt_roles', Snowflake[]>; + +/** + * Returned when an auto moderation rule's exempt channels is changed + */ +export type APIAuditLogChangeKeyExemptChannels = AuditLogChangeData<'exempt_channels', Snowflake[]>; + interface AuditLogChangeData { key: K; /** diff --git a/deno/payloads/v9/autoModeration.ts b/deno/payloads/v9/autoModeration.ts new file mode 100644 index 000000000..e36bd15eb --- /dev/null +++ b/deno/payloads/v9/autoModeration.ts @@ -0,0 +1,195 @@ +/** + * Types extracted from https://discord.com/developers/docs/resources/auto-moderation + */ + +import type { Snowflake } from '../../globals.ts'; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-auto-moderation-rule-structure + */ +export interface APIAutoModerationRule { + /** + * The id of this rule + */ + id: Snowflake; + /** + * The guild which this rule belongs to + */ + guild_id: Snowflake; + /** + * The rule name + */ + name: string; + /** + * The user id who created this rule + */ + creator_id: Snowflake; + /** + * The rule event type + */ + event_type: AutoModerationRuleEventType; + /** + * The rule trigger type + */ + trigger_type: AutoModerationRuleTriggerType; + /** + * The rule trigger metadata + */ + trigger_metadata: APIAutoModerationRuleTriggerMetadata; + /** + * The actions which will execute when this rule is triggered + */ + actions: APIAutoModerationAction[]; + /** + * Whether this rule is enabled + */ + enabled: boolean; + /** + * The role ids that shouldn't be affected by this rule (Maximum of 20) + */ + exempt_roles: Snowflake[]; + /** + * The channel ids that shouldn't be affected by this rule (Maximum of 50) + */ + exempt_channels: Snowflake[]; +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types + */ +export enum AutoModerationRuleTriggerType { + /** + * Check if content contains words from a user defined list of keywords (Maximum of 3 per guild) + */ + Keyword = 1, + /** + * Check if content represents generic spam (Maximum of 1 per guild) + */ + Spam = 3, + /** + * Check if content contains words from internal pre-defined wordsets (Maximum of 1 per guild) + */ + KeywordPreset, + /** + * Check if content contains more mentions than allowed (Maximum of 1 per guild) + */ + MentionSpam, +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata + */ +export interface APIAutoModerationRuleTriggerMetadata { + /** + * Substrings which will be searched for in content (Maximum of 1000) + * + * A keyword can be a phrase which contains multiple words. Wildcard symbols can be used to customize how each string will be matched. Each keyword must be 30 characters or less + * See [keyword matching strategies](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies) + * + * Associated trigger type: {@link AutoModerationRuleTriggerType.Keyword} + */ + keyword_filter?: string[]; + /** + * The internally pre-defined wordsets which will be searched for in content + * + * Associated trigger type: {@link AutoModerationRuleTriggerType.KeywordPreset} + */ + presets?: AutoModerationRuleKeywordPresetType[]; + /** + * Substrings which will be exempt from triggering the preset trigger type (Maximum of 1000) + * + * A allowed-word can be a phrase which contains multiple words. Wildcard symbols can be used to customize how each string will be matched. Each keyword must be 30 characters or less + * See [keyword matching strategies](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies) + * + * Associated trigger type: {@link AutoModerationRuleTriggerType.KeywordPreset} + */ + allow_list?: string[]; + /** + * Total number of mentions (role & user) allowed per message (Maximum of 50) + * + * Associated trigger type: {@link AutoModerationRuleTriggerType.MentionSpam} + */ + mention_total_limit?: number; +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-preset-types + */ +export enum AutoModerationRuleKeywordPresetType { + /** + * Words that may be considered forms of swearing or cursing + */ + Profanity = 1, + /** + * Words that refer to sexually explicit behavior or activity + */ + SexualContent, + /** + * Personal insults or words that may be considered hate speech + */ + Slurs, +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types + */ +export enum AutoModerationRuleEventType { + /** + * When a member sends or edits a message in the guild + */ + MessageSend = 1, +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-auto-moderation-action-structure + */ +export interface APIAutoModerationAction { + /** + * The action type + */ + type: AutoModerationActionType; + /** + * Additional metadata needed during execution for this specific action type + * + * Will only be omitted if the action type is {@link AutoModerationActionType.BlockMessage} + */ + metadata?: APIAutoModerationActionMetadata; +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types + */ +export enum AutoModerationActionType { + /** + * Blocks the content of a message according to the rule + */ + BlockMessage = 1, + /** + * Logs user content to a specified channel + */ + SendAlertMessage, + /** + * Timeout user for specified duration, this action type can be set if the bot has `MODERATE_MEMBERS` permission + */ + Timeout, +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-metadata + */ +export interface APIAutoModerationActionMetadata { + /** + * Channel to which user content should be logged + * + * Associated action type: {@link AutoModerationActionType.SendAlertMessage} + */ + channel_id?: Snowflake; + /** + * Timeout duration in seconds (Maximum of 4 weeks - 2419200 seconds) + * + * Only available if using {@link AutoModerationRuleTriggerType.Keyword} + * + * Associated action type: {@link AutoModerationActionType.Timeout} + */ + duration_seconds?: number; +} diff --git a/deno/payloads/v9/channel.ts b/deno/payloads/v9/channel.ts index e0a184ec0..f26c88a7c 100644 --- a/deno/payloads/v9/channel.ts +++ b/deno/payloads/v9/channel.ts @@ -662,6 +662,7 @@ export enum MessageType { ThreadStarterMessage, GuildInviteReminder, ContextMenuCommand, + AutoModerationAction, } /** @@ -1018,6 +1019,12 @@ export enum EmbedType { * Link embed */ Link = 'link', + /** + * Auto moderation alert embed + * + * @unstable This embed type is currently not documented by Discord, but it is returned in the auto moderation system messages. + */ + AutoModerationMessage = 'auto_moderation_message', } /** diff --git a/deno/payloads/v9/guild.ts b/deno/payloads/v9/guild.ts index c0d60aa85..b425da3f7 100644 --- a/deno/payloads/v9/guild.ts +++ b/deno/payloads/v9/guild.ts @@ -382,6 +382,10 @@ export enum GuildFeature { * Guild has access to set an animated guild icon */ AnimatedIcon = 'ANIMATED_ICON', + /** + * Guild has set up auto moderation rules + */ + AutoModeration = 'AUTO_MODERATION', /** * Guild has access to set a guild banner image */ diff --git a/deno/payloads/v9/mod.ts b/deno/payloads/v9/mod.ts index 809966d7d..9143395b3 100644 --- a/deno/payloads/v9/mod.ts +++ b/deno/payloads/v9/mod.ts @@ -1,6 +1,7 @@ export * from '../common.ts'; export * from './application.ts'; export * from './auditLog.ts'; +export * from './autoModeration.ts'; export * from './channel.ts'; export * from './emoji.ts'; export * from './gateway.ts'; diff --git a/deno/rest/v10/autoModeration.ts b/deno/rest/v10/autoModeration.ts new file mode 100644 index 000000000..23a7f6a38 --- /dev/null +++ b/deno/rest/v10/autoModeration.ts @@ -0,0 +1,84 @@ +import type { Snowflake } from '../../globals.ts'; +import type { + APIAutoModerationAction, + APIAutoModerationRule, + AutoModerationRuleEventType, + APIAutoModerationRuleTriggerMetadata, + AutoModerationRuleTriggerType, +} from '../../payloads/v10/mod.ts'; +import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface } from '../../utils/internals.ts'; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#list-auto-moderation-rules-for-guild + */ +export type RESTGetAPIAutoModerationRulesResult = APIAutoModerationRule[]; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#get-auto-moderation-rule + */ +export type RESTGetAPIAutoModerationRuleResult = APIAutoModerationRule; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#create-auto-moderation-rule + */ +export type RESTPostAPIAutoModerationRuleJSONBody = AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{ + /** + * The rule name + */ + name: string; + /** + * The rule event type + */ + event_type: AutoModerationRuleEventType; + /** + * The rule trigger type + */ + trigger_type: AutoModerationRuleTriggerType; + /** + * The rule trigger metadata + * + * Can be omitted if the trigger type is {@link AutoModerationRuleTriggerType.HarmfulLink} or {@link AutoModerationRuleTriggerType.Spam} + */ + trigger_metadata?: APIAutoModerationRuleTriggerMetadata; + /** + * The actions which will execute when this rule is triggered + */ + actions: APIAutoModerationAction[]; + /** + * Whether this rule is enabled + * + * @default false + */ + enabled?: boolean; + /** + * The role ids that shouldn't be affected by this rule (Maximum of 20) + */ + exempt_roles?: Snowflake[]; + /** + * The channel ids that shouldn't be affected by this rule (Maximum of 50) + */ + exempt_channels?: Snowflake[]; +}>; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#create-auto-moderation-rule + */ +export type RESTPostAPIAutoModerationRuleResult = APIAutoModerationRule; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#modify-auto-moderation-rule + */ +export type RESTPatchAPIAutoModerationRuleJSONBody = Omit< + Partial, + 'trigger_type' +>; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#modify-auto-moderation-rule + */ +export type RESTPatchAPIAutoModerationRuleResult = APIAutoModerationRule; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#delete-auto-moderation-rule + */ +export type RESTDeleteAPIAutoModerationRuleResult = never; diff --git a/deno/rest/v10/mod.ts b/deno/rest/v10/mod.ts index eed5b7def..a7f0d1e91 100644 --- a/deno/rest/v10/mod.ts +++ b/deno/rest/v10/mod.ts @@ -20,6 +20,25 @@ export * from './webhook.ts'; export const APIVersion = '10'; export const Routes = { + /** + * Route for: + * - GET `/guilds/{guild.id}/auto-moderation/rules` + * - POST `/guilds/{guild.id}/auto-moderation/rules` + */ + guildAutoModerationRules(guildId: Snowflake) { + return `/guilds/${guildId}/auto-moderation/rules`; + }, + + /** + * Routes for: + * - GET `/guilds/{guild.id}/auto-moderation/rules/{rule.id}` + * - PATCH `/guilds/{guild.id}/auto-moderation/rules/{rule.id}` + * - DELETE `/guilds/{guild.id}/auto-moderation/rules/{rule.id}` + */ + guildAutoModerationRule(guildId: Snowflake, ruleId: Snowflake) { + return `/guilds/${guildId}/auto-moderation/rules/${ruleId}`; + }, + /** * Route for: * - GET `/guilds/{guild.id}/audit-logs` diff --git a/deno/rest/v9/autoModeration.ts b/deno/rest/v9/autoModeration.ts new file mode 100644 index 000000000..5ef585eea --- /dev/null +++ b/deno/rest/v9/autoModeration.ts @@ -0,0 +1,84 @@ +import type { Snowflake } from '../../globals.ts'; +import type { + APIAutoModerationAction, + APIAutoModerationRule, + AutoModerationRuleEventType, + APIAutoModerationRuleTriggerMetadata, + AutoModerationRuleTriggerType, +} from '../../payloads/v9/mod.ts'; +import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface } from '../../utils/internals.ts'; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#list-auto-moderation-rules-for-guild + */ +export type RESTGetAPIAutoModerationRulesResult = APIAutoModerationRule[]; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#get-auto-moderation-rule + */ +export type RESTGetAPIAutoModerationRuleResult = APIAutoModerationRule; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#create-auto-moderation-rule + */ +export type RESTPostAPIAutoModerationRuleJSONBody = AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{ + /** + * The rule name + */ + name: string; + /** + * The rule event type + */ + event_type: AutoModerationRuleEventType; + /** + * The rule trigger type + */ + trigger_type: AutoModerationRuleTriggerType; + /** + * The rule trigger metadata + * + * Can be omitted if the trigger type is {@link AutoModerationRuleTriggerType.HarmfulLink} or {@link AutoModerationRuleTriggerType.Spam} + */ + trigger_metadata?: APIAutoModerationRuleTriggerMetadata; + /** + * The actions which will execute when this rule is triggered + */ + actions: APIAutoModerationAction[]; + /** + * Whether this rule is enabled + * + * @default false + */ + enabled?: boolean; + /** + * The role ids that shouldn't be affected by this rule (Maximum of 20) + */ + exempt_roles?: Snowflake[]; + /** + * The channel ids that shouldn't be affected by this rule (Maximum of 50) + */ + exempt_channels?: Snowflake[]; +}>; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#create-auto-moderation-rule + */ +export type RESTPostAPIAutoModerationRuleResult = APIAutoModerationRule; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#modify-auto-moderation-rule + */ +export type RESTPatchAPIAutoModerationRuleJSONBody = Omit< + Partial, + 'trigger_type' +>; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#modify-auto-moderation-rule + */ +export type RESTPatchAPIAutoModerationRuleResult = APIAutoModerationRule; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#delete-auto-moderation-rule + */ +export type RESTDeleteAPIAutoModerationRuleResult = never; diff --git a/deno/rest/v9/mod.ts b/deno/rest/v9/mod.ts index fd7b71391..4071b31d3 100644 --- a/deno/rest/v9/mod.ts +++ b/deno/rest/v9/mod.ts @@ -2,6 +2,7 @@ import type { Snowflake } from '../../globals.ts'; export * from '../common.ts'; export * from './auditLog.ts'; +export * from './autoModeration.ts'; export * from './channel.ts'; export * from './emoji.ts'; export * from './gateway.ts'; @@ -20,6 +21,25 @@ export * from './webhook.ts'; export const APIVersion = '9'; export const Routes = { + /** + * Route for: + * - GET `/guilds/{guild.id}/auto-moderation/rules` + * - POST `/guilds/{guild.id}/auto-moderation/rules` + */ + guildAutoModerationRules(guildId: Snowflake) { + return `/guilds/${guildId}/auto-moderation/rules`; + }, + + /** + * Routes for: + * - GET `/guilds/{guild.id}/auto-moderation/rules/{rule.id}` + * - PATCH `/guilds/{guild.id}/auto-moderation/rules/{rule.id}` + * - DELETE `/guilds/{guild.id}/auto-moderation/rules/{rule.id}` + */ + guildAutoModerationRule(guildId: Snowflake, ruleId: Snowflake) { + return `/guilds/${guildId}/auto-moderation/rules/${ruleId}`; + }, + /** * Route for: * - GET `/guilds/{guild.id}/audit-logs` diff --git a/gateway/v10.ts b/gateway/v10.ts index a463141b7..5b7dc6909 100644 --- a/gateway/v10.ts +++ b/gateway/v10.ts @@ -6,6 +6,8 @@ import type { Snowflake } from '../globals'; import type { GatewayPresenceUpdate } from '../payloads/v10/gateway'; import type { APIApplication, + APIAutoModerationRule, + APIAutoModerationAction, APIChannel, APIEmoji, APIGuild, @@ -28,6 +30,7 @@ import type { GatewayVoiceState, InviteTargetType, PresenceUpdateStatus, + AutoModerationRuleTriggerType, } from '../payloads/v10/index'; import type { Nullable } from '../utils/internals'; @@ -190,6 +193,8 @@ export enum GatewayIntentBits { DirectMessageTyping = 1 << 14, MessageContent = 1 << 15, GuildScheduledEvents = 1 << 16, + AutoModerationConfiguration = 1 << 20, + AutoModerationExecution = 1 << 21, } /** @@ -252,6 +257,10 @@ export enum GatewayDispatchEvents { GuildScheduledEventDelete = 'GUILD_SCHEDULED_EVENT_DELETE', GuildScheduledEventUserAdd = 'GUILD_SCHEDULED_EVENT_USER_ADD', GuildScheduledEventUserRemove = 'GUILD_SCHEDULED_EVENT_USER_REMOVE', + AutoModerationRuleCreate = 'AUTO_MODERATION_RULE_CREATE', + AutoModerationRuleUpdate = 'AUTO_MODERATION_RULE_UPDATE', + AutoModerationRuleDelete = 'AUTO_MODERATION_RULE_DELETE', + AutoModerationActionExecution = 'AUTO_MODERATION_ACTION_EXECUTION', } export type GatewaySendPayload = @@ -432,6 +441,121 @@ export interface GatewayReadyDispatchData { */ export type GatewayResumedDispatch = DataPayload; +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-create + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-update + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-delete + */ +export type GatewayAutoModerationRuleModifyDispatch = DataPayload< + | GatewayDispatchEvents.AutoModerationRuleCreate + | GatewayDispatchEvents.AutoModerationRuleUpdate + | GatewayDispatchEvents.AutoModerationRuleDelete, + GatewayAutoModerationRuleModifyDispatchData +>; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-create + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-update + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-delete + */ +export type GatewayAutoModerationRuleModifyDispatchData = APIAutoModerationRule; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-create + */ +export type GatewayAutoModerationRuleCreateDispatch = GatewayAutoModerationRuleModifyDispatch; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-create + */ +export type GatewayAutoModerationRuleCreateDispatchData = GatewayAutoModerationRuleModifyDispatchData; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-update + */ +export type GatewayAutoModerationRuleUpdateDispatch = GatewayAutoModerationRuleModifyDispatch; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-update + */ +export type GatewayAutoModerationRuleUpdateDispatchData = GatewayAutoModerationRuleModifyDispatchData; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-delete + */ +export type GatewayAutoModerationRuleDeleteDispatch = GatewayAutoModerationRuleModifyDispatch; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-delete + */ +export type GatewayAutoModerationRuleDeleteDispatchData = GatewayAutoModerationRuleModifyDispatchData; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-action-execution + */ +export type GatewayAutoModerationActionExecutionDispatch = DataPayload< + GatewayDispatchEvents.AutoModerationActionExecution, + GatewayAutoModerationActionExecutionDispatchData +>; + +/** + * https://discord.com/developers/docs/topics/gateway-events#auto-moderation-action-execution + */ +export interface GatewayAutoModerationActionExecutionDispatchData { + /** + * The id of the guild in which action was executed + */ + guild_id: Snowflake; + /** + * The action which was executed + */ + action: APIAutoModerationAction; + /** + * The id of the rule which action belongs to + */ + rule_id: Snowflake; + /** + * The trigger type of rule which was triggered + */ + rule_trigger_type: AutoModerationRuleTriggerType; + /** + * The id of the user which generated the content which triggered the rule + */ + user_id: Snowflake; + /** + * The id of the channel in which user content was posted + */ + channel_id?: Snowflake; + /** + * The id of any user message which content belongs to + * + * This field will not be present if message was blocked by AutoMod or content was not part of any message + */ + message_id?: Snowflake; + /** + * The id of any system auto moderation messages posted as a result of this action + * + * This field will not be present if this event does not correspond to an action with type {@link AutoModerationActionType.SendAlertMessage} + */ + alert_system_message_id?: Snowflake; + /** + * The user generated text content + * + * `MESSAGE_CONTENT` (`1 << 15`) gateway intent is required to receive non-empty values from this field + */ + content: string; + /** + * The word or phrase configured in the rule that triggered the rule + */ + matched_keyword: string | null; + /** + * The substring in content that triggered the rule + * + * `MESSAGE_CONTENT` (`1 << 15`) gateway intent is required to receive non-empty values from this field + */ + matched_content: string | null; +} + /** * https://discord.com/developers/docs/topics/gateway#channel-create * https://discord.com/developers/docs/topics/gateway#channel-update diff --git a/gateway/v9.ts b/gateway/v9.ts index e6ace3c9c..af0e598e4 100644 --- a/gateway/v9.ts +++ b/gateway/v9.ts @@ -6,6 +6,8 @@ import type { Snowflake } from '../globals'; import type { GatewayPresenceUpdate } from '../payloads/v9/gateway'; import type { APIApplication, + APIAutoModerationRule, + APIAutoModerationAction, APIChannel, APIEmoji, APIGuild, @@ -28,6 +30,7 @@ import type { GatewayVoiceState, InviteTargetType, PresenceUpdateStatus, + AutoModerationRuleTriggerType, } from '../payloads/v9/index'; import type { Nullable } from '../utils/internals'; @@ -189,6 +192,8 @@ export enum GatewayIntentBits { DirectMessageReactions = 1 << 13, DirectMessageTyping = 1 << 14, GuildScheduledEvents = 1 << 16, + AutoModerationConfiguration = 1 << 20, + AutoModerationExecution = 1 << 21, } /** @@ -251,6 +256,10 @@ export enum GatewayDispatchEvents { GuildScheduledEventDelete = 'GUILD_SCHEDULED_EVENT_DELETE', GuildScheduledEventUserAdd = 'GUILD_SCHEDULED_EVENT_USER_ADD', GuildScheduledEventUserRemove = 'GUILD_SCHEDULED_EVENT_USER_REMOVE', + AutoModerationRuleCreate = 'AUTO_MODERATION_RULE_CREATE', + AutoModerationRuleUpdate = 'AUTO_MODERATION_RULE_UPDATE', + AutoModerationRuleDelete = 'AUTO_MODERATION_RULE_DELETE', + AutoModerationActionExecution = 'AUTO_MODERATION_ACTION_EXECUTION', } export type GatewaySendPayload = @@ -431,6 +440,121 @@ export interface GatewayReadyDispatchData { */ export type GatewayResumedDispatch = DataPayload; +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-create + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-update + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-delete + */ +export type GatewayAutoModerationRuleModifyDispatch = DataPayload< + | GatewayDispatchEvents.AutoModerationRuleCreate + | GatewayDispatchEvents.AutoModerationRuleUpdate + | GatewayDispatchEvents.AutoModerationRuleDelete, + GatewayAutoModerationRuleModifyDispatchData +>; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-create + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-update + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-delete + */ +export type GatewayAutoModerationRuleModifyDispatchData = APIAutoModerationRule; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-create + */ +export type GatewayAutoModerationRuleCreateDispatch = GatewayAutoModerationRuleModifyDispatch; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-create + */ +export type GatewayAutoModerationRuleCreateDispatchData = GatewayAutoModerationRuleModifyDispatchData; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-update + */ +export type GatewayAutoModerationRuleUpdateDispatch = GatewayAutoModerationRuleModifyDispatch; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-update + */ +export type GatewayAutoModerationRuleUpdateDispatchData = GatewayAutoModerationRuleModifyDispatchData; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-delete + */ +export type GatewayAutoModerationRuleDeleteDispatch = GatewayAutoModerationRuleModifyDispatch; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-rule-delete + */ +export type GatewayAutoModerationRuleDeleteDispatchData = GatewayAutoModerationRuleModifyDispatchData; + +/** + * https://discord.com/developers/docs/topics/gateway#auto-moderation-action-execution + */ +export type GatewayAutoModerationActionExecutionDispatch = DataPayload< + GatewayDispatchEvents.AutoModerationActionExecution, + GatewayAutoModerationActionExecutionDispatchData +>; + +/** + * https://discord.com/developers/docs/topics/gateway-events#auto-moderation-action-execution + */ +export interface GatewayAutoModerationActionExecutionDispatchData { + /** + * The id of the guild in which action was executed + */ + guild_id: Snowflake; + /** + * The action which was executed + */ + action: APIAutoModerationAction; + /** + * The id of the rule which action belongs to + */ + rule_id: Snowflake; + /** + * The trigger type of rule which was triggered + */ + rule_trigger_type: AutoModerationRuleTriggerType; + /** + * The id of the user which generated the content which triggered the rule + */ + user_id: Snowflake; + /** + * The id of the channel in which user content was posted + */ + channel_id?: Snowflake; + /** + * The id of any user message which content belongs to + * + * This field will not be present if message was blocked by AutoMod or content was not part of any message + */ + message_id?: Snowflake; + /** + * The id of any system auto moderation messages posted as a result of this action + * + * This field will not be present if this event does not correspond to an action with type {@link AutoModerationActionType.SendAlertMessage} + */ + alert_system_message_id?: Snowflake; + /** + * The user generated text content + * + * `MESSAGE_CONTENT` (`1 << 15`) gateway intent is required to receive non-empty values from this field + */ + content: string; + /** + * The word or phrase configured in the rule that triggered the rule + */ + matched_keyword: string | null; + /** + * The substring in content that triggered the rule + * + * `MESSAGE_CONTENT` (`1 << 15`) gateway intent is required to receive non-empty values from this field + */ + matched_content: string | null; +} + /** * https://discord.com/developers/docs/topics/gateway#channel-create * https://discord.com/developers/docs/topics/gateway#channel-update diff --git a/payloads/v10/auditLog.ts b/payloads/v10/auditLog.ts index d9194e28e..db02eb37c 100644 --- a/payloads/v10/auditLog.ts +++ b/payloads/v10/auditLog.ts @@ -2,6 +2,13 @@ * Types extracted from https://discord.com/developers/docs/resources/audit-log */ +import type { + APIAutoModerationAction, + APIAutoModerationRule, + APIAutoModerationRuleTriggerMetadata, + AutoModerationRuleEventType, + AutoModerationRuleTriggerType, +} from './autoModeration'; import type { APIChannel, APIOverwrite } from './channel'; import type { APIGuildIntegration, @@ -52,6 +59,12 @@ export interface APIAuditLog { * See https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object */ audit_log_entries: APIAuditLogEntry[]; + /** + * List of auto moderation rules referenced in the audit log + * + * See https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object + */ + auto_moderation_rules: APIAutoModerationRule[]; /** * Partial integration objects * @@ -180,12 +193,37 @@ export enum AuditLogEvent { ThreadDelete, ApplicationCommandPermissionUpdate = 121, + + AutoModerationRuleCreate = 140, + AutoModerationRuleUpdate, + AutoModerationRuleDelete, + AutoModerationBlockMessage, + AutoModerationFlagToChannel, + AutoModerationUserCommunicationDisabled, } /** * https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info */ export interface APIAuditLogOptions { + /** + * Name of the Auto Moderation rule that was triggered + * + * Present from: + * - AUTO_MODERATION_BLOCK_MESSAGE + * - AUTO_MODERATION_FLAG_TO_CHANNEL + * - AUTO_MODERATION_USER_COMMUNICATION_DISABLED + */ + auto_moderation_rule_name?: string; + /** + * Trigger type of the Auto Moderation rule that was triggered + * + * Present from: + * - AUTO_MODERATION_BLOCK_MESSAGE + * - AUTO_MODERATION_FLAG_TO_CHANNEL + * - AUTO_MODERATION_USER_COMMUNICATION_DISABLED + */ + auto_moderation_rule_trigger_type?: string; /** * Number of days after which inactive members were kicked * @@ -212,6 +250,9 @@ export interface APIAuditLogOptions { * - STAGE_INSTANCE_CREATE * - STAGE_INSTANCE_UPDATE * - STAGE_INSTANCE_DELETE + * - AUTO_MODERATION_BLOCK_MESSAGE + * - AUTO_MODERATION_FLAG_TO_CHANNEL + * - AUTO_MODERATION_USER_COMMUNICATION_DISABLED */ channel_id?: Snowflake; @@ -347,7 +388,14 @@ export type APIAuditLogChange = | APIAuditLogChangeKeyEntityType | APIAuditLogChangeKeyStatus | APIAuditLogChangeKeyLocation - | APIAuditLogChangeKeyCommunicationDisabledUntil; + | APIAuditLogChangeKeyCommunicationDisabledUntil + | APIAuditLogChangeKeyTriggerType + | APIAuditLogChangeKeyEventType + | APIAuditLogChangeKeyTriggerMetadata + | APIAuditLogChangeKeyActions + | APIAuditLogChangeKeyEnabled + | APIAuditLogChangeKeyExemptRoles + | APIAuditLogChangeKeyExemptChannels; /** * Returned when an entity's name is changed @@ -710,6 +758,44 @@ export type APIAuditLogChangeKeyLocation = AuditLogChangeData<'location', string */ export type APIAuditLogChangeKeyCommunicationDisabledUntil = AuditLogChangeData<'communication_disabled_until', string>; +/** + * Returned when an auto moderation rule's trigger type is changed (only in rule creation or deletion) + */ +export type APIAuditLogChangeKeyTriggerType = AuditLogChangeData<'trigger_type', AutoModerationRuleTriggerType>; + +/** + * Returned when an auto moderation rule's event type is changed + */ +export type APIAuditLogChangeKeyEventType = AuditLogChangeData<'event_type', AutoModerationRuleEventType>; + +/** + * Returned when an auto moderation rule's trigger metadata is changed + */ +export type APIAuditLogChangeKeyTriggerMetadata = AuditLogChangeData< + 'trigger_metadata', + APIAutoModerationRuleTriggerMetadata +>; + +/** + * Returned when an auto moderation rule's actions is changed + */ +export type APIAuditLogChangeKeyActions = AuditLogChangeData<'actions', APIAutoModerationAction[]>; + +/** + * Returned when an auto moderation rule's enabled status is changed + */ +export type APIAuditLogChangeKeyEnabled = AuditLogChangeData<'enabled', boolean>; + +/** + * Returned when an auto moderation rule's exempt roles is changed + */ +export type APIAuditLogChangeKeyExemptRoles = AuditLogChangeData<'exempt_roles', Snowflake[]>; + +/** + * Returned when an auto moderation rule's exempt channels is changed + */ +export type APIAuditLogChangeKeyExemptChannels = AuditLogChangeData<'exempt_channels', Snowflake[]>; + interface AuditLogChangeData { key: K; /** diff --git a/payloads/v10/autoModeration.ts b/payloads/v10/autoModeration.ts new file mode 100644 index 000000000..3346f78a5 --- /dev/null +++ b/payloads/v10/autoModeration.ts @@ -0,0 +1,195 @@ +/** + * Types extracted from https://discord.com/developers/docs/resources/auto-moderation + */ + +import type { Snowflake } from '../../globals'; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-auto-moderation-rule-structure + */ +export interface APIAutoModerationRule { + /** + * The id of this rule + */ + id: Snowflake; + /** + * The guild which this rule belongs to + */ + guild_id: Snowflake; + /** + * The rule name + */ + name: string; + /** + * The user id who created this rule + */ + creator_id: Snowflake; + /** + * The rule event type + */ + event_type: AutoModerationRuleEventType; + /** + * The rule trigger type + */ + trigger_type: AutoModerationRuleTriggerType; + /** + * The rule trigger metadata + */ + trigger_metadata: APIAutoModerationRuleTriggerMetadata; + /** + * The actions which will execute when this rule is triggered + */ + actions: APIAutoModerationAction[]; + /** + * Whether this rule is enabled + */ + enabled: boolean; + /** + * The role ids that shouldn't be affected by this rule (Maximum of 20) + */ + exempt_roles: Snowflake[]; + /** + * The channel ids that shouldn't be affected by this rule (Maximum of 50) + */ + exempt_channels: Snowflake[]; +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types + */ +export enum AutoModerationRuleTriggerType { + /** + * Check if content contains words from a user defined list of keywords (Maximum of 3 per guild) + */ + Keyword = 1, + /** + * Check if content represents generic spam (Maximum of 1 per guild) + */ + Spam = 3, + /** + * Check if content contains words from internal pre-defined wordsets (Maximum of 1 per guild) + */ + KeywordPreset, + /** + * Check if content contains more mentions than allowed (Maximum of 1 per guild) + */ + MentionSpam, +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata + */ +export interface APIAutoModerationRuleTriggerMetadata { + /** + * Substrings which will be searched for in content (Maximum of 1000) + * + * A keyword can be a phrase which contains multiple words. Wildcard symbols can be used to customize how each string will be matched. Each keyword must be 30 characters or less + * See [keyword matching strategies](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies) + * + * Associated trigger type: {@link AutoModerationRuleTriggerType.Keyword} + */ + keyword_filter?: string[]; + /** + * The internally pre-defined wordsets which will be searched for in content + * + * Associated trigger type: {@link AutoModerationRuleTriggerType.KeywordPreset} + */ + presets?: AutoModerationRuleKeywordPresetType[]; + /** + * Substrings which will be exempt from triggering the preset trigger type (Maximum of 1000) + * + * A allowed-word can be a phrase which contains multiple words. Wildcard symbols can be used to customize how each string will be matched. Each keyword must be 30 characters or less + * See [keyword matching strategies](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies) + * + * Associated trigger type: {@link AutoModerationRuleTriggerType.KeywordPreset} + */ + allow_list?: string[]; + /** + * Total number of mentions (role & user) allowed per message (Maximum of 50) + * + * Associated trigger type: {@link AutoModerationRuleTriggerType.MentionSpam} + */ + mention_total_limit?: number; +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-preset-types + */ +export enum AutoModerationRuleKeywordPresetType { + /** + * Words that may be considered forms of swearing or cursing + */ + Profanity = 1, + /** + * Words that refer to sexually explicit behavior or activity + */ + SexualContent, + /** + * Personal insults or words that may be considered hate speech + */ + Slurs, +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types + */ +export enum AutoModerationRuleEventType { + /** + * When a member sends or edits a message in the guild + */ + MessageSend = 1, +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-auto-moderation-action-structure + */ +export interface APIAutoModerationAction { + /** + * The action type + */ + type: AutoModerationActionType; + /** + * Additional metadata needed during execution for this specific action type + * + * Will only be omitted if the action type is {@link AutoModerationActionType.BlockMessage} + */ + metadata?: APIAutoModerationActionMetadata; +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types + */ +export enum AutoModerationActionType { + /** + * Blocks the content of a message according to the rule + */ + BlockMessage = 1, + /** + * Logs user content to a specified channel + */ + SendAlertMessage, + /** + * Timeout user for specified duration, this action type can be set if the bot has `MODERATE_MEMBERS` permission + */ + Timeout, +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-metadata + */ +export interface APIAutoModerationActionMetadata { + /** + * Channel to which user content should be logged + * + * Associated action type: {@link AutoModerationActionType.SendAlertMessage} + */ + channel_id?: Snowflake; + /** + * Timeout duration in seconds (Maximum of 4 weeks - 2419200 seconds) + * + * Only available if using {@link AutoModerationRuleTriggerType.Keyword} + * + * Associated action type: {@link AutoModerationActionType.Timeout} + */ + duration_seconds?: number; +} diff --git a/payloads/v10/channel.ts b/payloads/v10/channel.ts index d743ac644..98ce836e0 100644 --- a/payloads/v10/channel.ts +++ b/payloads/v10/channel.ts @@ -667,6 +667,7 @@ export enum MessageType { ThreadStarterMessage, GuildInviteReminder, ContextMenuCommand, + AutoModerationAction, } /** @@ -1019,6 +1020,12 @@ export enum EmbedType { * Link embed */ Link = 'link', + /** + * Auto moderation alert embed + * + * @unstable This embed type is currently not documented by Discord, but it is returned in the auto moderation system messages. + */ + AutoModerationMessage = 'auto_moderation_message', } /** diff --git a/payloads/v10/guild.ts b/payloads/v10/guild.ts index 82b8f935a..76014876d 100644 --- a/payloads/v10/guild.ts +++ b/payloads/v10/guild.ts @@ -382,6 +382,10 @@ export enum GuildFeature { * Guild has access to set an animated guild icon */ AnimatedIcon = 'ANIMATED_ICON', + /** + * Guild has set up auto moderation rules + */ + AutoModeration = 'AUTO_MODERATION', /** * Guild has access to set a guild banner image */ diff --git a/payloads/v10/index.ts b/payloads/v10/index.ts index 1c0980539..b83fd0968 100644 --- a/payloads/v10/index.ts +++ b/payloads/v10/index.ts @@ -1,6 +1,7 @@ export * from '../common'; export * from './application'; export * from './auditLog'; +export * from './autoModeration'; export * from './channel'; export * from './emoji'; export * from './gateway'; diff --git a/payloads/v9/auditLog.ts b/payloads/v9/auditLog.ts index d9194e28e..db02eb37c 100644 --- a/payloads/v9/auditLog.ts +++ b/payloads/v9/auditLog.ts @@ -2,6 +2,13 @@ * Types extracted from https://discord.com/developers/docs/resources/audit-log */ +import type { + APIAutoModerationAction, + APIAutoModerationRule, + APIAutoModerationRuleTriggerMetadata, + AutoModerationRuleEventType, + AutoModerationRuleTriggerType, +} from './autoModeration'; import type { APIChannel, APIOverwrite } from './channel'; import type { APIGuildIntegration, @@ -52,6 +59,12 @@ export interface APIAuditLog { * See https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object */ audit_log_entries: APIAuditLogEntry[]; + /** + * List of auto moderation rules referenced in the audit log + * + * See https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object + */ + auto_moderation_rules: APIAutoModerationRule[]; /** * Partial integration objects * @@ -180,12 +193,37 @@ export enum AuditLogEvent { ThreadDelete, ApplicationCommandPermissionUpdate = 121, + + AutoModerationRuleCreate = 140, + AutoModerationRuleUpdate, + AutoModerationRuleDelete, + AutoModerationBlockMessage, + AutoModerationFlagToChannel, + AutoModerationUserCommunicationDisabled, } /** * https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info */ export interface APIAuditLogOptions { + /** + * Name of the Auto Moderation rule that was triggered + * + * Present from: + * - AUTO_MODERATION_BLOCK_MESSAGE + * - AUTO_MODERATION_FLAG_TO_CHANNEL + * - AUTO_MODERATION_USER_COMMUNICATION_DISABLED + */ + auto_moderation_rule_name?: string; + /** + * Trigger type of the Auto Moderation rule that was triggered + * + * Present from: + * - AUTO_MODERATION_BLOCK_MESSAGE + * - AUTO_MODERATION_FLAG_TO_CHANNEL + * - AUTO_MODERATION_USER_COMMUNICATION_DISABLED + */ + auto_moderation_rule_trigger_type?: string; /** * Number of days after which inactive members were kicked * @@ -212,6 +250,9 @@ export interface APIAuditLogOptions { * - STAGE_INSTANCE_CREATE * - STAGE_INSTANCE_UPDATE * - STAGE_INSTANCE_DELETE + * - AUTO_MODERATION_BLOCK_MESSAGE + * - AUTO_MODERATION_FLAG_TO_CHANNEL + * - AUTO_MODERATION_USER_COMMUNICATION_DISABLED */ channel_id?: Snowflake; @@ -347,7 +388,14 @@ export type APIAuditLogChange = | APIAuditLogChangeKeyEntityType | APIAuditLogChangeKeyStatus | APIAuditLogChangeKeyLocation - | APIAuditLogChangeKeyCommunicationDisabledUntil; + | APIAuditLogChangeKeyCommunicationDisabledUntil + | APIAuditLogChangeKeyTriggerType + | APIAuditLogChangeKeyEventType + | APIAuditLogChangeKeyTriggerMetadata + | APIAuditLogChangeKeyActions + | APIAuditLogChangeKeyEnabled + | APIAuditLogChangeKeyExemptRoles + | APIAuditLogChangeKeyExemptChannels; /** * Returned when an entity's name is changed @@ -710,6 +758,44 @@ export type APIAuditLogChangeKeyLocation = AuditLogChangeData<'location', string */ export type APIAuditLogChangeKeyCommunicationDisabledUntil = AuditLogChangeData<'communication_disabled_until', string>; +/** + * Returned when an auto moderation rule's trigger type is changed (only in rule creation or deletion) + */ +export type APIAuditLogChangeKeyTriggerType = AuditLogChangeData<'trigger_type', AutoModerationRuleTriggerType>; + +/** + * Returned when an auto moderation rule's event type is changed + */ +export type APIAuditLogChangeKeyEventType = AuditLogChangeData<'event_type', AutoModerationRuleEventType>; + +/** + * Returned when an auto moderation rule's trigger metadata is changed + */ +export type APIAuditLogChangeKeyTriggerMetadata = AuditLogChangeData< + 'trigger_metadata', + APIAutoModerationRuleTriggerMetadata +>; + +/** + * Returned when an auto moderation rule's actions is changed + */ +export type APIAuditLogChangeKeyActions = AuditLogChangeData<'actions', APIAutoModerationAction[]>; + +/** + * Returned when an auto moderation rule's enabled status is changed + */ +export type APIAuditLogChangeKeyEnabled = AuditLogChangeData<'enabled', boolean>; + +/** + * Returned when an auto moderation rule's exempt roles is changed + */ +export type APIAuditLogChangeKeyExemptRoles = AuditLogChangeData<'exempt_roles', Snowflake[]>; + +/** + * Returned when an auto moderation rule's exempt channels is changed + */ +export type APIAuditLogChangeKeyExemptChannels = AuditLogChangeData<'exempt_channels', Snowflake[]>; + interface AuditLogChangeData { key: K; /** diff --git a/payloads/v9/autoModeration.ts b/payloads/v9/autoModeration.ts new file mode 100644 index 000000000..3346f78a5 --- /dev/null +++ b/payloads/v9/autoModeration.ts @@ -0,0 +1,195 @@ +/** + * Types extracted from https://discord.com/developers/docs/resources/auto-moderation + */ + +import type { Snowflake } from '../../globals'; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-auto-moderation-rule-structure + */ +export interface APIAutoModerationRule { + /** + * The id of this rule + */ + id: Snowflake; + /** + * The guild which this rule belongs to + */ + guild_id: Snowflake; + /** + * The rule name + */ + name: string; + /** + * The user id who created this rule + */ + creator_id: Snowflake; + /** + * The rule event type + */ + event_type: AutoModerationRuleEventType; + /** + * The rule trigger type + */ + trigger_type: AutoModerationRuleTriggerType; + /** + * The rule trigger metadata + */ + trigger_metadata: APIAutoModerationRuleTriggerMetadata; + /** + * The actions which will execute when this rule is triggered + */ + actions: APIAutoModerationAction[]; + /** + * Whether this rule is enabled + */ + enabled: boolean; + /** + * The role ids that shouldn't be affected by this rule (Maximum of 20) + */ + exempt_roles: Snowflake[]; + /** + * The channel ids that shouldn't be affected by this rule (Maximum of 50) + */ + exempt_channels: Snowflake[]; +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types + */ +export enum AutoModerationRuleTriggerType { + /** + * Check if content contains words from a user defined list of keywords (Maximum of 3 per guild) + */ + Keyword = 1, + /** + * Check if content represents generic spam (Maximum of 1 per guild) + */ + Spam = 3, + /** + * Check if content contains words from internal pre-defined wordsets (Maximum of 1 per guild) + */ + KeywordPreset, + /** + * Check if content contains more mentions than allowed (Maximum of 1 per guild) + */ + MentionSpam, +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata + */ +export interface APIAutoModerationRuleTriggerMetadata { + /** + * Substrings which will be searched for in content (Maximum of 1000) + * + * A keyword can be a phrase which contains multiple words. Wildcard symbols can be used to customize how each string will be matched. Each keyword must be 30 characters or less + * See [keyword matching strategies](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies) + * + * Associated trigger type: {@link AutoModerationRuleTriggerType.Keyword} + */ + keyword_filter?: string[]; + /** + * The internally pre-defined wordsets which will be searched for in content + * + * Associated trigger type: {@link AutoModerationRuleTriggerType.KeywordPreset} + */ + presets?: AutoModerationRuleKeywordPresetType[]; + /** + * Substrings which will be exempt from triggering the preset trigger type (Maximum of 1000) + * + * A allowed-word can be a phrase which contains multiple words. Wildcard symbols can be used to customize how each string will be matched. Each keyword must be 30 characters or less + * See [keyword matching strategies](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies) + * + * Associated trigger type: {@link AutoModerationRuleTriggerType.KeywordPreset} + */ + allow_list?: string[]; + /** + * Total number of mentions (role & user) allowed per message (Maximum of 50) + * + * Associated trigger type: {@link AutoModerationRuleTriggerType.MentionSpam} + */ + mention_total_limit?: number; +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-preset-types + */ +export enum AutoModerationRuleKeywordPresetType { + /** + * Words that may be considered forms of swearing or cursing + */ + Profanity = 1, + /** + * Words that refer to sexually explicit behavior or activity + */ + SexualContent, + /** + * Personal insults or words that may be considered hate speech + */ + Slurs, +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types + */ +export enum AutoModerationRuleEventType { + /** + * When a member sends or edits a message in the guild + */ + MessageSend = 1, +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-auto-moderation-action-structure + */ +export interface APIAutoModerationAction { + /** + * The action type + */ + type: AutoModerationActionType; + /** + * Additional metadata needed during execution for this specific action type + * + * Will only be omitted if the action type is {@link AutoModerationActionType.BlockMessage} + */ + metadata?: APIAutoModerationActionMetadata; +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types + */ +export enum AutoModerationActionType { + /** + * Blocks the content of a message according to the rule + */ + BlockMessage = 1, + /** + * Logs user content to a specified channel + */ + SendAlertMessage, + /** + * Timeout user for specified duration, this action type can be set if the bot has `MODERATE_MEMBERS` permission + */ + Timeout, +} + +/** + * https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-metadata + */ +export interface APIAutoModerationActionMetadata { + /** + * Channel to which user content should be logged + * + * Associated action type: {@link AutoModerationActionType.SendAlertMessage} + */ + channel_id?: Snowflake; + /** + * Timeout duration in seconds (Maximum of 4 weeks - 2419200 seconds) + * + * Only available if using {@link AutoModerationRuleTriggerType.Keyword} + * + * Associated action type: {@link AutoModerationActionType.Timeout} + */ + duration_seconds?: number; +} diff --git a/payloads/v9/channel.ts b/payloads/v9/channel.ts index 1214a5792..16a6b4be8 100644 --- a/payloads/v9/channel.ts +++ b/payloads/v9/channel.ts @@ -662,6 +662,7 @@ export enum MessageType { ThreadStarterMessage, GuildInviteReminder, ContextMenuCommand, + AutoModerationAction, } /** @@ -1018,6 +1019,12 @@ export enum EmbedType { * Link embed */ Link = 'link', + /** + * Auto moderation alert embed + * + * @unstable This embed type is currently not documented by Discord, but it is returned in the auto moderation system messages. + */ + AutoModerationMessage = 'auto_moderation_message', } /** diff --git a/payloads/v9/guild.ts b/payloads/v9/guild.ts index 82b8f935a..76014876d 100644 --- a/payloads/v9/guild.ts +++ b/payloads/v9/guild.ts @@ -382,6 +382,10 @@ export enum GuildFeature { * Guild has access to set an animated guild icon */ AnimatedIcon = 'ANIMATED_ICON', + /** + * Guild has set up auto moderation rules + */ + AutoModeration = 'AUTO_MODERATION', /** * Guild has access to set a guild banner image */ diff --git a/payloads/v9/index.ts b/payloads/v9/index.ts index 1c0980539..b83fd0968 100644 --- a/payloads/v9/index.ts +++ b/payloads/v9/index.ts @@ -1,6 +1,7 @@ export * from '../common'; export * from './application'; export * from './auditLog'; +export * from './autoModeration'; export * from './channel'; export * from './emoji'; export * from './gateway'; diff --git a/rest/v10/autoModeration.ts b/rest/v10/autoModeration.ts new file mode 100644 index 000000000..1d9e211e2 --- /dev/null +++ b/rest/v10/autoModeration.ts @@ -0,0 +1,84 @@ +import type { Snowflake } from '../../globals'; +import type { + APIAutoModerationAction, + APIAutoModerationRule, + AutoModerationRuleEventType, + APIAutoModerationRuleTriggerMetadata, + AutoModerationRuleTriggerType, +} from '../../payloads/v10/index'; +import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface } from '../../utils/internals'; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#list-auto-moderation-rules-for-guild + */ +export type RESTGetAPIAutoModerationRulesResult = APIAutoModerationRule[]; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#get-auto-moderation-rule + */ +export type RESTGetAPIAutoModerationRuleResult = APIAutoModerationRule; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#create-auto-moderation-rule + */ +export type RESTPostAPIAutoModerationRuleJSONBody = AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{ + /** + * The rule name + */ + name: string; + /** + * The rule event type + */ + event_type: AutoModerationRuleEventType; + /** + * The rule trigger type + */ + trigger_type: AutoModerationRuleTriggerType; + /** + * The rule trigger metadata + * + * Can be omitted if the trigger type is {@link AutoModerationRuleTriggerType.HarmfulLink} or {@link AutoModerationRuleTriggerType.Spam} + */ + trigger_metadata?: APIAutoModerationRuleTriggerMetadata; + /** + * The actions which will execute when this rule is triggered + */ + actions: APIAutoModerationAction[]; + /** + * Whether this rule is enabled + * + * @default false + */ + enabled?: boolean; + /** + * The role ids that shouldn't be affected by this rule (Maximum of 20) + */ + exempt_roles?: Snowflake[]; + /** + * The channel ids that shouldn't be affected by this rule (Maximum of 50) + */ + exempt_channels?: Snowflake[]; +}>; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#create-auto-moderation-rule + */ +export type RESTPostAPIAutoModerationRuleResult = APIAutoModerationRule; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#modify-auto-moderation-rule + */ +export type RESTPatchAPIAutoModerationRuleJSONBody = Omit< + Partial, + 'trigger_type' +>; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#modify-auto-moderation-rule + */ +export type RESTPatchAPIAutoModerationRuleResult = APIAutoModerationRule; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#delete-auto-moderation-rule + */ +export type RESTDeleteAPIAutoModerationRuleResult = never; diff --git a/rest/v10/index.ts b/rest/v10/index.ts index 25c1e9d2d..ad219dd84 100644 --- a/rest/v10/index.ts +++ b/rest/v10/index.ts @@ -20,6 +20,25 @@ export * from './webhook'; export const APIVersion = '10'; export const Routes = { + /** + * Route for: + * - GET `/guilds/{guild.id}/auto-moderation/rules` + * - POST `/guilds/{guild.id}/auto-moderation/rules` + */ + guildAutoModerationRules(guildId: Snowflake) { + return `/guilds/${guildId}/auto-moderation/rules`; + }, + + /** + * Routes for: + * - GET `/guilds/{guild.id}/auto-moderation/rules/{rule.id}` + * - PATCH `/guilds/{guild.id}/auto-moderation/rules/{rule.id}` + * - DELETE `/guilds/{guild.id}/auto-moderation/rules/{rule.id}` + */ + guildAutoModerationRule(guildId: Snowflake, ruleId: Snowflake) { + return `/guilds/${guildId}/auto-moderation/rules/${ruleId}`; + }, + /** * Route for: * - GET `/guilds/{guild.id}/audit-logs` diff --git a/rest/v9/autoModeration.ts b/rest/v9/autoModeration.ts new file mode 100644 index 000000000..a69f77092 --- /dev/null +++ b/rest/v9/autoModeration.ts @@ -0,0 +1,84 @@ +import type { Snowflake } from '../../globals'; +import type { + APIAutoModerationAction, + APIAutoModerationRule, + AutoModerationRuleEventType, + APIAutoModerationRuleTriggerMetadata, + AutoModerationRuleTriggerType, +} from '../../payloads/v9/index'; +import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface } from '../../utils/internals'; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#list-auto-moderation-rules-for-guild + */ +export type RESTGetAPIAutoModerationRulesResult = APIAutoModerationRule[]; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#get-auto-moderation-rule + */ +export type RESTGetAPIAutoModerationRuleResult = APIAutoModerationRule; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#create-auto-moderation-rule + */ +export type RESTPostAPIAutoModerationRuleJSONBody = AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{ + /** + * The rule name + */ + name: string; + /** + * The rule event type + */ + event_type: AutoModerationRuleEventType; + /** + * The rule trigger type + */ + trigger_type: AutoModerationRuleTriggerType; + /** + * The rule trigger metadata + * + * Can be omitted if the trigger type is {@link AutoModerationRuleTriggerType.HarmfulLink} or {@link AutoModerationRuleTriggerType.Spam} + */ + trigger_metadata?: APIAutoModerationRuleTriggerMetadata; + /** + * The actions which will execute when this rule is triggered + */ + actions: APIAutoModerationAction[]; + /** + * Whether this rule is enabled + * + * @default false + */ + enabled?: boolean; + /** + * The role ids that shouldn't be affected by this rule (Maximum of 20) + */ + exempt_roles?: Snowflake[]; + /** + * The channel ids that shouldn't be affected by this rule (Maximum of 50) + */ + exempt_channels?: Snowflake[]; +}>; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#create-auto-moderation-rule + */ +export type RESTPostAPIAutoModerationRuleResult = APIAutoModerationRule; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#modify-auto-moderation-rule + */ +export type RESTPatchAPIAutoModerationRuleJSONBody = Omit< + Partial, + 'trigger_type' +>; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#modify-auto-moderation-rule + */ +export type RESTPatchAPIAutoModerationRuleResult = APIAutoModerationRule; + +/** + * https://discord.com/developers/docs/resources/auto-moderation#delete-auto-moderation-rule + */ +export type RESTDeleteAPIAutoModerationRuleResult = never; diff --git a/rest/v9/index.ts b/rest/v9/index.ts index b49837bcb..44f5c3754 100644 --- a/rest/v9/index.ts +++ b/rest/v9/index.ts @@ -2,6 +2,7 @@ import type { Snowflake } from '../../globals'; export * from '../common'; export * from './auditLog'; +export * from './autoModeration'; export * from './channel'; export * from './emoji'; export * from './gateway'; @@ -20,6 +21,25 @@ export * from './webhook'; export const APIVersion = '9'; export const Routes = { + /** + * Route for: + * - GET `/guilds/{guild.id}/auto-moderation/rules` + * - POST `/guilds/{guild.id}/auto-moderation/rules` + */ + guildAutoModerationRules(guildId: Snowflake) { + return `/guilds/${guildId}/auto-moderation/rules`; + }, + + /** + * Routes for: + * - GET `/guilds/{guild.id}/auto-moderation/rules/{rule.id}` + * - PATCH `/guilds/{guild.id}/auto-moderation/rules/{rule.id}` + * - DELETE `/guilds/{guild.id}/auto-moderation/rules/{rule.id}` + */ + guildAutoModerationRule(guildId: Snowflake, ruleId: Snowflake) { + return `/guilds/${guildId}/auto-moderation/rules/${ruleId}`; + }, + /** * Route for: * - GET `/guilds/{guild.id}/audit-logs`