mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 08:03:30 +01:00
feat(structures): add AutoModeration structures (#11381)
* feat(structures): add barrel exports in preparation new structures * feat(structures): add AutoModerationRule structure * feat(structures): add AutoModerationRuleTriggerMetadata structure * feat(structures): add AutoModerationAction substructure * feat(structure): add AutoModerationActionMetadata substructure * chore: correct typo * chore: do not expose exemptRoles and exemptChannels as getters * feat(structures): rename substructure files * chore(structures): update barrel exports * chore(structures): export automod structures in package barrel exports
This commit is contained in:
77
packages/structures/src/automoderation/AutoModerationRule.ts
Normal file
77
packages/structures/src/automoderation/AutoModerationRule.ts
Normal file
@@ -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<Omitted extends keyof APIAutoModerationRule | '' = ''> 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<APIAutoModerationRule> = {};
|
||||
|
||||
/**
|
||||
* @param data - The raw data received from the API for the auto moderation rule
|
||||
*/
|
||||
public constructor(data: Partialize<APIAutoModerationRule, Omitted>) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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<APIAutoModerationRuleTriggerMetadata, Omitted> {
|
||||
/**
|
||||
* The template used for removing data from the raw data stored for each auto moderation rule trigger metadata
|
||||
*/
|
||||
public static override DataTemplate: Partial<APIAutoModerationRuleTriggerMetadata> = {};
|
||||
|
||||
/**
|
||||
* @param data - The raw data received from the API for the auto moderation rule trigger metadata
|
||||
*/
|
||||
public constructor(data: Partialize<APIAutoModerationRuleTriggerMetadata, Omitted>) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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<Omitted extends keyof APIAutoModerationAction | '' = ''> 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<APIAutoModerationAction> = {};
|
||||
|
||||
/**
|
||||
* @param data - The raw data received from the API for the auto moderation action
|
||||
*/
|
||||
public constructor(data: Partialize<APIAutoModerationAction, Omitted>) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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<APIAutoModerationActionMetadata, Omitted> {
|
||||
/**
|
||||
* The template used for removing data from the raw data stored for each auto moderation action metadata
|
||||
*/
|
||||
public static override DataTemplate: Partial<APIAutoModerationActionMetadata> = {};
|
||||
|
||||
/**
|
||||
* @param data - The raw data received from the API for the auto moderation action metadata
|
||||
*/
|
||||
public constructor(data: Partialize<APIAutoModerationActionMetadata, Omitted>) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
2
packages/structures/src/automoderation/actions/index.ts
Normal file
2
packages/structures/src/automoderation/actions/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './AutoModerationAction.js';
|
||||
export * from './AutoModerationActionMetadata.js';
|
||||
4
packages/structures/src/automoderation/index.ts
Normal file
4
packages/structures/src/automoderation/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './actions/index.js';
|
||||
|
||||
export * from './AutoModerationRule.js';
|
||||
export * from './AutoModerationRuleTriggerMetadata.js';
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './automoderation/index.js';
|
||||
export * from './bitfields/index.js';
|
||||
export * from './channels/index.js';
|
||||
export * from './emojis/index.js';
|
||||
|
||||
Reference in New Issue
Block a user