mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 18:43:31 +01:00
fix(AutoModerationActionExecution): transform action (#9111)
* fix: transform action upon execution * chore: move method into transformer --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { _transformAPIAutoModerationAction } = require('../util/Transformers');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the structure of an executed action when an {@link AutoModerationRule} is triggered.
|
* Represents the structure of an executed action when an {@link AutoModerationRule} is triggered.
|
||||||
*/
|
*/
|
||||||
@@ -15,7 +17,7 @@ class AutoModerationActionExecution {
|
|||||||
* The action that was executed.
|
* The action that was executed.
|
||||||
* @type {AutoModerationAction}
|
* @type {AutoModerationAction}
|
||||||
*/
|
*/
|
||||||
this.action = data.action;
|
this.action = _transformAPIAutoModerationAction(data.action);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The id of the auto moderation rule this action belongs to.
|
* The id of the auto moderation rule this action belongs to.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const { Collection } = require('@discordjs/collection');
|
const { Collection } = require('@discordjs/collection');
|
||||||
const Base = require('./Base');
|
const Base = require('./Base');
|
||||||
|
const { _transformAPIAutoModerationAction } = require('../util/Transformers');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an auto moderation rule.
|
* Represents an auto moderation rule.
|
||||||
@@ -101,13 +102,7 @@ class AutoModerationRule extends Base {
|
|||||||
* The actions of this auto moderation rule.
|
* The actions of this auto moderation rule.
|
||||||
* @type {AutoModerationAction[]}
|
* @type {AutoModerationAction[]}
|
||||||
*/
|
*/
|
||||||
this.actions = data.actions.map(action => ({
|
this.actions = data.actions.map(action => _transformAPIAutoModerationAction(action));
|
||||||
type: action.type,
|
|
||||||
metadata: {
|
|
||||||
durationSeconds: action.metadata.duration_seconds ?? null,
|
|
||||||
channelId: action.metadata.channel_id ?? null,
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('enabled' in data) {
|
if ('enabled' in data) {
|
||||||
|
|||||||
@@ -28,6 +28,11 @@
|
|||||||
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10#APIApplicationCommandOption}
|
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10#APIApplicationCommandOption}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @external APIAutoModerationAction
|
||||||
|
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/interface/APIAutoModerationAction}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @external APIButtonComponent
|
* @external APIButtonComponent
|
||||||
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10#APIButtonComponent}
|
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10#APIButtonComponent}
|
||||||
|
|||||||
@@ -16,4 +16,20 @@ function toSnakeCase(obj) {
|
|||||||
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [snakeCase(key), toSnakeCase(value)]));
|
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [snakeCase(key), toSnakeCase(value)]));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { toSnakeCase };
|
/**
|
||||||
|
* Transforms an API auto moderation action object to a camel-cased variant.
|
||||||
|
* @param {APIAutoModerationAction} autoModerationAction The action to transform
|
||||||
|
* @returns {AutoModerationAction}
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
function _transformAPIAutoModerationAction(autoModerationAction) {
|
||||||
|
return {
|
||||||
|
type: autoModerationAction.type,
|
||||||
|
metadata: {
|
||||||
|
durationSeconds: autoModerationAction.metadata.duration_seconds ?? null,
|
||||||
|
channelId: autoModerationAction.metadata.channel_id ?? null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { toSnakeCase, _transformAPIAutoModerationAction };
|
||||||
|
|||||||
Reference in New Issue
Block a user