diff --git a/packages/structures/src/automoderation/AutoModerationRule.ts b/packages/structures/src/automoderation/AutoModerationRule.ts new file mode 100644 index 000000000..336d5404a --- /dev/null +++ b/packages/structures/src/automoderation/AutoModerationRule.ts @@ -0,0 +1,77 @@ +import type { APIAutoModerationRule } from 'discord-api-types/v10'; +import { Structure } from '../Structure.js'; +import { kData } from '../utils/symbols.js'; +import type { Partialize } from '../utils/types.js'; + +/** + * Represents an auto moderation rule on Discord. + * + * @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate` + * @remarks has substructure `TriggerMetadata` which needs to be instantiated and stored by an extending class using it + * @remarks intentionally does not export `exemptRoles` and `exemptChannels` so that extending classes can resolve `Snowflake[]` to `Role[]` and `Channel[]`, respectively + */ +export class AutoModerationRule extends Structure< + APIAutoModerationRule, + Omitted +> { + /** + * The template used for removing data from the raw data stored for each auto moderation rule + */ + public static override DataTemplate: Partial = {}; + + /** + * @param data - The raw data received from the API for the auto moderation rule + */ + public constructor(data: Partialize) { + super(data); + } + + /** + * The id of this rule + */ + public get id() { + return this[kData].id; + } + + /** + * The id of the guild which this rule belongs to + */ + public get guildId() { + return this[kData].guild_id; + } + + /** + * The rule name + */ + public get name() { + return this[kData].name; + } + + /** + * The user who first created this rule + */ + public get creatorId() { + return this[kData].creator_id; + } + + /** + * The rule {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types | event type} + */ + public get eventType() { + return this[kData].event_type; + } + + /** + * The rule {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types | trigger type} + */ + public get triggerType() { + return this[kData].trigger_type; + } + + /** + * Whether the rule is enabled + */ + public get enabled() { + return this[kData].enabled; + } +} diff --git a/packages/structures/src/automoderation/AutoModerationRuleTriggerMetadata.ts b/packages/structures/src/automoderation/AutoModerationRuleTriggerMetadata.ts new file mode 100644 index 000000000..0a0b45c08 --- /dev/null +++ b/packages/structures/src/automoderation/AutoModerationRuleTriggerMetadata.ts @@ -0,0 +1,102 @@ +import type { APIAutoModerationRuleTriggerMetadata, AutoModerationRuleTriggerType } from 'discord-api-types/v10'; +import { Structure } from '../Structure.js'; +import { kData } from '../utils/symbols.js'; +import type { Partialize } from '../utils/types.js'; + +/** + * Represents an auto moderation rule trigger metadata on Discord. + * + * @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate` + */ +export class AutoModerationRuleTriggerMetadata< + Omitted extends keyof APIAutoModerationRuleTriggerMetadata | '' = '', +> extends Structure { + /** + * The template used for removing data from the raw data stored for each auto moderation rule trigger metadata + */ + public static override DataTemplate: Partial = {}; + + /** + * @param data - The raw data received from the API for the auto moderation rule trigger metadata + */ + public constructor(data: Partialize) { + super(data); + } + + /** + * 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 keyword will be matched. Each keyword must be 60 characters or less. + * + * @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies | Keyword matching strategies} + * + * Associated trigger types: {@link AutoModerationRuleTriggerType.Keyword}, {@link AutoModerationRuleTriggerType.MemberProfile} + */ + public get keywordFilter() { + return this[kData].keyword_filter; + } + + /** + * Regular expression patterns which will be matched against content (Maximum of 10) + * + * Only Rust flavored regex is currently supported, which can be tested in online editors such as {@link https://rustexp.lpil.uk/ | Rustexp}. + * + * Each regex pattern must be 260 characters or less. + * + * Associated trigger types: {@link AutoModerationRuleTriggerType.Keyword}, {@link AutoModerationRuleTriggerType.MemberProfile} + */ + public get regexPatterns() { + return this[kData].regex_patterns; + } + + /** + * The internally pre-defined wordsets which will be searched for in content + * + * @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-preset-types | Keyword preset types} + * + * Associated trigger types: {@link AutoModerationRuleTriggerType.KeywordPreset} + */ + public get presets() { + return this[kData].presets; + } + + /** + * Substrings which should not trigger the rule (Maximum of 100 or 1000). + * + * Wildcard symbols can be used to customize how each keyword will be matched (see Keyword matching strategies). + * + * Each `allow_list` keyword can be a phrase which contains multiple words. + * + * Rules with `KEYWORD` triggerType accept a maximum of 100 keywords. + * + * Rules with `KEYWORD_PRESET` triggerType accept a maximum of 1000 keywords. + * + * @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types | triggerType} + * @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies | Keyword matching strategies} + * + * Associated trigger types: {@link AutoModerationRuleTriggerType.Keyword}, {@link AutoModerationRuleTriggerType.KeywordPreset}, {@link AutoModerationRuleTriggerType.MemberProfile} + */ + public get allowList() { + return this[kData].allow_list; + } + + /** + * Total number of unique role and user mentions allowed per message (Maximum of 50) + * + * Associated trigger types: {@link AutoModerationRuleTriggerType.MentionSpam} + */ + public get mentionTotalLimit() { + return this[kData].mention_total_limit; + } + + /** + * Whether to automatically detect mention raids + * + * Associated trigger types: {@link AutoModerationRuleTriggerType.MentionSpam} + */ + public get mentionRaidProtectionEnabled() { + return this[kData].mention_raid_protection_enabled; + } +} diff --git a/packages/structures/src/automoderation/actions/AutoModerationAction.ts b/packages/structures/src/automoderation/actions/AutoModerationAction.ts new file mode 100644 index 000000000..ccbc91182 --- /dev/null +++ b/packages/structures/src/automoderation/actions/AutoModerationAction.ts @@ -0,0 +1,34 @@ +import type { APIAutoModerationAction } from 'discord-api-types/v10'; +import { Structure } from '../../Structure.js'; +import { kData } from '../../utils/symbols.js'; +import type { Partialize } from '../../utils/types.js'; + +/** + * Represents an auto moderation action on Discord. + * + * @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate` + * @remarks has substructure `ActionMetadata` which needs to be instantiated and stored by an extending class using it + */ +export class AutoModerationAction extends Structure< + APIAutoModerationAction, + Omitted +> { + /** + * The template used for removing data from the raw data stored for each auto moderation action + */ + public static override DataTemplate: Partial = {}; + + /** + * @param data - The raw data received from the API for the auto moderation action + */ + public constructor(data: Partialize) { + super(data); + } + + /** + * The {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types | action type} + */ + public get type() { + return this[kData].type; + } +} diff --git a/packages/structures/src/automoderation/actions/AutoModerationActionMetadata.ts b/packages/structures/src/automoderation/actions/AutoModerationActionMetadata.ts new file mode 100644 index 000000000..d11ae0e3e --- /dev/null +++ b/packages/structures/src/automoderation/actions/AutoModerationActionMetadata.ts @@ -0,0 +1,60 @@ +import type { + APIAutoModerationActionMetadata, + AutoModerationActionType, + AutoModerationRuleTriggerType, +} from 'discord-api-types/v10'; +import { Structure } from '../../Structure.js'; +import { kData } from '../../utils/symbols.js'; +import type { Partialize } from '../../utils/types.js'; + +/** + * Represents an auto moderation action metadata on Discord. + * + * @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate` + */ +export class AutoModerationActionMetadata< + Omitted extends keyof APIAutoModerationActionMetadata | '' = '', +> extends Structure { + /** + * The template used for removing data from the raw data stored for each auto moderation action metadata + */ + public static override DataTemplate: Partial = {}; + + /** + * @param data - The raw data received from the API for the auto moderation action metadata + */ + public constructor(data: Partialize) { + super(data); + } + + /** + * Channel to which user content should be logged. This must be an existing channel + * + * Associated action types: {@link AutoModerationActionType.SendAlertMessage} + */ + public get channelId() { + return this[kData].channel_id; + } + + /** + * Timeout duration in seconds. Maximum of 2419200 seconds (4 weeks). + * + * A `TIMEOUT` action can only be set up for {@link AutoModerationRuleTriggerType.Keyword} and {@link AutoModerationRuleTriggerType.MentionSpam}. + * + * The `MODERATE_MEMBERS` permission is required to use {@link AutoModerationActionType.Timeout} actions. + * + * Associated action types: {@link AutoModerationActionType.Timeout} + */ + public get durationSeconds() { + return this[kData].duration_seconds; + } + + /** + * Additional explanation that will be shown to members whenever their message is blocked. Maximum of 150 characters + * + * Associated action types: {@link AutoModerationActionType.BlockMessage} + */ + public get customMessage() { + return this[kData].custom_message; + } +} diff --git a/packages/structures/src/automoderation/actions/index.ts b/packages/structures/src/automoderation/actions/index.ts new file mode 100644 index 000000000..b6b02678e --- /dev/null +++ b/packages/structures/src/automoderation/actions/index.ts @@ -0,0 +1,2 @@ +export * from './AutoModerationAction.js'; +export * from './AutoModerationActionMetadata.js'; diff --git a/packages/structures/src/automoderation/index.ts b/packages/structures/src/automoderation/index.ts new file mode 100644 index 000000000..d2f5714fc --- /dev/null +++ b/packages/structures/src/automoderation/index.ts @@ -0,0 +1,4 @@ +export * from './actions/index.js'; + +export * from './AutoModerationRule.js'; +export * from './AutoModerationRuleTriggerMetadata.js'; diff --git a/packages/structures/src/index.ts b/packages/structures/src/index.ts index 97ad34d05..d294ceeea 100644 --- a/packages/structures/src/index.ts +++ b/packages/structures/src/index.ts @@ -1,3 +1,4 @@ +export * from './automoderation/index.js'; export * from './bitfields/index.js'; export * from './channels/index.js'; export * from './emojis/index.js';