* Remove GroupDMChannels

they sparked no joy

* Start partials for message deletion

* MessageUpdate partials

* Add partials as an opt-in client option

* Add fetch() to Message

* Message.author should never be undefined

* Fix channels being the wrong type

* Allow fetching channels

* Refactor and add reaction add partials

* Reaction remove partials

* Check for emoji first

* fix message fetching

janky

* User partials in audit logs

* refactor overwrite code

* guild member partials

* partials as a whitelist

* document GuildMember#fetch

* fix: check whether a structure is a partial, not whether cache is true

* typings: Updated for latest commit (#3075)

* partials: fix messageUpdate behaviour (now "old" message can be partial)

* partials: add warnings and docs

* partials: add partials to index.yml

* partials: tighten "partial" definitions

* partials: fix embed-only messages counting as partials
This commit is contained in:
Amish Shah
2019-02-13 17:39:39 +00:00
committed by GitHub
parent 8910fed729
commit 5c3f5d7048
35 changed files with 295 additions and 383 deletions

View File

@@ -24,7 +24,7 @@ class Message extends Base {
/**
* The channel that the message was sent in
* @type {TextChannel|DMChannel|GroupDMChannel}
* @type {TextChannel|DMChannel}
*/
this.channel = channel;
@@ -60,7 +60,7 @@ class Message extends Base {
* The author of the message
* @type {User}
*/
this.author = this.client.users.add(data.author, !data.webhook_id);
this.author = data.author ? this.client.users.add(data.author, !data.webhook_id) : null;
/**
* Whether or not this message is pinned
@@ -90,17 +90,19 @@ class Message extends Base {
* A list of embeds in the message - e.g. YouTube Player
* @type {MessageEmbed[]}
*/
this.embeds = data.embeds.map(e => new Embed(e));
this.embeds = (data.embeds || []).map(e => new Embed(e));
/**
* A collection of attachments in the message - e.g. Pictures - mapped by their ID
* @type {Collection<Snowflake, MessageAttachment>}
*/
this.attachments = new Collection();
for (const attachment of data.attachments) {
this.attachments.set(attachment.id, new MessageAttachment(
attachment.url, attachment.filename, attachment
));
if (data.attachments) {
for (const attachment of data.attachments) {
this.attachments.set(attachment.id, new MessageAttachment(
attachment.url, attachment.filename, attachment
));
}
}
/**
@@ -167,6 +169,14 @@ class Message extends Base {
}
}
/**
* Whether or not this message is a partial
* @type {boolean}
*/
get partial() {
return typeof this.content !== 'string' || !this.author;
}
/**
* Updates the message.
* @param {Object} data Raw Discord message update data
@@ -472,6 +482,14 @@ class Message extends Base {
);
}
/**
* Fetch this message.
* @returns {Promise<Message>}
*/
fetch() {
return this.channel.messages.fetch(this.id, true);
}
/**
* Fetches the webhook used to create this message.
* @returns {Promise<?Webhook>}