refactor(actions): safer getChannel calls

backport #10434
This commit is contained in:
Elysia
2024-09-17 20:23:59 +07:00
parent aed4d149b3
commit fb510d9bf5
11 changed files with 11 additions and 11 deletions

View File

@@ -9,7 +9,7 @@ let deprecationEmitted = false;
class MessageCreateAction extends Action { class MessageCreateAction extends Action {
handle(data) { handle(data) {
const client = this.client; 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) {
if (!channel.isText()) return {}; if (!channel.isText()) return {};

View File

@@ -7,7 +7,7 @@ const { Events } = require('../../util/Constants');
class MessageDeleteAction extends Action { class MessageDeleteAction extends Action {
handle(data) { handle(data) {
const client = this.client; const client = this.client;
const channel = this.getChannel(data); const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id });
let message; let message;
if (channel) { if (channel) {
if (!channel.isText()) return {}; if (!channel.isText()) return {};

View File

@@ -23,7 +23,7 @@ class MessageReactionAdd extends Action {
if (!user) return false; if (!user) return false;
// Verify channel // 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 || !channel.isText()) return false; if (!channel || !channel.isText()) return false;
// Verify message // Verify message

View File

@@ -19,7 +19,7 @@ class MessageReactionRemove extends Action {
if (!user) return false; if (!user) return false;
// Verify channel // 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 || !channel.isText()) return false; if (!channel || !channel.isText()) return false;
// Verify message // Verify message

View File

@@ -6,7 +6,7 @@ const { Events } = require('../../util/Constants');
class MessageReactionRemoveAll extends Action { class MessageReactionRemoveAll extends Action {
handle(data) { handle(data) {
// Verify channel // Verify channel
const channel = this.getChannel(data); const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id });
if (!channel || !channel.isText()) return false; if (!channel || !channel.isText()) return false;
// Verify message // Verify message

View File

@@ -5,7 +5,7 @@ const { Events } = require('../../util/Constants');
class MessageReactionRemoveEmoji extends Action { class MessageReactionRemoveEmoji extends Action {
handle(data) { handle(data) {
const channel = this.getChannel(data); const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id });
if (!channel || !channel.isText()) return false; if (!channel || !channel.isText()) return false;
const message = this.getMessage(data, channel); const message = this.getMessage(data, channel);

View File

@@ -4,7 +4,7 @@ const Action = require('./Action');
class MessageUpdateAction extends Action { class MessageUpdateAction extends Action {
handle(data) { handle(data) {
const channel = this.getChannel(data); const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id });
if (channel) { if (channel) {
if (!channel.isText()) return {}; if (!channel.isText()) return {};

View File

@@ -6,7 +6,7 @@ const { Events } = require('../../util/Constants');
class StageInstanceCreateAction extends Action { class StageInstanceCreateAction extends Action {
handle(data) { handle(data) {
const client = this.client; const client = this.client;
const channel = this.getChannel(data); const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id });
if (channel) { if (channel) {
const stageInstance = channel.guild.stageInstances._add(data); const stageInstance = channel.guild.stageInstances._add(data);

View File

@@ -7,7 +7,7 @@ const { Events } = require('../../util/Constants');
class StageInstanceDeleteAction extends Action { class StageInstanceDeleteAction extends Action {
handle(data) { handle(data) {
const client = this.client; const client = this.client;
const channel = this.getChannel(data); const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id });
if (channel) { if (channel) {
const stageInstance = channel.guild.stageInstances._add(data); const stageInstance = channel.guild.stageInstances._add(data);

View File

@@ -6,7 +6,7 @@ const { Events } = require('../../util/Constants');
class StageInstanceUpdateAction extends Action { class StageInstanceUpdateAction extends Action {
handle(data) { handle(data) {
const client = this.client; const client = this.client;
const channel = this.getChannel(data); const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id });
if (channel) { if (channel) {
const oldStageInstance = channel.guild.stageInstances.cache.get(data.id)?._clone() ?? null; const oldStageInstance = channel.guild.stageInstances.cache.get(data.id)?._clone() ?? null;

View File

@@ -6,7 +6,7 @@ const { Events } = require('../../util/Constants');
class TypingStart extends Action { class TypingStart extends Action {
handle(data) { 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) return;
if (!channel.isText()) { if (!channel.isText()) {