Skip to content

Commit

Permalink
fix: assert channel types in message actions (#6919)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceEEC committed Nov 1, 2021
1 parent 95d2a4d commit 9bd3689
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/client/actions/MessageCreate.js
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/client/actions/MessageDelete.js
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/client/actions/MessageDeleteBulk.js
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/actions/MessageReactionAdd.js
@@ -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');

/*
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/client/actions/MessageReactionRemove.js
@@ -1,7 +1,7 @@
'use strict';

const Action = require('./Action');
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
const { Events } = require('../../util/Constants');

/*
{ user_id: 'id',
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/client/actions/MessageReactionRemoveAll.js
@@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/client/actions/MessageReactionRemoveEmoji.js
@@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/client/actions/MessageUpdate.js
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/actions/TypingStart.js
Expand Up @@ -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;
}
Expand Down

0 comments on commit 9bd3689

Please sign in to comment.