Expose TextBasedChannel#fetchMessage() (#602)

This commit is contained in:
Manuel Kraus
2016-09-04 19:46:29 +02:00
committed by Amish Shah
parent 4a252380d9
commit 48e7fad1c9
6 changed files with 48 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@@ -287,6 +287,18 @@ class RESTMethods {
});
}
getChannelMessage(channel, messageID) {
return new Promise((resolve, reject) => {
const msg = channel.messages.get(messageID);
if (msg) return resolve(msg);
const endpoint = Constants.Endpoints.channelMessage(channel.id, messageID);
return this.rest.makeRequest('get', endpoint, true)
.then(resolve)
.catch(reject);
});
}
updateGuildMember(member, data) {
return new Promise((resolve, reject) => {
if (data.channel) data.channel_id = this.rest.client.resolver.resolveChannel(data.channel).id;

View File

@@ -59,6 +59,10 @@ class DMChannel extends Channel {
return;
}
fetchMessage() {
return;
}
bulkDelete() {
return;
}

View File

@@ -118,6 +118,10 @@ class GroupDMChannel extends Channel {
return;
}
fetchMessage() {
return;
}
bulkDelete() {
return;
}

View File

@@ -43,6 +43,10 @@ class TextChannel extends GuildChannel {
return;
}
fetchMessage() {
return;
}
bulkDelete() {
return;
}

View File

@@ -133,6 +133,28 @@ class TextBasedChannel {
});
}
/**
* Gets a single message from this channel, regardless of it being cached or not.
* @param {string} messageID The ID of the message to get
* @returns {Promise<Message>}
* @example
* // get message
* channel.fetchMessage('99539446449315840')
* .then(message => console.log(message.content))
* .catch(console.error);
*/
fetchMessage(messageID) {
return new Promise((resolve, reject) => {
this.client.rest.methods.getChannelMessage(this, messageID).then(data => {
let msg = data;
if (!(msg instanceof Message)) msg = new Message(this, data, this.client);
this._cacheMessage(msg);
resolve(msg);
}).catch(reject);
});
}
/**
* Starts a typing indicator in the channel.
* @param {number} [count] The number of times startTyping should be considered to have been called
@@ -394,6 +416,7 @@ exports.applyToClass = (structure, full = false) => {
if (full) {
props.push('_cacheMessage');
props.push('fetchMessages');
props.push('fetchMessage');
props.push('bulkDelete');
props.push('startTyping');
props.push('stopTyping');