mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Reduce memory usage by dynamically creating Dates
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -260,11 +260,7 @@ class Guild {
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.large = data.large;
|
||||
/**
|
||||
* The date at which the logged-in client joined the guild.
|
||||
* @type {Date}
|
||||
*/
|
||||
this.joinDate = new Date(data.joined_at);
|
||||
this._joinDate = new Date(data.joined_at).getTime();
|
||||
/**
|
||||
* The hash of the guild icon, or null if there is no icon.
|
||||
* @type {?String}
|
||||
@@ -359,6 +355,13 @@ class Guild {
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The date at which the logged-in client joined the guild.
|
||||
* @type {Date}
|
||||
*/
|
||||
get joinDate() {
|
||||
return new Date(this._joinDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Channel in the Guild.
|
||||
|
||||
@@ -59,11 +59,7 @@ class GuildMember {
|
||||
* @type {?String}
|
||||
*/
|
||||
this.voiceChannelID = data.channel_id;
|
||||
/**
|
||||
* The date this member joined the guild
|
||||
* @type {Date}
|
||||
*/
|
||||
this.joinDate = new Date(data.joined_at);
|
||||
this._joinDate = new Date(data.joined_at).getTime();
|
||||
/**
|
||||
* Whether this meember is speaking
|
||||
* @type {?Boolean}
|
||||
@@ -77,6 +73,14 @@ class GuildMember {
|
||||
this._roles = data.roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* The date this member joined the guild
|
||||
* @type {Date}
|
||||
*/
|
||||
get joinDate() {
|
||||
return new Date(this._joinDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of roles that are applied to this GuildMember
|
||||
* @type {Array<Role>}
|
||||
|
||||
@@ -47,12 +47,7 @@ class Invite {
|
||||
* @type {String}
|
||||
*/
|
||||
this.code = data.code;
|
||||
|
||||
/**
|
||||
* The creation date of the invite
|
||||
* @type {Date}
|
||||
*/
|
||||
this.creationDate = new Date(data.created_at);
|
||||
this._creationDate = new Date(data.created_at).getTime();
|
||||
|
||||
/**
|
||||
* Whether or not this invite is temporary
|
||||
@@ -93,6 +88,14 @@ class Invite {
|
||||
this.channels = this.client.channels.get(data.channel.id) || new PartialGuildChannel(this.client, data.channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* The creation date of the invite
|
||||
* @type {Date}
|
||||
*/
|
||||
get creationDate() {
|
||||
return new Date(this._creationDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes this invite
|
||||
* @returns {Promise<Invite, Error>}
|
||||
|
||||
@@ -55,16 +55,8 @@ class Message {
|
||||
* @type {String}
|
||||
*/
|
||||
this.content = data.content;
|
||||
/**
|
||||
* When the message was sent
|
||||
* @type {Date}
|
||||
*/
|
||||
this.timestamp = new Date(data.timestamp);
|
||||
/**
|
||||
* If the message was edited, the timestamp at which it was last edited
|
||||
* @type {?Date}
|
||||
*/
|
||||
this.editedTimestamp = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
||||
this._timestamp = new Date(data.timestamp).getTime();
|
||||
this._editedTimestamp = data.edited_timestamp ? new Date(data.edited_timestamp).getTime() : null;
|
||||
/**
|
||||
* Whether or not the message was Text-To-Speech
|
||||
* @type {Boolean}
|
||||
@@ -147,6 +139,21 @@ class Message {
|
||||
this.system = true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* When the message was sent
|
||||
* @type {Date}
|
||||
*/
|
||||
get timestamp() {
|
||||
return new Date(this._timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the message was edited, the timestamp at which it was last edited
|
||||
* @type {?Date}
|
||||
*/
|
||||
get editedTimestamp() {
|
||||
return new Date(this._editedTimestamp);
|
||||
}
|
||||
|
||||
patch(data) {
|
||||
if (data.author) {
|
||||
@@ -159,10 +166,10 @@ class Message {
|
||||
this.content = data.content;
|
||||
}
|
||||
if (data.timestamp) {
|
||||
this.timestamp = new Date(data.timestamp);
|
||||
this._timestamp = new Date(data.timestamp).getTime();
|
||||
}
|
||||
if (data.edited_timestamp) {
|
||||
this.editedTimestamp = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
||||
this._editedTimestamp = data.edited_timestamp ? new Date(data.edited_timestamp).getTime() : null;
|
||||
}
|
||||
if ('tts' in data) {
|
||||
this.tts = data.tts;
|
||||
@@ -247,8 +254,8 @@ class Message {
|
||||
|
||||
if (base && rawData) {
|
||||
base = this.mentions.everyone === message.mentions.everyone &&
|
||||
this.timestamp.getTime() === new Date(rawData.timestamp).getTime() &&
|
||||
this.editedTimestamp === new Date(rawData.edited_timestamp).getTime();
|
||||
this._timestamp === new Date(rawData.timestamp).getTime() &&
|
||||
this._editedTimestamp === new Date(rawData.edited_timestamp).getTime();
|
||||
}
|
||||
|
||||
return base;
|
||||
|
||||
@@ -4,7 +4,7 @@ const Discord = require('../');
|
||||
const request = require('superagent');
|
||||
const fs = require('fs');
|
||||
|
||||
const client = new Discord.Client({ fetch_all_members: false });
|
||||
const client = new Discord.Client({ fetch_all_members: true });
|
||||
|
||||
const { email, password, token } = require('./auth.json');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user