mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
Datastore cleanup (#1892)
* Start Store cleanup * wip store cleanup * fix iterables initiating datastores * handle the possibility of a datastore with no holds and no its own 'create' method * more cleanup (instances that need more than just client/data) * missed RoleStore extras * not sure how eslint didn't catch that tab... * avoid re-getting the channel we already have... * cleanup resolvers and refactor them into DataStores * ^ * and remove * fix some bugs * fix lint * fix documentation maybe? * formatting * fix presences * really fix presences this time * bad fix was bad... let;s see how bad this one is.. * forgot to save a file * make presence resolving take userresolveables too * fix tabs in jsdocs * fix bad fix from last night that caused issues, with better fix... * oops
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const DataStore = require('./DataStore');
|
||||
const Collection = require('../util/Collection');
|
||||
const Message = require('../structures/Message');
|
||||
const { Error } = require('../errors');
|
||||
let Message;
|
||||
|
||||
/**
|
||||
* Stores messages for text-based channels.
|
||||
@@ -9,19 +9,12 @@ let Message;
|
||||
*/
|
||||
class MessageStore extends DataStore {
|
||||
constructor(channel, iterable) {
|
||||
super(channel.client, iterable);
|
||||
super(channel.client, iterable, Message);
|
||||
this.channel = channel;
|
||||
Message = require('../structures/Message');
|
||||
}
|
||||
|
||||
create(data, cache = true) {
|
||||
const existing = this.get(data.id);
|
||||
if (existing) return existing;
|
||||
|
||||
const message = new Message(this.client.channels.get(data.channel_id), data, this.client);
|
||||
|
||||
if (cache) this.set(message.id, message);
|
||||
return message;
|
||||
create(data, cache) {
|
||||
return super.create(data, cache, { extras: [this.channel] });
|
||||
}
|
||||
|
||||
set(key, value) {
|
||||
@@ -62,7 +55,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 the reactions of the messages.
|
||||
* <info>The returned Collection does not contain the reactions of the messages.
|
||||
* Those need to be fetched seperately.</info>
|
||||
* @returns {Promise<Collection<Snowflake, Message>>}
|
||||
*/
|
||||
@@ -95,6 +88,30 @@ class MessageStore extends DataStore {
|
||||
return messages;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Data that can be resolved to a Message object. This can be:
|
||||
* * A Message
|
||||
* * A Snowflake
|
||||
* @typedef {Message|Snowflake} MessageResolvable
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves a MessageResolvable to a Message object.
|
||||
* @method resolve
|
||||
* @memberof MessageStore
|
||||
* @param {MessageResolvable} message The message resolvable to resolve
|
||||
* @returns {?Message}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves a MessageResolvable to a Message ID string.
|
||||
* @method MessageStore
|
||||
* @memberof PresenceStore
|
||||
* @param {MessageResolvable} message The message resolvable to resolve
|
||||
* @returns {?string}
|
||||
*/
|
||||
}
|
||||
|
||||
module.exports = MessageStore;
|
||||
|
||||
Reference in New Issue
Block a user