Add more @readonly and clean up some stuff

This commit is contained in:
Schuyler Cebulskie
2016-09-27 20:07:33 -04:00
parent 1a3f5ca6a9
commit 973dbe8266
11 changed files with 31 additions and 21 deletions

File diff suppressed because one or more lines are too long

View File

@@ -157,8 +157,8 @@ class Client extends EventEmitter {
/** /**
* The status for the logged in Client. * The status for the logged in Client.
* @readonly
* @type {?number} * @type {?number}
* @readonly
*/ */
get status() { get status() {
return this.ws.status; return this.ws.status;
@@ -166,8 +166,8 @@ class Client extends EventEmitter {
/** /**
* The uptime for the logged in Client. * The uptime for the logged in Client.
* @readonly
* @type {?number} * @type {?number}
* @readonly
*/ */
get uptime() { get uptime() {
return this.readyTime ? Date.now() - this.readyTime : null; return this.readyTime ? Date.now() - this.readyTime : null;
@@ -175,8 +175,8 @@ class Client extends EventEmitter {
/** /**
* Returns a Collection, mapping Guild ID to Voice Connections. * Returns a Collection, mapping Guild ID to Voice Connections.
* @readonly
* @type {Collection<string, VoiceConnection>} * @type {Collection<string, VoiceConnection>}
* @readonly
*/ */
get voiceConnections() { get voiceConnections() {
return this.voice.connections; return this.voice.connections;

View File

@@ -16,6 +16,7 @@ class ShardClientUtil {
/** /**
* ID of this shard * ID of this shard
* @type {number} * @type {number}
* @readonly
*/ */
get id() { get id() {
return this.client.options.shardId; return this.client.options.shardId;
@@ -24,6 +25,7 @@ class ShardClientUtil {
/** /**
* Total number of shards * Total number of shards
* @type {number} * @type {number}
* @readonly
*/ */
get count() { get count() {
return this.client.options.shardCount; return this.client.options.shardCount;

View File

@@ -148,19 +148,13 @@ class ClientUser extends User {
if (data.game) { if (data.game) {
game = data.game; game = data.game;
if (game.url) { if (game.url) game.type = 1;
game.type = 1;
}
}
if (typeof data.afk !== 'undefined') {
afk = data.afk;
} }
if (typeof data.afk !== 'undefined') afk = data.afk;
afk = Boolean(afk); afk = Boolean(afk);
this.localPresence = { status, game, afk }; this.localPresence = { status, game, afk };
this.localPresence.since = 0; this.localPresence.since = 0;
this.client.ws.send({ this.client.ws.send({

View File

@@ -80,6 +80,7 @@ class GroupDMChannel extends Channel {
/** /**
* The owner of this Group DM. * The owner of this Group DM.
* @type {User} * @type {User}
* @readonly
*/ */
get owner() { get owner() {
return this.client.users.get(this.ownerID); return this.client.users.get(this.ownerID);

View File

@@ -59,14 +59,6 @@ class Guild {
} }
} }
_setPresence(id, presence) {
if (this.presences.get(id)) {
this.presences.get(id).update(presence);
return;
}
this.presences.set(id, new Presence(presence));
}
/** /**
* Sets up the Guild * Sets up the Guild
* @param {*} data The raw data of the guild * @param {*} data The raw data of the guild
@@ -754,6 +746,14 @@ class Guild {
} }
} }
_setPresence(id, presence) {
if (this.presences.get(id)) {
this.presences.get(id).update(presence);
return;
}
this.presences.set(id, new Presence(presence));
}
_checkChunks() { _checkChunks() {
if (this._fetchWaiter) { if (this._fetchWaiter) {
if (this.members.size === this.memberCount) { if (this.members.size === this.memberCount) {

View File

@@ -132,6 +132,7 @@ class GuildMember {
/** /**
* The role of the member with the highest position. * The role of the member with the highest position.
* @type {Role} * @type {Role}
* @readonly
*/ */
get highestRole() { get highestRole() {
return this.roles.reduce((prev, role) => return this.roles.reduce((prev, role) =>
@@ -178,6 +179,7 @@ class GuildMember {
/** /**
* The overall set of permissions for the guild member, taking only roles into account * The overall set of permissions for the guild member, taking only roles into account
* @type {EvaluatedPermissions} * @type {EvaluatedPermissions}
* @readonly
*/ */
get permissions() { get permissions() {
if (this.user.id === this.guild.ownerID) return new EvaluatedPermissions(this, Constants.ALL_PERMISSIONS); if (this.user.id === this.guild.ownerID) return new EvaluatedPermissions(this, Constants.ALL_PERMISSIONS);
@@ -195,6 +197,7 @@ class GuildMember {
/** /**
* Whether the member is kickable by the client user. * Whether the member is kickable by the client user.
* @type {boolean} * @type {boolean}
* @readonly
*/ */
get kickable() { get kickable() {
if (this.user.id === this.guild.ownerID) return false; if (this.user.id === this.guild.ownerID) return false;
@@ -207,6 +210,7 @@ class GuildMember {
/** /**
* Whether the member is bannable by the client user. * Whether the member is bannable by the client user.
* @type {boolean} * @type {boolean}
* @readonly
*/ */
get bannable() { get bannable() {
if (this.user.id === this.guild.ownerID) return false; if (this.user.id === this.guild.ownerID) return false;

View File

@@ -215,6 +215,7 @@ class Message {
/** /**
* The guild the message was sent in (if in a guild channel) * The guild the message was sent in (if in a guild channel)
* @type {?Guild} * @type {?Guild}
* @readonly
*/ */
get guild() { get guild() {
return this.channel.guild || null; return this.channel.guild || null;
@@ -224,6 +225,7 @@ class Message {
* The message contents with all mentions replaced by the equivalent text. If mentions cannot be resolved to a name, * The message contents with all mentions replaced by the equivalent text. If mentions cannot be resolved to a name,
* the relevant mention in the message content will not be converted. * the relevant mention in the message content will not be converted.
* @type {string} * @type {string}
* @readonly
*/ */
get cleanContent() { get cleanContent() {
return this.content return this.content
@@ -262,6 +264,7 @@ class Message {
* An array of cached versions of the message, including the current version. * An array of cached versions of the message, including the current version.
* Sorted from latest (first) to oldest (last). * Sorted from latest (first) to oldest (last).
* @type {Message[]} * @type {Message[]}
* @readonly
*/ */
get edits() { get edits() {
return this._edits.slice().unshift(this); return this._edits.slice().unshift(this);
@@ -270,6 +273,7 @@ class Message {
/** /**
* Whether the message is editable by the client user. * Whether the message is editable by the client user.
* @type {boolean} * @type {boolean}
* @readonly
*/ */
get editable() { get editable() {
return this.author.id === this.client.user.id; return this.author.id === this.client.user.id;
@@ -278,6 +282,7 @@ class Message {
/** /**
* Whether the message is deletable by the client user. * Whether the message is deletable by the client user.
* @type {boolean} * @type {boolean}
* @readonly
*/ */
get deletable() { get deletable() {
return this.author.id === this.client.user.id || (this.guild && return this.author.id === this.client.user.id || (this.guild &&
@@ -288,6 +293,7 @@ class Message {
/** /**
* Whether the message is pinnable by the client user. * Whether the message is pinnable by the client user.
* @type {boolean} * @type {boolean}
* @readonly
*/ */
get pinnable() { get pinnable() {
return !this.guild || return !this.guild ||

View File

@@ -103,6 +103,7 @@ class Role {
/** /**
* The cached guild members that have this role. * The cached guild members that have this role.
* @type {Collection<string, GuildMember>} * @type {Collection<string, GuildMember>}
* @readonly
*/ */
get members() { get members() {
return this.guild.members.filter(m => m.roles.has(this.id)); return this.guild.members.filter(m => m.roles.has(this.id));

View File

@@ -76,8 +76,8 @@ class User {
/** /**
* The presence of this user * The presence of this user
* @readonly
* @type {Presence} * @type {Presence}
* @readonly
*/ */
get presence() { get presence() {
if (this.client.presences.has(this.id)) return this.client.presences.get(this.id); if (this.client.presences.has(this.id)) return this.client.presences.get(this.id);

View File

@@ -241,6 +241,7 @@ class TextBasedChannel {
/** /**
* Whether or not the typing indicator is being shown in the channel. * Whether or not the typing indicator is being shown in the channel.
* @type {boolean} * @type {boolean}
* @readonly
*/ */
get typing() { get typing() {
return this.client.user._typing.has(this.id); return this.client.user._typing.has(this.id);
@@ -249,6 +250,7 @@ class TextBasedChannel {
/** /**
* Number of times `startTyping` has been called. * Number of times `startTyping` has been called.
* @type {number} * @type {number}
* @readonly
*/ */
get typingCount() { get typingCount() {
if (this.client.user._typing.has(this.id)) return this.client.user._typing.get(this.id).count; if (this.client.user._typing.has(this.id)) return this.client.user._typing.get(this.id).count;