mirror of
https://github.com/discordeno/discordeno.git
synced 2026-05-31 16:00:07 +00:00
fix(types)!: Fix optionals for some props in auto moderation. (#4150)
* Fix optionals for some props in autoModeration. Also fix some comments to be more clear * Fix type error in automodActionExecution * Fix type error in automod.spec.ts e2e test --------- Co-authored-by: Awesome Stickz <awesome@stickz.dev>
This commit is contained in:
@@ -15,11 +15,13 @@ export function transformAutoModerationActionExecution(bot: Bot, payload: Discor
|
||||
matchedContent: payload.matched_content ?? '',
|
||||
action: {
|
||||
type: payload.action.type,
|
||||
metadata: {
|
||||
durationSeconds: payload.action.metadata.duration_seconds,
|
||||
customMessage: payload.action.metadata.custom_message,
|
||||
channelId: payload.action.metadata.channel_id ? bot.transformers.snowflake(payload.action.metadata.channel_id) : undefined,
|
||||
},
|
||||
metadata: payload.action.metadata
|
||||
? {
|
||||
durationSeconds: payload.action.metadata.duration_seconds,
|
||||
customMessage: payload.action.metadata.custom_message,
|
||||
channelId: payload.action.metadata.channel_id ? bot.transformers.snowflake(payload.action.metadata.channel_id) : undefined,
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
} as AutoModerationActionExecution
|
||||
|
||||
|
||||
@@ -333,7 +333,7 @@ export interface AutoModerationActionExecution {
|
||||
|
||||
export interface AutoModerationAction {
|
||||
type: AutoModerationActionType
|
||||
metadata: AutoModerationActionMetadata
|
||||
metadata?: AutoModerationActionMetadata
|
||||
}
|
||||
|
||||
export interface AutoModerationActionMetadata {
|
||||
|
||||
@@ -228,8 +228,8 @@ describe('Run automod tests', async () => {
|
||||
expect(fetchedRule.actions[0]).to.be.exist
|
||||
expect(fetchedRule.actions[1].metadata).to.be.exist
|
||||
expect(fetchedRule.actions[2].metadata).to.be.exist
|
||||
expect(fetchedRule.actions[1].metadata.channelId).to.equal(channel.id)
|
||||
expect(fetchedRule.actions[2].metadata.durationSeconds).to.equal(10)
|
||||
expect(fetchedRule.actions[1].metadata?.channelId).to.equal(channel.id)
|
||||
expect(fetchedRule.actions[2].metadata?.durationSeconds).to.equal(10)
|
||||
expect(fetchedRule.actions[0].type).to.equal(AutoModerationActionType.BlockMessage)
|
||||
expect(fetchedRule.actions[1].type).to.equal(AutoModerationActionType.SendAlertMessage)
|
||||
expect(fetchedRule.actions[2].type).to.equal(AutoModerationActionType.Timeout)
|
||||
|
||||
@@ -59,7 +59,7 @@ export interface DiscordAutoModerationRuleTriggerMetadata {
|
||||
*
|
||||
* Can have up to 10 elements in the array and each string can have up to 260 characters
|
||||
*/
|
||||
regex_patterns: string[]
|
||||
regex_patterns?: string[]
|
||||
/**
|
||||
* The pre-defined lists of words to match from.
|
||||
*
|
||||
@@ -118,7 +118,7 @@ export interface DiscordAutoModerationAction {
|
||||
/** The type of action to take when a rule is triggered */
|
||||
type: AutoModerationActionType
|
||||
/** additional metadata needed during execution for this specific action type */
|
||||
metadata: DiscordAutoModerationActionMetadata
|
||||
metadata?: DiscordAutoModerationActionMetadata
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types */
|
||||
@@ -142,10 +142,31 @@ export enum AutoModerationActionType {
|
||||
|
||||
/** https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-metadata */
|
||||
export interface DiscordAutoModerationActionMetadata {
|
||||
/** The id of channel to which user content should be logged. Only in ActionType.SendAlertMessage */
|
||||
/**
|
||||
* The id of channel to which user content should be logged.
|
||||
*
|
||||
* @remarks
|
||||
* Only for actions of type {@link AutoModerationActionType.SendAlertMessage}.
|
||||
*/
|
||||
channel_id?: string
|
||||
/** Additional explanation that will be shown to members whenever their message is blocked. Maximum of 150 characters. Only supported for AutoModerationActionType.BlockMessage */
|
||||
custom_message?: string
|
||||
/** Timeout duration in seconds maximum of 2419200 seconds (4 weeks). Only supported for TriggerType.Keyword && Only in ActionType.Timeout */
|
||||
/**
|
||||
* Timeout duration in seconds.
|
||||
*
|
||||
* @remarks
|
||||
* Only for actions of type {@link AutoModerationActionType.Timeout}.
|
||||
*
|
||||
* Maximum of 2419200 seconds (4 weeks).
|
||||
*/
|
||||
duration_seconds?: number
|
||||
/**
|
||||
* Additional explanation that will be shown to members whenever their message is blocked.
|
||||
*
|
||||
* This may set to undefined if no custom message is provided.
|
||||
*
|
||||
* @remarks
|
||||
* Only for actions of type {@link AutoModerationActionType.BlockMessage}.
|
||||
*
|
||||
* Maximum of 150 characters.
|
||||
*/
|
||||
custom_message?: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user