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

fix: assert channel types in message actions #6919

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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