Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(APIAutoModeration): add support for auto moderation #418

Merged
merged 41 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
16421fa
feat(RESTJSONErrorCodes): add error 50080
vvito7 Apr 23, 2022
b974b00
refactor(GuildFeature): remove seven & three day thread archive
vvito7 Apr 25, 2022
fec7bf9
Merge branch 'main' of https://github.com/vitorlops/discord-api-types
vvito7 Apr 25, 2022
6f65990
fix: oops
vvito7 Apr 25, 2022
547bcd2
refator: use the new error name
vvito7 Apr 29, 2022
69b2524
refator: use the new error name 2
vvito7 Apr 29, 2022
2a77c89
Merge branch 'discordjs:main' into main
vvito7 Apr 29, 2022
686a9b2
Merge branch 'discordjs:main' into main
vvito7 Apr 30, 2022
712fdcf
feat(MessageType): add `AutoModerationMessage`
vvito7 May 1, 2022
c8675e7
feat(EmbedType): add `AutoModAlerts`
vvito7 May 1, 2022
f007c20
refactor: use `AutoModerationMessage` instead
vvito7 May 1, 2022
5799d9a
feat: add `AutoModeration` to `GuildFeature` & message to action
vvito7 May 1, 2022
538d32c
chore: change `AutoModerationMessage` description
vvito7 May 2, 2022
39ad85f
chore: forgot the alert
vvito7 May 2, 2022
3a1a972
feat(AuditLogEvent): add automod rules
vvito7 May 5, 2022
b24cd64
feat: add `AutoModerationBlockMessage` rule
vvito7 May 6, 2022
3a5364c
Merge branch 'main' into msg-type-for-automod
vvito7 May 13, 2022
0b10f96
feat: add `APIGuildAutoModRule`
vvito7 May 13, 2022
43b514d
fix: eslint problem
vvito7 May 13, 2022
c866059
refactor: handle automod properly
vvito7 May 22, 2022
2fe6156
fix: use export/import correctly
vvito7 May 22, 2022
02394c5
feat: upstream up-to-date
vvito7 Jun 8, 2022
86d45d0
feat: keep up-to-date
vvito7 Jun 14, 2022
0e8f067
chore: keep up-to-date
vvito7 Jun 16, 2022
08329e2
chore: fix action links
vvito7 Jun 16, 2022
c50ec00
refactor: make requested changes
vvito7 Jun 16, 2022
517afbf
feat: more requested changes
vvito7 Jun 16, 2022
ebcd6d7
feat: add missing `APIAuditLogChangeKeyTriggerType` type
vvito7 Jun 17, 2022
20c898c
refactor: optional fields & intent necessary for `content`
vvito7 Jun 18, 2022
b5dc29d
refactor: trigger metada fields are optional
vvito7 Jun 19, 2022
503a324
docs: add a note about `MESSAGE_CONTENT`
vvito7 Jun 22, 2022
0abb8e2
Merge branch 'main' into msg-type-for-automod
vvito7 Jun 30, 2022
d1ded47
refactor: add `allow_list` and improve docs
vvito7 Jun 30, 2022
0cec331
Merge branch 'main' into msg-type-for-automod
vvito7 Jul 1, 2022
9a9da67
refactor: update old stuff
vvito7 Aug 31, 2022
c0c3884
Merge branch 'msg-type-for-automod' of https://github.com/vvito7/disc…
vvito7 Aug 31, 2022
7bb1b12
docs: make requested changes
vvito7 Sep 23, 2022
1ac16c6
Merge branch 'main' into msg-type-for-automod
vvito7 Sep 23, 2022
567e7bf
feat: keep up-to-date
vvito7 Oct 1, 2022
6f8e84e
Merge branch 'msg-type-for-automod' of https://github.com/vvito7/disc…
vvito7 Oct 1, 2022
035e3cb
revert: remove support for regex matching
vvito7 Oct 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
124 changes: 124 additions & 0 deletions deno/gateway/v10.ts
Original file line number Diff line number Diff line change
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',
vvito7 marked this conversation as resolved.
Show resolved Hide resolved
AutoModerationRuleUpdate = 'AUTO_MODERATION_RULE_UPDATE',
AutoModerationRuleDelete = 'AUTO_MODERATION_RULE_DELETE',
AutoModerationActionExecution = 'AUTO_MODERATION_ACTION_EXECUTION',
}

export type GatewaySendPayload =
Expand Down Expand Up @@ -428,6 +437,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#auto-moderation-action-execution-auto-moderation-action-execution-event-fields
*/
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
Original file line number Diff line number Diff line change
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 @@ -427,6 +436,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#auto-moderation-action-execution-auto-moderation-action-execution-event-fields
*/
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