From 50be99531b2218e688e6e4e2656a268447100e06 Mon Sep 17 00:00:00 2001 From: didinele Date: Wed, 7 Aug 2024 19:50:09 +0300 Subject: [PATCH 1/2] refactor(actions): safer getChannel calls --- 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..f79b50555aeb 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({ channel_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..4df2876a810d 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({ channel_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..d0056ab5b650 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({ channel_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..81aea3eaa2b8 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({ channel_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..deb8dd2fb3d8 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({ channel_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..de793c67e987 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({ channel_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..c93c5f8bb30b 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({ channel_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..dacea8d80901 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({ channel_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..695ed6352749 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({ channel_id: data.channel_id, guild_id: data.guild_id }); if (!channel) return; if (!channel.isTextBased()) { From 6b924f375444a70a5474f63a8b79460e02c23023 Mon Sep 17 00:00:00 2001 From: didinele Date: Wed, 7 Aug 2024 21:11:29 +0300 Subject: [PATCH 2/2] chore: consistency --- 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 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/discord.js/src/client/actions/MessageReactionAdd.js b/packages/discord.js/src/client/actions/MessageReactionAdd.js index f79b50555aeb..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({ channel_id: data.channel_id, guild_id: data.guild_id, user_id: data.user_id }); + 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 4df2876a810d..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({ channel_id: data.channel_id, guild_id: data.guild_id, user_id: data.user_id }); + 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 d0056ab5b650..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({ channel_id: data.channel_id, guild_id: data.guild_id }); + 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 81aea3eaa2b8..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({ channel_id: data.channel_id, guild_id: data.guild_id }); + 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 deb8dd2fb3d8..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({ channel_id: data.channel_id, guild_id: data.guild_id }); + 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 de793c67e987..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({ channel_id: data.channel_id, guild_id: data.guild_id }); + 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 c93c5f8bb30b..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({ channel_id: data.channel_id, guild_id: data.guild_id }); + 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 dacea8d80901..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({ channel_id: data.channel_id, guild_id: data.guild_id }); + 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 695ed6352749..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({ channel_id: data.channel_id, guild_id: data.guild_id }); + const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); if (!channel) return; if (!channel.isTextBased()) {