mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 12:33:30 +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}
|
* @type {Boolean}
|
||||||
*/
|
*/
|
||||||
this.large = data.large;
|
this.large = data.large;
|
||||||
/**
|
this._joinDate = new Date(data.joined_at).getTime();
|
||||||
* The date at which the logged-in client joined the guild.
|
|
||||||
* @type {Date}
|
|
||||||
*/
|
|
||||||
this.joinDate = new Date(data.joined_at);
|
|
||||||
/**
|
/**
|
||||||
* The hash of the guild icon, or null if there is no icon.
|
* The hash of the guild icon, or null if there is no icon.
|
||||||
* @type {?String}
|
* @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.
|
* Creates a new Channel in the Guild.
|
||||||
|
|||||||
@@ -59,11 +59,7 @@ class GuildMember {
|
|||||||
* @type {?String}
|
* @type {?String}
|
||||||
*/
|
*/
|
||||||
this.voiceChannelID = data.channel_id;
|
this.voiceChannelID = data.channel_id;
|
||||||
/**
|
this._joinDate = new Date(data.joined_at).getTime();
|
||||||
* The date this member joined the guild
|
|
||||||
* @type {Date}
|
|
||||||
*/
|
|
||||||
this.joinDate = new Date(data.joined_at);
|
|
||||||
/**
|
/**
|
||||||
* Whether this meember is speaking
|
* Whether this meember is speaking
|
||||||
* @type {?Boolean}
|
* @type {?Boolean}
|
||||||
@@ -77,6 +73,14 @@ class GuildMember {
|
|||||||
this._roles = data.roles;
|
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
|
* A list of roles that are applied to this GuildMember
|
||||||
* @type {Array<Role>}
|
* @type {Array<Role>}
|
||||||
|
|||||||
@@ -47,12 +47,7 @@ class Invite {
|
|||||||
* @type {String}
|
* @type {String}
|
||||||
*/
|
*/
|
||||||
this.code = data.code;
|
this.code = data.code;
|
||||||
|
this._creationDate = new Date(data.created_at).getTime();
|
||||||
/**
|
|
||||||
* The creation date of the invite
|
|
||||||
* @type {Date}
|
|
||||||
*/
|
|
||||||
this.creationDate = new Date(data.created_at);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not this invite is temporary
|
* 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);
|
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
|
* Deletes this invite
|
||||||
* @returns {Promise<Invite, Error>}
|
* @returns {Promise<Invite, Error>}
|
||||||
|
|||||||
@@ -55,16 +55,8 @@ class Message {
|
|||||||
* @type {String}
|
* @type {String}
|
||||||
*/
|
*/
|
||||||
this.content = data.content;
|
this.content = data.content;
|
||||||
/**
|
this._timestamp = new Date(data.timestamp).getTime();
|
||||||
* When the message was sent
|
this._editedTimestamp = data.edited_timestamp ? new Date(data.edited_timestamp).getTime() : null;
|
||||||
* @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;
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the message was Text-To-Speech
|
* Whether or not the message was Text-To-Speech
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
@@ -147,6 +139,21 @@ class Message {
|
|||||||
this.system = true;
|
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) {
|
patch(data) {
|
||||||
if (data.author) {
|
if (data.author) {
|
||||||
@@ -159,10 +166,10 @@ class Message {
|
|||||||
this.content = data.content;
|
this.content = data.content;
|
||||||
}
|
}
|
||||||
if (data.timestamp) {
|
if (data.timestamp) {
|
||||||
this.timestamp = new Date(data.timestamp);
|
this._timestamp = new Date(data.timestamp).getTime();
|
||||||
}
|
}
|
||||||
if (data.edited_timestamp) {
|
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) {
|
if ('tts' in data) {
|
||||||
this.tts = data.tts;
|
this.tts = data.tts;
|
||||||
@@ -247,8 +254,8 @@ class Message {
|
|||||||
|
|
||||||
if (base && rawData) {
|
if (base && rawData) {
|
||||||
base = this.mentions.everyone === message.mentions.everyone &&
|
base = this.mentions.everyone === message.mentions.everyone &&
|
||||||
this.timestamp.getTime() === new Date(rawData.timestamp).getTime() &&
|
this._timestamp === new Date(rawData.timestamp).getTime() &&
|
||||||
this.editedTimestamp === new Date(rawData.edited_timestamp).getTime();
|
this._editedTimestamp === new Date(rawData.edited_timestamp).getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
return base;
|
return base;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const Discord = require('../');
|
|||||||
const request = require('superagent');
|
const request = require('superagent');
|
||||||
const fs = require('fs');
|
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');
|
const { email, password, token } = require('./auth.json');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user