From 22a9e2f35a031b549af8ada0d02120b88aafb892 Mon Sep 17 00:00:00 2001 From: DD Date: Mon, 19 Aug 2024 22:53:42 +0300 Subject: [PATCH] refactor(actions): safer getChannel calls (#10434) * refactor(actions): safer getChannel calls * chore: consistency --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/discord.js/src/client/actions/MessageCreate.js | 2 +- packages/discord.js/src/client/actions/MessageDelete.js | 2 +- packages/discord.js/src/client/actions/MessagePollVoteAdd.js | 2 +- packages/discord.js/src/client/actions/MessagePollVoteRemove.js | 2 +- packages/discord.js/src/client/actions/MessageReactionAdd.js | 2 +- packages/discord.js/src/client/actions/MessageReactionRemove.js | 2 +- .../discord.js/src/client/actions/MessageReactionRemoveAll.js | 2 +- .../discord.js/src/client/actions/MessageReactionRemoveEmoji.js | 2 +- packages/discord.js/src/client/actions/MessageUpdate.js | 2 +- packages/discord.js/src/client/actions/StageInstanceCreate.js | 2 +- packages/discord.js/src/client/actions/StageInstanceDelete.js | 2 +- packages/discord.js/src/client/actions/StageInstanceUpdate.js | 2 +- packages/discord.js/src/client/actions/TypingStart.js | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/discord.js/src/client/actions/MessageCreate.js b/packages/discord.js/src/client/actions/MessageCreate.js index 070a9f58eeee..2babdaf3b287 100644 --- a/packages/discord.js/src/client/actions/MessageCreate.js +++ b/packages/discord.js/src/client/actions/MessageCreate.js @@ -6,7 +6,7 @@ const Events = require('../../util/Events'); class MessageCreateAction extends Action { handle(data) { const client = this.client; - const channel = this.getChannel(data); + const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id, author: data.author }); if (channel) { if (!channel.isTextBased()) return {}; diff --git a/packages/discord.js/src/client/actions/MessageDelete.js b/packages/discord.js/src/client/actions/MessageDelete.js index f0c74d762e94..34acb42b3ba4 100644 --- a/packages/discord.js/src/client/actions/MessageDelete.js +++ b/packages/discord.js/src/client/actions/MessageDelete.js @@ -6,7 +6,7 @@ const Events = require('../../util/Events'); class MessageDeleteAction extends Action { handle(data) { const client = this.client; - const channel = this.getChannel(data); + const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); let message; if (channel) { if (!channel.isTextBased()) return {}; diff --git a/packages/discord.js/src/client/actions/MessagePollVoteAdd.js b/packages/discord.js/src/client/actions/MessagePollVoteAdd.js index 0c0d93570fd5..2a2bdc649ee1 100644 --- a/packages/discord.js/src/client/actions/MessagePollVoteAdd.js +++ b/packages/discord.js/src/client/actions/MessagePollVoteAdd.js @@ -5,7 +5,7 @@ const Events = require('../../util/Events'); class MessagePollVoteAddAction extends Action { handle(data) { - const channel = this.getChannel(data); + const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); if (!channel?.isTextBased()) return false; const message = this.getMessage(data, channel); diff --git a/packages/discord.js/src/client/actions/MessagePollVoteRemove.js b/packages/discord.js/src/client/actions/MessagePollVoteRemove.js index 59ee2a9770d5..c3eab3bd6742 100644 --- a/packages/discord.js/src/client/actions/MessagePollVoteRemove.js +++ b/packages/discord.js/src/client/actions/MessagePollVoteRemove.js @@ -5,7 +5,7 @@ const Events = require('../../util/Events'); class MessagePollVoteRemoveAction extends Action { handle(data) { - const channel = this.getChannel(data); + const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); if (!channel?.isTextBased()) return false; const message = this.getMessage(data, channel); diff --git a/packages/discord.js/src/client/actions/MessageReactionAdd.js b/packages/discord.js/src/client/actions/MessageReactionAdd.js index ea97bd60d56f..6932358cf107 100644 --- a/packages/discord.js/src/client/actions/MessageReactionAdd.js +++ b/packages/discord.js/src/client/actions/MessageReactionAdd.js @@ -22,7 +22,7 @@ class MessageReactionAdd extends Action { if (!user) return false; // Verify channel - const channel = this.getChannel(data); + const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id, user_id: data.user_id }); if (!channel?.isTextBased()) return false; // Verify message diff --git a/packages/discord.js/src/client/actions/MessageReactionRemove.js b/packages/discord.js/src/client/actions/MessageReactionRemove.js index 9ca3a8e5e951..93874a777d26 100644 --- a/packages/discord.js/src/client/actions/MessageReactionRemove.js +++ b/packages/discord.js/src/client/actions/MessageReactionRemove.js @@ -19,7 +19,7 @@ class MessageReactionRemove extends Action { if (!user) return false; // Verify channel - const channel = this.getChannel(data); + const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id, user_id: data.user_id }); if (!channel?.isTextBased()) return false; // Verify message diff --git a/packages/discord.js/src/client/actions/MessageReactionRemoveAll.js b/packages/discord.js/src/client/actions/MessageReactionRemoveAll.js index b1c023f4b60b..5816341732f6 100644 --- a/packages/discord.js/src/client/actions/MessageReactionRemoveAll.js +++ b/packages/discord.js/src/client/actions/MessageReactionRemoveAll.js @@ -6,7 +6,7 @@ const Events = require('../../util/Events'); class MessageReactionRemoveAll extends Action { handle(data) { // Verify channel - const channel = this.getChannel(data); + const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); if (!channel?.isTextBased()) return false; // Verify message diff --git a/packages/discord.js/src/client/actions/MessageReactionRemoveEmoji.js b/packages/discord.js/src/client/actions/MessageReactionRemoveEmoji.js index 3290214ceed2..2916f061d290 100644 --- a/packages/discord.js/src/client/actions/MessageReactionRemoveEmoji.js +++ b/packages/discord.js/src/client/actions/MessageReactionRemoveEmoji.js @@ -5,7 +5,7 @@ const Events = require('../../util/Events'); class MessageReactionRemoveEmoji extends Action { handle(data) { - const channel = this.getChannel(data); + const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); if (!channel?.isTextBased()) return false; const message = this.getMessage(data, channel); diff --git a/packages/discord.js/src/client/actions/MessageUpdate.js b/packages/discord.js/src/client/actions/MessageUpdate.js index fe757c04e50d..181c17448c75 100644 --- a/packages/discord.js/src/client/actions/MessageUpdate.js +++ b/packages/discord.js/src/client/actions/MessageUpdate.js @@ -4,7 +4,7 @@ const Action = require('./Action'); class MessageUpdateAction extends Action { handle(data) { - const channel = this.getChannel(data); + const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); if (channel) { if (!channel.isTextBased()) return {}; diff --git a/packages/discord.js/src/client/actions/StageInstanceCreate.js b/packages/discord.js/src/client/actions/StageInstanceCreate.js index 4edd530460a2..1f3eb90670c6 100644 --- a/packages/discord.js/src/client/actions/StageInstanceCreate.js +++ b/packages/discord.js/src/client/actions/StageInstanceCreate.js @@ -6,7 +6,7 @@ const Events = require('../../util/Events'); class StageInstanceCreateAction extends Action { handle(data) { const client = this.client; - const channel = this.getChannel(data); + const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); if (channel) { const stageInstance = channel.guild.stageInstances._add(data); diff --git a/packages/discord.js/src/client/actions/StageInstanceDelete.js b/packages/discord.js/src/client/actions/StageInstanceDelete.js index 0d5da38a8a3f..b11bee2def5f 100644 --- a/packages/discord.js/src/client/actions/StageInstanceDelete.js +++ b/packages/discord.js/src/client/actions/StageInstanceDelete.js @@ -6,7 +6,7 @@ const Events = require('../../util/Events'); class StageInstanceDeleteAction extends Action { handle(data) { const client = this.client; - const channel = this.getChannel(data); + const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); if (channel) { const stageInstance = channel.guild.stageInstances._add(data); diff --git a/packages/discord.js/src/client/actions/StageInstanceUpdate.js b/packages/discord.js/src/client/actions/StageInstanceUpdate.js index 008a53ccec64..1375527547bb 100644 --- a/packages/discord.js/src/client/actions/StageInstanceUpdate.js +++ b/packages/discord.js/src/client/actions/StageInstanceUpdate.js @@ -6,7 +6,7 @@ const Events = require('../../util/Events'); class StageInstanceUpdateAction extends Action { handle(data) { const client = this.client; - const channel = this.getChannel(data); + const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); if (channel) { const oldStageInstance = channel.guild.stageInstances.cache.get(data.id)?._clone() ?? null; diff --git a/packages/discord.js/src/client/actions/TypingStart.js b/packages/discord.js/src/client/actions/TypingStart.js index 4e79920f2453..8e217eccc909 100644 --- a/packages/discord.js/src/client/actions/TypingStart.js +++ b/packages/discord.js/src/client/actions/TypingStart.js @@ -6,7 +6,7 @@ const Events = require('../../util/Events'); class TypingStart extends Action { handle(data) { - const channel = this.getChannel(data); + const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); if (!channel) return; if (!channel.isTextBased()) {