Skip to content

Commit

Permalink
feat(APIAutoModeration): add support for auto moderation (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
vvito7 committed Oct 14, 2022
1 parent 05cfe1b commit b216f7a
Show file tree
Hide file tree
Showing 32 changed files with 2,086 additions and 4 deletions.
124 changes: 124 additions & 0 deletions deno/gateway/v10.ts
Expand Up @@ -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,
Expand All @@ -28,6 +30,7 @@ import type {
GatewayVoiceState,
InviteTargetType,
PresenceUpdateStatus,
AutoModerationRuleTriggerType,
} from '../payloads/v10/mod.ts';
import type { Nullable } from '../utils/internals.ts';

Expand Down Expand Up @@ -190,6 +193,8 @@ export enum GatewayIntentBits {
DirectMessageTyping = 1 << 14,
MessageContent = 1 << 15,
GuildScheduledEvents = 1 << 16,
AutoModerationConfiguration = 1 << 20,
AutoModerationExecution = 1 << 21,
}

/**
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -432,6 +441,121 @@ export interface GatewayReadyDispatchData {
*/
export type GatewayResumedDispatch = DataPayload<GatewayDispatchEvents.Resumed, never>;

/**
* 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
Expand Down
124 changes: 124 additions & 0 deletions deno/gateway/v9.ts
Expand Up @@ -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,
Expand All @@ -28,6 +30,7 @@ import type {
GatewayVoiceState,
InviteTargetType,
PresenceUpdateStatus,
AutoModerationRuleTriggerType,
} from '../payloads/v9/mod.ts';
import type { Nullable } from '../utils/internals.ts';

Expand Down Expand Up @@ -189,6 +192,8 @@ export enum GatewayIntentBits {
DirectMessageReactions = 1 << 13,
DirectMessageTyping = 1 << 14,
GuildScheduledEvents = 1 << 16,
AutoModerationConfiguration = 1 << 20,
AutoModerationExecution = 1 << 21,
}

/**
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -431,6 +440,121 @@ export interface GatewayReadyDispatchData {
*/
export type GatewayResumedDispatch = DataPayload<GatewayDispatchEvents.Resumed, never>;

/**
* 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
Expand Down

1 comment on commit b216f7a

@vercel
Copy link

@vercel vercel bot commented on b216f7a Oct 14, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.