fix: assert channel types in message actions (#6919)

This commit is contained in:
SpaceEEC
2021-11-01 18:40:19 +01:00
committed by GitHub
parent 95d2a4d35e
commit 9bd3689fb1
9 changed files with 18 additions and 10 deletions

View File

@@ -10,6 +10,8 @@ class MessageCreateAction extends Action {
const client = this.client;
const channel = this.getChannel(data);
if (channel) {
if (!channel.isText()) return {};
const existing = channel.messages.cache.get(data.id);
if (existing) return { message: existing };
const message = channel.messages._add(data);

View File

@@ -9,6 +9,8 @@ class MessageDeleteAction extends Action {
const channel = this.getChannel(data);
let message;
if (channel) {
if (!channel.isText()) return {};
message = this.getMessage(data, channel);
if (message) {
channel.messages.cache.delete(message.id);

View File

@@ -10,6 +10,8 @@ class MessageDeleteBulkAction extends Action {
const channel = client.channels.cache.get(data.channel_id);
if (channel) {
if (!channel.isText()) return {};
const ids = data.ids;
const messages = new Collection();
for (const id of ids) {

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
const { Events } = require('../../util/Constants');
const { PartialTypes } = require('../../util/Constants');
/*
@@ -23,7 +23,7 @@ class MessageReactionAdd extends Action {
// Verify channel
const channel = this.getChannel(data);
if (!channel || VoiceBasedChannelTypes.includes(channel.type)) return false;
if (!channel || !channel.isText()) return false;
// Verify message
const message = this.getMessage(data, channel);

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
const { Events } = require('../../util/Constants');
/*
{ user_id: 'id',
@@ -20,7 +20,7 @@ class MessageReactionRemove extends Action {
// Verify channel
const channel = this.getChannel(data);
if (!channel || VoiceBasedChannelTypes.includes(channel.type)) return false;
if (!channel || !channel.isText()) return false;
// Verify message
const message = this.getMessage(data, channel);

View File

@@ -1,13 +1,13 @@
'use strict';
const Action = require('./Action');
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
const { Events } = require('../../util/Constants');
class MessageReactionRemoveAll extends Action {
handle(data) {
// Verify channel
const channel = this.getChannel(data);
if (!channel || VoiceBasedChannelTypes.includes(channel.type)) return false;
if (!channel || !channel.isText()) return false;
// Verify message
const message = this.getMessage(data, channel);

View File

@@ -1,12 +1,12 @@
'use strict';
const Action = require('./Action');
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
const { Events } = require('../../util/Constants');
class MessageReactionRemoveEmoji extends Action {
handle(data) {
const channel = this.getChannel(data);
if (!channel || VoiceBasedChannelTypes.includes(channel.type)) return false;
if (!channel || !channel.isText()) return false;
const message = this.getMessage(data, channel);
if (!message) return false;

View File

@@ -6,6 +6,8 @@ class MessageUpdateAction extends Action {
handle(data) {
const channel = this.getChannel(data);
if (channel) {
if (!channel.isText()) return {};
const { id, channel_id, guild_id, author, timestamp, type } = data;
const message = this.getMessage({ id, channel_id, guild_id, author, timestamp, type }, channel);
if (message) {

View File

@@ -2,14 +2,14 @@
const Action = require('./Action');
const Typing = require('../../structures/Typing');
const { Events, TextBasedChannelTypes } = require('../../util/Constants');
const { Events } = require('../../util/Constants');
class TypingStart extends Action {
handle(data) {
const channel = this.getChannel(data);
if (!channel) return;
if (!TextBasedChannelTypes.includes(channel.type)) {
if (!channel.isText()) {
this.client.emit(Events.WARN, `Discord sent a typing packet to a ${channel.type} channel ${channel.id}`);
return;
}