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: backport automod #8886

Merged
merged 13 commits into from
Jan 13, 2023
4 changes: 4 additions & 0 deletions src/client/actions/ActionsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class ActionsManager {
constructor(client) {
this.client = client;

this.register(require('./AutoModerationActionExecution'));
this.register(require('./AutoModerationRuleCreate'));
this.register(require('./AutoModerationRuleDelete'));
this.register(require('./AutoModerationRuleUpdate'));
this.register(require('./ChannelCreate'));
this.register(require('./ChannelDelete'));
this.register(require('./ChannelUpdate'));
Expand Down
26 changes: 26 additions & 0 deletions src/client/actions/AutoModerationActionExecution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

const Action = require('./Action');
const AutoModerationActionExecution = require('../../structures/AutoModerationActionExecution');
const { Events } = require('../../util/Constants');

class AutoModerationActionExecutionAction extends Action {
handle(data) {
const { client } = this;
const guild = client.guilds.cache.get(data.guild_id);

if (guild) {
/**
* Emitted whenever an auto moderation rule is triggered.
* <info>This event requires the {@link Permissions.FLAGS.MANAGE_GUILD} permission.</info>
* @event Client#autoModerationActionExecution
* @param {AutoModerationActionExecution} autoModerationActionExecution The data of the execution
*/
client.emit(Events.AUTO_MODERATION_ACTION_EXECUTION, new AutoModerationActionExecution(data, guild));
}

return {};
}
}

module.exports = AutoModerationActionExecutionAction;
27 changes: 27 additions & 0 deletions src/client/actions/AutoModerationRuleCreate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const Action = require('./Action');
const { Events } = require('../../util/Constants');

class AutoModerationRuleCreateAction extends Action {
handle(data) {
const { client } = this;
const guild = client.guilds.cache.get(data.guild_id);

if (guild) {
const autoModerationRule = guild.autoModerationRules._add(data);

/**
* Emitted whenever an auto moderation rule is created.
* <info>This event requires the {@link Permissions.FLAGS.MANAGE_GUILD} permission.</info>
* @event Client#autoModerationRuleCreate
* @param {AutoModerationRule} autoModerationRule The created auto moderation rule
*/
client.emit(Events.AUTO_MODERATION_RULE_CREATE, autoModerationRule);
}

return {};
}
}

module.exports = AutoModerationRuleCreateAction;
31 changes: 31 additions & 0 deletions src/client/actions/AutoModerationRuleDelete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const Action = require('./Action');
const { Events } = require('../../util/Constants');

class AutoModerationRuleDeleteAction extends Action {
handle(data) {
const { client } = this;
const guild = client.guilds.cache.get(data.guild_id);

if (guild) {
const autoModerationRule = guild.autoModerationRules.cache.get(data.id);

if (autoModerationRule) {
guild.autoModerationRules.cache.delete(autoModerationRule.id);

/**
* Emitted whenever an auto moderation rule is deleted.
* <info>This event requires the {@link Permissions.FLAGS.MANAGE_GUILD} permission.</info>
* @event Client#autoModerationRuleDelete
* @param {AutoModerationRule} autoModerationRule The deleted auto moderation rule
*/
client.emit(Events.AUTO_MODERATION_RULE_DELETE, autoModerationRule);
}
}

return {};
}
}

module.exports = AutoModerationRuleDeleteAction;
29 changes: 29 additions & 0 deletions src/client/actions/AutoModerationRuleUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const Action = require('./Action');
const { Events } = require('../../util/Constants');

class AutoModerationRuleUpdateAction extends Action {
handle(data) {
const { client } = this;
const guild = client.guilds.cache.get(data.guild_id);

if (guild) {
const oldAutoModerationRule = guild.autoModerationRules.cache.get(data.id)?._clone() ?? null;
const newAutoModerationRule = guild.autoModerationRules._add(data);

/**
* Emitted whenever an auto moderation rule gets updated.
* <info>This event requires the {@link Permissions.FLAGS.MANAGE_GUILD} permission.</info>
* @event Client#autoModerationRuleUpdate
* @param {?AutoModerationRule} oldAutoModerationRule The auto moderation rule before the update
* @param {AutoModerationRule} newAutoModerationRule The auto moderation rule after the update
*/
client.emit(Events.AUTO_MODERATION_RULE_UPDATE, oldAutoModerationRule, newAutoModerationRule);
}

return {};
}
}

module.exports = AutoModerationRuleUpdateAction;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = (client, packet) => {
client.actions.AutoModerationActionExecution.handle(packet.d);
};
5 changes: 5 additions & 0 deletions src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = (client, packet) => {
client.actions.AutoModerationRuleCreate.handle(packet.d);
};
5 changes: 5 additions & 0 deletions src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = (client, packet) => {
client.actions.AutoModerationRuleDelete.handle(packet.d);
};
5 changes: 5 additions & 0 deletions src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = (client, packet) => {
client.actions.AutoModerationRuleUpdate.handle(packet.d);
};
4 changes: 4 additions & 0 deletions src/client/websocket/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const handlers = Object.fromEntries([
['APPLICATION_COMMAND_CREATE', require('./APPLICATION_COMMAND_CREATE')],
['APPLICATION_COMMAND_DELETE', require('./APPLICATION_COMMAND_DELETE')],
['APPLICATION_COMMAND_UPDATE', require('./APPLICATION_COMMAND_UPDATE')],
['AUTO_MODERATION_ACTION_EXECUTION', require('./AUTO_MODERATION_ACTION_EXECUTION')],
['AUTO_MODERATION_RULE_CREATE', require('./AUTO_MODERATION_RULE_CREATE')],
['AUTO_MODERATION_RULE_DELETE', require('./AUTO_MODERATION_RULE_DELETE')],
['AUTO_MODERATION_RULE_UPDATE', require('./AUTO_MODERATION_RULE_UPDATE')],
['GUILD_CREATE', require('./GUILD_CREATE')],
['GUILD_DELETE', require('./GUILD_DELETE')],
['GUILD_UPDATE', require('./GUILD_UPDATE')],
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ exports.version = require('../package.json').version;
// Managers
exports.ApplicationCommandManager = require('./managers/ApplicationCommandManager');
exports.ApplicationCommandPermissionsManager = require('./managers/ApplicationCommandPermissionsManager');
exports.AutoModerationRuleManager = require('./managers/AutoModerationRuleManager');
exports.BaseGuildEmojiManager = require('./managers/BaseGuildEmojiManager');
exports.CachedManager = require('./managers/CachedManager');
exports.ChannelManager = require('./managers/ChannelManager');
Expand Down Expand Up @@ -72,6 +73,8 @@ exports.AnonymousGuild = require('./structures/AnonymousGuild');
exports.Application = require('./structures/interfaces/Application');
exports.ApplicationCommand = require('./structures/ApplicationCommand');
exports.AutocompleteInteraction = require('./structures/AutocompleteInteraction');
exports.AutoModerationActionExecution = require('./structures/AutoModerationActionExecution');
exports.AutoModerationRule = require('./structures/AutoModerationRule');
exports.Base = require('./structures/Base');
exports.BaseCommandInteraction = require('./structures/BaseCommandInteraction');
exports.BaseGuild = require('./structures/BaseGuild');
Expand Down
Loading