From ab113790e3907b1caf7e31030e8d9a590ee6f039 Mon Sep 17 00:00:00 2001 From: March 7th <71698422+aiko-chan-ai@users.noreply.github.com> Date: Wed, 30 Mar 2022 18:09:23 +0700 Subject: [PATCH] 1. Fix message.mentions --- src/rest/RequestHandler.js | 4 +-- src/structures/Message.js | 58 +++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/rest/RequestHandler.js b/src/rest/RequestHandler.js index 355e0ea..8925dc4 100644 --- a/src/rest/RequestHandler.js +++ b/src/rest/RequestHandler.js @@ -11,8 +11,8 @@ const { } = require('../util/Constants'); function parseResponse(res) { - if (res.headers.get('content-type').startsWith('application/json')) return res.json(); - return res.buffer(); + if (res.headers.get('content-type').startsWith('application/json')) return res.json(); + return res.arrayBuffer(); // Cre: TheDevYellowy } function getAPIOffset(serverDate) { diff --git a/src/structures/Message.js b/src/structures/Message.js index 3a52cde..428bcce 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -225,19 +225,14 @@ class Message extends Base { * All valid mentions that the message contains * @type {MessageMentions} */ - if (!data.mentions) - this.mentions = new Mentions( - this, - data.mentions, - data.mention_roles, - data.mention_everyone, - data.mention_channels, - data.referenced_message?.author, - ); - else - data.mentions instanceof Mentions - ? (this.mentions = data.mentions) - : (this.mentions = null); + this.mentions = new Mentions( + this, + data.mentions, + data.mention_roles, + data.mention_everyone, + data.mention_channels, + data.referenced_message?.author, + ); } else { this.mentions = new Mentions( this, @@ -491,9 +486,8 @@ class Message extends Base { * @readonly */ get url() { - return `https://discord.com/channels/${this.guildId ?? '@me'}/${ - this.channelId - }/${this.id}`; + return `https://discord.com/channels/${this.guildId ?? '@me'}/${this.channelId + }/${this.id}`; } /** @@ -619,8 +613,8 @@ class Message extends Base { get editable() { const precheck = Boolean( this.author.id === this.client.user.id && - !deletedMessages.has(this) && - (!this.guild || this.channel?.viewable), + !deletedMessages.has(this) && + (!this.guild || this.channel?.viewable), ); // Regardless of permissions thread messages cannot be edited if // the thread is locked. @@ -654,8 +648,8 @@ class Message extends Base { return Boolean( this.author.id === this.client.user.id || - (permissions.has(Permissions.FLAGS.MANAGE_MESSAGES, false) && - this.guild.me.communicationDisabledUntilTimestamp < Date.now()), + (permissions.has(Permissions.FLAGS.MANAGE_MESSAGES, false) && + this.guild.me.communicationDisabledUntilTimestamp < Date.now()), ); } @@ -668,12 +662,12 @@ class Message extends Base { const { channel } = this; return Boolean( !this.system && - !deletedMessages.has(this) && - (!this.guild || - (channel?.viewable && - channel - ?.permissionsFor(this.client.user) - ?.has(Permissions.FLAGS.MANAGE_MESSAGES, false))), + !deletedMessages.has(this) && + (!this.guild || + (channel?.viewable && + channel + ?.permissionsFor(this.client.user) + ?.has(Permissions.FLAGS.MANAGE_MESSAGES, false))), ); } @@ -704,11 +698,11 @@ class Message extends Base { const { channel } = this; return Boolean( channel?.type === 'GUILD_NEWS' && - !this.flags.has(MessageFlags.FLAGS.CROSSPOSTED) && - this.type === 'DEFAULT' && - channel.viewable && - channel.permissionsFor(this.client.user)?.has(bitfield, false) && - !deletedMessages.has(this), + !this.flags.has(MessageFlags.FLAGS.CROSSPOSTED) && + this.type === 'DEFAULT' && + channel.viewable && + channel.permissionsFor(this.client.user)?.has(bitfield, false) && + !deletedMessages.has(this), ); } @@ -1097,7 +1091,7 @@ class Message extends Base { */ async contextMenu(botID, commandName) { if (!botID) throw new Error('Bot ID is required'); - const user = await this.client.users.fetch(botID).catch(() => {}); + const user = await this.client.users.fetch(botID).catch(() => { }); if (!user || !user.bot || !user.applications) throw new Error( 'BotID is not a bot or does not have an application slash command',