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

refactor(actions): safer getChannel calls #10434

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/discord.js/src/client/actions/MessageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};

Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/client/actions/MessageDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
didinele marked this conversation as resolved.
Show resolved Hide resolved
if (!channel?.isTextBased()) return false;

// Verify message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
didinele marked this conversation as resolved.
Show resolved Hide resolved
if (!channel?.isTextBased()) return false;

// Verify message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/client/actions/MessageUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/client/actions/TypingStart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Loading