feat(MessageStore): add cache parameter to fetchPinned() (#3154)

* add cache param to MessageStore#fetchPinned()

* typings for cache param

* set cache to true by default
This commit is contained in:
izexi
2019-03-19 19:35:58 +00:00
committed by SpaceEEC
parent 2341d13615
commit 9b2bf03ff6
2 changed files with 6 additions and 5 deletions

View File

@@ -66,6 +66,7 @@ class MessageStore extends DataStore {
* Fetches the pinned messages of this channel and returns a collection of them.
* <info>The returned Collection does not contain any reaction data of the messages.
* Those need to be fetched separately.</info>
* @param {boolean} [cache=true] Whether to cache the message(s)
* @returns {Promise<Collection<Snowflake, Message>>}
* @example
* // Get pinned messages
@@ -73,10 +74,10 @@ class MessageStore extends DataStore {
* .then(messages => console.log(`Received ${messages.size} messages`))
* .catch(console.error);
*/
fetchPinned() {
fetchPinned(cache = true) {
return this.client.api.channels[this.channel.id].pins.get().then(data => {
const messages = new Collection();
for (const message of data) messages.set(message.id, this.add(message));
for (const message of data) messages.set(message.id, this.add(message, cache));
return messages;
});
}

6
typings/index.d.ts vendored
View File

@@ -1366,9 +1366,9 @@ declare module 'discord.js' {
export class MessageStore extends DataStore<Snowflake, Message, typeof Message, MessageResolvable> {
constructor(channel: TextChannel | DMChannel, iterable?: Iterable<any>);
public fetch(message: Snowflake): Promise<Message>;
public fetch(options?: ChannelLogsQueryOptions): Promise<Collection<Snowflake, Message>>;
public fetchPinned(): Promise<Collection<Snowflake, Message>>;
public fetch(message: Snowflake, cache?: boolean): Promise<Message>;
public fetch(options?: ChannelLogsQueryOptions, cache?: boolean): Promise<Collection<Snowflake, Message>>;
public fetchPinned(cache?: boolean): Promise<Collection<Snowflake, Message>>;
}
export class PresenceStore extends DataStore<Snowflake, Presence, typeof Presence, PresenceResolvable> {