feat(Message): add support for flag editing / embed suppression (#3674)

This commit is contained in:
Vlad Frangu
2020-02-16 20:36:10 +02:00
committed by GitHub
parent bc5e2950d0
commit 46ee06b424
3 changed files with 38 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ const MessageAttachment = require('./MessageAttachment');
const { browser } = require('../util/Constants');
const Util = require('../util/Util');
const { RangeError } = require('../errors');
const MessageFlags = require('../util/MessageFlags');
/**
* Represents a message to be sent to the API.
@@ -63,6 +64,16 @@ class APIMessage {
return this.target instanceof User || this.target instanceof GuildMember;
}
/**
* Whether or not the target is a message
* @type {boolean}
* @readonly
*/
get isMessage() {
const Message = require('./Message');
return this.target instanceof Message;
}
/**
* Makes the content of this message.
* @returns {?(string|string[])}
@@ -126,6 +137,7 @@ class APIMessage {
const content = this.makeContent();
const tts = Boolean(this.options.tts);
let nonce;
if (typeof this.options.nonce !== 'undefined') {
nonce = parseInt(this.options.nonce);
@@ -149,6 +161,12 @@ class APIMessage {
if (this.options.avatarURL) avatarURL = this.options.avatarURL;
}
let flags;
if (this.isMessage) {
// eslint-disable-next-line eqeqeq
flags = this.options.flags != null ? new MessageFlags(this.options.flags).bitfield : this.target.flags.bitfield;
}
this.data = {
content,
tts,
@@ -157,6 +175,7 @@ class APIMessage {
embeds,
username,
avatar_url: avatarURL,
flags,
};
return this;
}