From c9497a0f750c8e96d194182fd4d967bd61e1be31 Mon Sep 17 00:00:00 2001 From: abalabahaha Date: Sun, 22 Nov 2015 17:15:49 -0800 Subject: [PATCH] Emit -ed and fixed presence vs. userUpdated check --- lib/Client/Client.js | 2 +- lib/Client/ConnectionState.js | 2 +- lib/Client/InternalClient.js | 10 +++++----- lib/Client/Resolver/Resolver.js | 2 +- lib/Constants.js | 2 +- lib/Structures/Channel.js | 2 +- lib/Structures/ChannelPermissions.js | 2 +- lib/Structures/Invite.js | 2 +- lib/Structures/Message.js | 2 +- lib/Structures/PMChannel.js | 2 +- lib/Structures/PermissionOverwrite.js | 2 +- lib/Structures/Role.js | 2 +- lib/Structures/Server.js | 2 +- lib/Structures/ServerChannel.js | 2 +- lib/Structures/TextChannel.js | 2 +- lib/Structures/User.js | 6 +++++- lib/Structures/VoiceChannel.js | 2 +- lib/Util/ArgumentRegulariser.js | 2 +- lib/Util/Cache.js | 2 +- lib/Util/Equality.js | 2 +- lib/Voice/AudioEncoder.js | 2 +- lib/Voice/StreamIntent.js | 2 +- lib/Voice/VoiceConnection.js | 2 +- lib/Voice/VoicePacket.js | 2 +- lib/index.js | 2 +- src/Client/InternalClient.js | 8 ++++---- src/Structures/User.js | 12 ++++++++++++ 27 files changed, 49 insertions(+), 33 deletions(-) diff --git a/lib/Client/Client.js b/lib/Client/Client.js index 3d407da7f..5bf5fb03b 100644 --- a/lib/Client/Client.js +++ b/lib/Client/Client.js @@ -933,4 +933,4 @@ var Client = (function (_EventEmitter) { return Client; })(EventEmitter); -module.exports = Client; \ No newline at end of file +module.exports = Client; diff --git a/lib/Client/ConnectionState.js b/lib/Client/ConnectionState.js index 86fb95261..e0585d77e 100644 --- a/lib/Client/ConnectionState.js +++ b/lib/Client/ConnectionState.js @@ -4,4 +4,4 @@ exports.IDLE = 0; exports.LOGGING_IN = 1; exports.LOGGED_IN = 2; exports.READY = 3; -exports.DISCONNECTED = 4; \ No newline at end of file +exports.DISCONNECTED = 4; diff --git a/lib/Client/InternalClient.js b/lib/Client/InternalClient.js index e3673eb14..4d9e5c9f9 100644 --- a/lib/Client/InternalClient.js +++ b/lib/Client/InternalClient.js @@ -1556,14 +1556,14 @@ var InternalClient = (function () { var presenceUser = new User(data.user, client); - if (presenceUser.equalsStrict(user)) { + if (presenceUser.equals(user)) { // a real presence update client.emit("presence", user, data.status, data.game_id); user.status = data.status; user.gameID = data.game_id; } else { // a name change or avatar change - client.emit("userUpdate", user, presenceUser); + client.emit("userUpdated", user, presenceUser); self.users.update(user, presenceUser); } } else { @@ -1583,14 +1583,14 @@ var InternalClient = (function () { } else { user.typing.since = Date.now(); user.typing.channel = channel; - client.emit("userTypingStart", user, channel); + client.emit("userTypingStarted", user, channel); } setTimeout(function () { if (Date.now() - user.typing.since > 5500) { // they haven't typed since user.typing.since = null; user.typing.channel = null; - client.emit("userTypingStop", user, channel); + client.emit("userTypingStopped", user, channel); } }, 6000); } else { @@ -1631,4 +1631,4 @@ var InternalClient = (function () { return InternalClient; })(); -module.exports = InternalClient; \ No newline at end of file +module.exports = InternalClient; diff --git a/lib/Client/Resolver/Resolver.js b/lib/Client/Resolver/Resolver.js index ed23d92f7..b6edf95de 100644 --- a/lib/Client/Resolver/Resolver.js +++ b/lib/Client/Resolver/Resolver.js @@ -236,4 +236,4 @@ var Resolver = (function () { return Resolver; })(); -module.exports = Resolver; \ No newline at end of file +module.exports = Resolver; diff --git a/lib/Constants.js b/lib/Constants.js index 572f3c8f2..bd03f3260 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -127,4 +127,4 @@ var PacketType = { exports.API_ENDPOINT = API; exports.Endpoints = Endpoints; exports.PacketType = PacketType; -exports.Permissions = Permissions; \ No newline at end of file +exports.Permissions = Permissions; diff --git a/lib/Structures/Channel.js b/lib/Structures/Channel.js index 93d222f13..395c14552 100644 --- a/lib/Structures/Channel.js +++ b/lib/Structures/Channel.js @@ -36,4 +36,4 @@ var Channel = (function (_Equality) { return Channel; })(Equality); -module.exports = Channel; \ No newline at end of file +module.exports = Channel; diff --git a/lib/Structures/ChannelPermissions.js b/lib/Structures/ChannelPermissions.js index fe7a039fd..0c1b29e93 100644 --- a/lib/Structures/ChannelPermissions.js +++ b/lib/Structures/ChannelPermissions.js @@ -72,4 +72,4 @@ var ChannelPermissions = (function () { return ChannelPermissions; })(); -module.exports = ChannelPermissions; \ No newline at end of file +module.exports = ChannelPermissions; diff --git a/lib/Structures/Invite.js b/lib/Structures/Invite.js index 04a125d23..5471c534c 100644 --- a/lib/Structures/Invite.js +++ b/lib/Structures/Invite.js @@ -29,4 +29,4 @@ var Invite = (function () { return Invite; })(); -module.exports = Invite; \ No newline at end of file +module.exports = Invite; diff --git a/lib/Structures/Message.js b/lib/Structures/Message.js index d61295506..6564f2844 100644 --- a/lib/Structures/Message.js +++ b/lib/Structures/Message.js @@ -84,4 +84,4 @@ var Message = (function (_Equality) { return Message; })(Equality); -module.exports = Message; \ No newline at end of file +module.exports = Message; diff --git a/lib/Structures/PMChannel.js b/lib/Structures/PMChannel.js index 3f0404241..b2bb2aa3f 100644 --- a/lib/Structures/PMChannel.js +++ b/lib/Structures/PMChannel.js @@ -50,4 +50,4 @@ var PMChannel = (function (_Channel) { return PMChannel; })(Channel); -module.exports = PMChannel; \ No newline at end of file +module.exports = PMChannel; diff --git a/lib/Structures/PermissionOverwrite.js b/lib/Structures/PermissionOverwrite.js index f20d61b7a..99f82bc0b 100644 --- a/lib/Structures/PermissionOverwrite.js +++ b/lib/Structures/PermissionOverwrite.js @@ -83,4 +83,4 @@ var PermissionOverwrite = (function () { return PermissionOverwrite; })(); -module.exports = PermissionOverwrite; \ No newline at end of file +module.exports = PermissionOverwrite; diff --git a/lib/Structures/Role.js b/lib/Structures/Role.js index 048c183cb..21e0f2b88 100644 --- a/lib/Structures/Role.js +++ b/lib/Structures/Role.js @@ -136,4 +136,4 @@ var Role = (function () { return Role; })(); -module.exports = Role; \ No newline at end of file +module.exports = Role; diff --git a/lib/Structures/Server.js b/lib/Structures/Server.js index 99ee3971a..a43875b2b 100644 --- a/lib/Structures/Server.js +++ b/lib/Structures/Server.js @@ -166,4 +166,4 @@ var Server = (function (_Equality) { return Server; })(Equality); -module.exports = Server; \ No newline at end of file +module.exports = Server; diff --git a/lib/Structures/ServerChannel.js b/lib/Structures/ServerChannel.js index 0349d33f9..1e0fdae96 100644 --- a/lib/Structures/ServerChannel.js +++ b/lib/Structures/ServerChannel.js @@ -114,4 +114,4 @@ var ServerChannel = (function (_Channel) { return ServerChannel; })(Channel); -module.exports = ServerChannel; \ No newline at end of file +module.exports = ServerChannel; diff --git a/lib/Structures/TextChannel.js b/lib/Structures/TextChannel.js index 181d20354..5868bed13 100644 --- a/lib/Structures/TextChannel.js +++ b/lib/Structures/TextChannel.js @@ -55,4 +55,4 @@ var TextChannel = (function (_ServerChannel) { return TextChannel; })(ServerChannel); -module.exports = TextChannel; \ No newline at end of file +module.exports = TextChannel; diff --git a/lib/Structures/User.js b/lib/Structures/User.js index 3815089ee..bd9fd5469 100644 --- a/lib/Structures/User.js +++ b/lib/Structures/User.js @@ -41,6 +41,10 @@ var User = (function (_Equality) { if (obj instanceof User) return this.id === obj.id && this.username === obj.username && this.discriminator === obj.discriminator && this.avatar === obj.avatar && this.status === obj.status && this.gameID === obj.gameID;else return false; }; + User.prototype.equals = function equals(obj) { + if (obj instanceof User) return this.id === obj.id && this.username === obj.username && this.discriminator === obj.discriminator && this.avatar === obj.avatar;else return false; + }; + _createClass(User, [{ key: "avatarURL", get: function get() { @@ -55,4 +59,4 @@ var User = (function (_Equality) { return User; })(Equality); -module.exports = User; \ No newline at end of file +module.exports = User; diff --git a/lib/Structures/VoiceChannel.js b/lib/Structures/VoiceChannel.js index 333786b58..b61a9082e 100644 --- a/lib/Structures/VoiceChannel.js +++ b/lib/Structures/VoiceChannel.js @@ -18,4 +18,4 @@ var VoiceChannel = (function (_ServerChannel) { return VoiceChannel; })(ServerChannel); -module.exports = VoiceChannel; \ No newline at end of file +module.exports = VoiceChannel; diff --git a/lib/Util/ArgumentRegulariser.js b/lib/Util/ArgumentRegulariser.js index 9c98ddb39..1ffbee29a 100644 --- a/lib/Util/ArgumentRegulariser.js +++ b/lib/Util/ArgumentRegulariser.js @@ -2,4 +2,4 @@ exports.reg = function (c, a) { return [c].concat(Array.prototype.slice.call(a)); -}; \ No newline at end of file +}; diff --git a/lib/Util/Cache.js b/lib/Util/Cache.js index a5d978624..e8ddfe890 100644 --- a/lib/Util/Cache.js +++ b/lib/Util/Cache.js @@ -103,4 +103,4 @@ var Cache = (function (_Array) { return Cache; })(Array); -module.exports = Cache; \ No newline at end of file +module.exports = Cache; diff --git a/lib/Util/Equality.js b/lib/Util/Equality.js index 3288d530a..dd5763f74 100644 --- a/lib/Util/Equality.js +++ b/lib/Util/Equality.js @@ -42,4 +42,4 @@ var Equality = (function () { return Equality; })(); -module.exports = Equality; \ No newline at end of file +module.exports = Equality; diff --git a/lib/Voice/AudioEncoder.js b/lib/Voice/AudioEncoder.js index 517a7cf68..f178f9e2b 100644 --- a/lib/Voice/AudioEncoder.js +++ b/lib/Voice/AudioEncoder.js @@ -126,4 +126,4 @@ var AudioEncoder = (function () { return AudioEncoder; })(); -module.exports = AudioEncoder; \ No newline at end of file +module.exports = AudioEncoder; diff --git a/lib/Voice/StreamIntent.js b/lib/Voice/StreamIntent.js index 97953194c..aa6bb38c4 100644 --- a/lib/Voice/StreamIntent.js +++ b/lib/Voice/StreamIntent.js @@ -19,4 +19,4 @@ var StreamIntent = (function (_EventEmitter) { return StreamIntent; })(EventEmitter); -module.exports = StreamIntent; \ No newline at end of file +module.exports = StreamIntent; diff --git a/lib/Voice/VoiceConnection.js b/lib/Voice/VoiceConnection.js index 9af846704..c89cba4c6 100644 --- a/lib/Voice/VoiceConnection.js +++ b/lib/Voice/VoiceConnection.js @@ -330,4 +330,4 @@ var VoiceConnection = (function (_EventEmitter) { return VoiceConnection; })(EventEmitter); -module.exports = VoiceConnection; \ No newline at end of file +module.exports = VoiceConnection; diff --git a/lib/Voice/VoicePacket.js b/lib/Voice/VoicePacket.js index 8fa32d5f6..88bbe3b08 100644 --- a/lib/Voice/VoicePacket.js +++ b/lib/Voice/VoicePacket.js @@ -23,4 +23,4 @@ var VoicePacket = function VoicePacket(data, sequence, time, ssrc) { return returnBuffer; }; -module.exports = VoicePacket; \ No newline at end of file +module.exports = VoicePacket; diff --git a/lib/index.js b/lib/index.js index 29c9cc6a3..c7f00139b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -15,4 +15,4 @@ module.exports = { User: require("./Structures/User"), VoiceChannel: require("./Structures/VoiceChannel"), Constants: require("./Constants.js") -}; \ No newline at end of file +}; diff --git a/src/Client/InternalClient.js b/src/Client/InternalClient.js index ad5db7423..0d51d6789 100644 --- a/src/Client/InternalClient.js +++ b/src/Client/InternalClient.js @@ -1627,7 +1627,7 @@ class InternalClient { var presenceUser = new User(data.user, client); - if (presenceUser.equalsStrict(user)) { + if (presenceUser.equals(user)) { // a real presence update client.emit("presence", user, data.status, data.game_id); user.status = data.status; @@ -1635,7 +1635,7 @@ class InternalClient { } else { // a name change or avatar change - client.emit("userUpdate", user, presenceUser); + client.emit("userUpdated", user, presenceUser); self.users.update(user, presenceUser); } @@ -1656,14 +1656,14 @@ class InternalClient { } else { user.typing.since = Date.now(); user.typing.channel = channel; - client.emit("userTypingStart", user, channel); + client.emit("userTypingStarted", user, channel); } setTimeout(() => { if (Date.now() - user.typing.since > 5500) { // they haven't typed since user.typing.since = null; user.typing.channel = null; - client.emit("userTypingStop", user, channel); + client.emit("userTypingStopped", user, channel); } }, 6000); diff --git a/src/Structures/User.js b/src/Structures/User.js index c1be841e2..35cecdff0 100644 --- a/src/Structures/User.js +++ b/src/Structures/User.js @@ -48,6 +48,18 @@ class User extends Equality{ else return false; } + + equals(obj){ + if(obj instanceof User) + return ( + this.id === obj.id && + this.username === obj.username && + this.discriminator === obj.discriminator && + this.avatar === obj.avatar + ); + else + return false; + } } module.exports = User; \ No newline at end of file