Skip to content

Commit

Permalink
ignore events containing unsupported channel types
Browse files Browse the repository at this point in the history
  • Loading branch information
timotejroiko committed Mar 17, 2022
1 parent bea8935 commit 2fc6c83
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ module.exports = {
if(!data.guild_id) { return; }
const guild = getOrCreateGuild(c, data.guild_id, data.shardId);
const channel = getOrCreateChannel(c, data.channel_id, guild);
if(!channel) { return {}; }
const invite = guild.invites._add(Object.assign(data, { channel, guild }));
return { invite };
},
Expand All @@ -422,6 +423,7 @@ module.exports = {
let invite = guild.invites.cache.get(data.code);
if(!invite) {
const channel = getOrCreateChannel(c, data.channel_id, guild);
if(!channel) { return {}; }
invite = guild.invites._add(Object.assign(data, { channel, guild }), false);
invite.partial = true;
}
Expand All @@ -433,6 +435,7 @@ module.exports = {
const c = this.client;
const guild = data.guild_id ? getOrCreateGuild(c, data.guild_id, data.shardId) : void 0;
const channel = getOrCreateChannel(c, data.channel_id, guild);
if(!channel) { return {}; }
channel.lastMessageId = data.id;
const message = channel.messages._add(data);
return { message };
Expand All @@ -443,6 +446,7 @@ module.exports = {
const c = this.client;
const guild = data.guild_id ? getOrCreateGuild(c, data.guild_id, data.shardId) : void 0;
const channel = getOrCreateChannel(c, data.channel_id, guild);
if(!channel) { return {}; }
const message = getOrCreateMessage(channel, data.id);
channel.messages.cache.delete(message.id);
message.deleted = true;
Expand All @@ -453,6 +457,7 @@ module.exports = {
const c = this.client;
const guild = data.guild_id ? getOrCreateGuild(c, data.guild_id, data.shardId) : void 0;
const channel = getOrCreateChannel(c, data.channel_id, guild);
if(!channel) { return {}; }
const deleted = new Collection();
for(const id of data.ids) {
const message = getOrCreateMessage(channel, id);
Expand All @@ -467,6 +472,7 @@ module.exports = {
const c = this.client;
const guild = data.guild_id ? getOrCreateGuild(c, data.guild_id, data.shardId) : void 0;
const channel = getOrCreateChannel(c, data.channel_id, guild);
if(!channel) { return {}; }
let message = channel.messages.cache.get(data.id);
let old;
if(message) {
Expand All @@ -488,6 +494,7 @@ module.exports = {
if(!channel) {
const guild = data.guild_id ? getOrCreateGuild(c, data.guild_id, data.shardId) : void 0;
channel = getOrCreateChannel(c, data.channel_id, guild);
if(!channel) { return {}; }
}
let user = data.user || c.users.cache.get(data.user_id);
if(!user) {
Expand Down Expand Up @@ -515,6 +522,7 @@ module.exports = {
const c = this.client;
const guild = data.guild_id ? getOrCreateGuild(c, data.guild_id, data.shardId) : void 0;
const channel = getOrCreateChannel(c, data.channel_id, guild);
if(!channel) { return {}; }
let user = c.users.cache.get(data.user_id);
if(!user) {
user = c.users._add({ id: data.user_id }, false); // has built in partial
Expand All @@ -540,6 +548,7 @@ module.exports = {
const c = this.client;
const guild = data.guild_id ? getOrCreateGuild(c, data.guild_id, data.shardId) : void 0;
const channel = getOrCreateChannel(c, data.channel_id, guild);
if(!channel) { return {}; }
const message = getOrCreateMessage(channel, data.message_id);
const removed = message.reactions.cache.clone();
message.reactions.cache.clear();
Expand All @@ -550,6 +559,7 @@ module.exports = {
const c = this.client;
const guild = data.guild_id ? getOrCreateGuild(c, data.guild_id, data.shardId) : void 0;
const channel = getOrCreateChannel(c, data.channel_id, guild);
if(!channel) { return {}; }
const message = getOrCreateMessage(channel, data.message_id);
let reaction = message.reactions.cache.get(data.emoji.id ?? decodeURIComponent(data.emoji.name));
if(!reaction) {
Expand Down Expand Up @@ -596,6 +606,7 @@ module.exports = {
const c = this.client;
const guild = getOrCreateGuild(c, data.guild_id, data.shardId);
const channel = getOrCreateChannel(c, data.channel_id, guild);
if(!channel) { return {}; }
const stageInstance = channel.guild.stageInstances._add(data);
c.emit(Constants.Events.STAGE_INSTANCE_CREATE, stageInstance);
return { stageInstance };
Expand All @@ -605,6 +616,7 @@ module.exports = {
const c = this.client;
const guild = getOrCreateGuild(c, data.guild_id, data.shardId);
const channel = getOrCreateChannel(c, data.channel_id, guild);
if(!channel) { return {}; }
const stageInstance = channel.guild.stageInstances._add(data);
if(stageInstance) {
channel.guild.stageInstances.cache.delete(stageInstance.id);
Expand All @@ -618,6 +630,7 @@ module.exports = {
const c = this.client;
const guild = getOrCreateGuild(c, data.guild_id, data.shardId);
const channel = getOrCreateChannel(c, data.channel_id, guild);
if(!channel) { return {}; }
let oldStageInstance = channel.guild.stageInstances.cache.get(data.id)?._clone();
if(!oldStageInstance) {
oldStageInstance = channel.guild.stageInstances._add({ id: data.id }, false);
Expand Down Expand Up @@ -739,6 +752,7 @@ module.exports = {
const c = this.client;
const guild = data.guild_id ? getOrCreateGuild(c, data.guild_id, data.shardId) : void 0;
const channel = getOrCreateChannel(c, data.channel_id, guild);
if(!channel) { return; }
let user = c.users.cache.get(data.user_id);
if(!user) {
if(data.member?.user) {
Expand Down Expand Up @@ -796,6 +810,7 @@ module.exports = {
const c = this.client;
const guild = getOrCreateGuild(c, data.guild_id, data.shardId);
const channel = getOrCreateChannel(c, data.channel_id, guild);
if(!channel) { return; }
c.emit(Constants.Events.WEBHOOKS_UPDATE, channel);
}

Expand Down
1 change: 1 addition & 0 deletions extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ override("/structures/MessageMentions.js", X => class MessageMentions extends X
let matches;
while((matches = this.constructor.CHANNELS_PATTERN.exec(this._content)) !== null) {
const chan = getOrCreateChannel(this.client, matches[1], this.guild);
if(!chan) { continue; }
this._channels.set(chan.id, chan);
}
return this._channels;
Expand Down
1 change: 1 addition & 0 deletions functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function getOrCreateChannel(client, id, guild) {
let channel = client.channels.cache.get(id);
if(!channel) {
channel = client.channels._add({ id, type: guild ? 0 : 1 }, guild, { cache: false });
if(!channel) { return null; }
makePartial(channel);
}
return channel;
Expand Down
11 changes: 11 additions & 0 deletions handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const handlers = {
CHANNEL_PINS_UPDATE: (client, { d: data }, shard) => {
const guild = data.guild_id ? getOrCreateGuild(client, data.guild_id, shard.id) : void 0;
const channel = getOrCreateChannel(client, data.channel_id, guild);
if(!channel) { return; }
const time = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
channel.lastPinTimestamp = time;
client.emit(Constants.Events.CHANNEL_PINS_UPDATE, channel, time);
Expand Down Expand Up @@ -264,60 +265,70 @@ const handlers = {
INVITE_CREATE: (client, packet, shard) => {
packet.d.shardId = shard.id;
const { invite } = client.actions.InviteCreate.handle(packet.d);
if(!invite) { return; }
client.emit(Constants.Events.INVITE_CREATE, invite);
},

INVITE_DELETE: (client, packet, shard) => {
packet.d.shardId = shard.id;
const { invite } = client.actions.InviteDelete.handle(packet.d);
if(!invite) { return; }
client.emit(Constants.Events.INVITE_DELETE, invite);
},

MESSAGE_CREATE: (client, packet, shard) => {
packet.d.shardId = shard.id;
const { message } = client.actions.MessageCreate.handle(packet.d);
if(!message) { return; }
client.emit(Constants.Events.MESSAGE_CREATE, message);
},

MESSAGE_DELETE: (client, packet, shard) => {
packet.d.shardId = shard.id;
const { message } = client.actions.MessageDelete.handle(packet.d);
if(!message) { return; }
client.emit(Constants.Events.MESSAGE_DELETE, message);
},

MESSAGE_DELETE_BULK: (client, packet, shard) => {
packet.d.shardId = shard.id;
const { messages } = client.actions.MessageDeleteBulk.handle(packet.d);
if(!messages) { return; }
client.emit(Constants.Events.MESSAGE_BULK_DELETE, messages);
},

MESSAGE_UPDATE: (client, packet, shard) => {
packet.d.shardId = shard.id;
const { old, updated } = client.actions.MessageUpdate.handle(packet.d);
if(!updated) { return; }
client.emit(Constants.Events.MESSAGE_UPDATE, old, updated);
},

MESSAGE_REACTION_ADD: (client, packet, shard) => {
packet.d.shardId = shard.id;
const { reaction, user } = client.actions.MessageReactionAdd.handle(packet.d);
if(!reaction) { return; }
client.emit(Constants.Events.MESSAGE_REACTION_ADD, reaction, user);
},

MESSAGE_REACTION_REMOVE: (client, packet, shard) => {
packet.d.shardId = shard.id;
const { reaction, user } = client.actions.MessageReactionRemove.handle(packet.d);
if(!reaction) { return; }
client.emit(Constants.Events.MESSAGE_REACTION_REMOVE, reaction, user);
},

MESSAGE_REACTION_REMOVE_ALL: (client, packet, shard) => {
packet.d.shardId = shard.id;
const { message, removed } = client.actions.MessageReactionRemoveAll.handle(packet.d);
if(!message) { return; }
client.emit(Constants.Events.MESSAGE_REACTION_REMOVE_ALL, message, removed);
},

MESSAGE_REACTION_REMOVE_EMOJI: (client, packet, shard) => {
packet.d.shardId = shard.id;
const { reaction } = client.actions.MessageReactionRemoveEmoji.handle(packet.d);
if(!reaction) { return; }
client.emit(Constants.Events.MESSAGE_REACTION_REMOVE_EMOJI, reaction);
},

Expand Down

0 comments on commit 2fc6c83

Please sign in to comment.