This repository has been archived by the owner on Jul 19, 2024. It is now read-only.
v2.3.0 - Cache n' Events
IN NO PARTICULAR ORDER!!!
Time of release: 2018-11-25
Main Part of the Update
index.d.ts
is now a thing. That's cool I guess.ClientOptions
now hascache
andcacheUpdateTimer
parameters!- What does this mean? You will no longer have to asynchronously fetch a bot/emoji/guild.
- To use, set
cache: true
, and if desired,cacheUpdateTimer: [Number]
, Number being the # of milliseconds to wait for each automatic cache update; Defaults to180000
(3 minutes; Set it as0
to disable) - Because
this.bots
,this.emojis
, andthis.guilds
won't be ready right on initialization, you'll be given new events. - Anytime you fetch something, it is automatically cached.
- Every New Event:
ready
=> When the first cache is updated, or it was never updated. Runs regardless of which.cacheUpdateAll
=> When all of the cache is updated.cacheUpdateBots
=> Emitted whenthis.bots
is updated.cacheUpdateEmojis
=> Emitted whenthis.emojis
is updated.cacheUpdateGuilds
=> Emitted withthis.guilds
is updated.post
=> Emitted when a post action is done.
- If
cache
is true, anytime you fetch a bot, emoji, or guild, it updates itself to their corrosponding Stores. this.bots
,this.emojis
, andthis.guilds
all use a newStore
class, which is generally aMap
but with more methods.
Utilizing Cache and Events
// Returns the bot's username.
Client.on('ready', (bots) => {
console.log(bots.get('BotID').username);
});
// You do not require the data value, you can call the Client itself.
// Returns each guild name.
Client.on('ready', () => {
console.log(Client.guilds.map(guild => guild.name).join('\n'));
});
// The total amount of animated listed emojis, which logs each time the emoji cache is updated.
Client.on('cacheUpdateEmojis', (bots, emojis, guilds) => {
console.log(Client.emojis.filter(e => e.animated).size);
});
// Get the data received when posting.
// Should return "200 Successfully updated server count" into the console.
Client.on('post', info => {
console.log(`${info.code} ${info.message}`);
});
Recap, Refactors, and Changes
Assumptions:
const Space = require('simple.space')
Important Notice: You are now to initiate the Client using new Space.Client()
New Structures
- Store - Basically a Map, but with extended methods for usage.
- UpvoteUser - Now, when fetching upvotes a bot has, the responses now have their own class instead of the partially-accepted PartialUser.
Main Features Implemented
Cache
Now synchronously fetch a bot/emoji/guild!
ClientOptions
accepts new values for use.cache
- Whether or not to cache all bots, guilds, and/or emojis.cacheUpdateTimer
- The number of milliseconds in which to update the cache. Set to 0 to disable.
- If cache is set to true,
this.bots
,.emojis
, and.guilds
, which are Stores, will be mapped by each respective bot/emoji/guild ID and its contents, and will be updated in an interval/whenever a Fetch is performed.
Events
Partially useful?
ready
- Emitted when the Client is initiated. If cache is set to true, this will be emitted when cache is complete. If false, this emits when initiated.cacheUpdate
- Emitted when ALL of the cache is updated. Works similarly toready
, but emits in a set interval. Never emits ifcacheUpdateTimer
is set to 0, nor ifClientOptions.cache
is configured tofalse
, its default value.cacheUpdateBots
- Emitted when any part ofthis.bots
is updated.cacheUpdateEmojis
- Emitted when any part ofthis.emojis
is updated.cacheUpdateGuilds
- Emitted when any part ofthis.guilds
is updated.post
Emitted whenever posting guild count is performed.
Type Fixes/Changes
- New
index.d.ts
file - Type Fixes where fetching all Bots/Guilds/Emojis claimed to return an array of Bot/Guild/Emoji with no Promise when indeed it would return a Promise.
No promises, though.
Function Reworks
.fetchUpvotes()
now returns an array of UpvoteUsers.hasUpvoted()
now accepts an array of strings. If an array of strings is passed in the first parameter, it returns a Store mapped by the user ID and whether or not they had upvoted..hasUpvoted()
now acceptsUpvoteFetchOptions
as its second parameter, though some values will be ignored, specificallynormal
,specified
,stringify
(It was originally intended forstringify
to be included as a usable parameter, but contributed to code clutter).postCount()
- Now accepts number as first parameter (Previously discouraged but I felt it was too annoying :p)
Bug Fixes
- Unsure what to call a bug though...
Deprecations
Client.setCount()
- Function rename; Now.postCount()
Misc
- All
FetchOptions
should now come into use when fetching anything, besides Stats. Space.Classes
rework; All classes (and client) now attached toindex.js
- Examples:
new Space.Client()
,new Space.ClientOptions({})
,new Space.Store()
- Examples:
Minor Note: In the future, fetching Bots, Emojis, or Guilds using the fetchAll
methods, may return a Store. normal
may then have a different use in that case, and FetchOptions
will have a new definition regarding getting the plain objects fetched. Not intended, but something to think about.