From e7df5bd400408fbd1c6fdb563ab12148f8378d5d Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Wed, 18 Nov 2015 16:59:37 +0000 Subject: [PATCH] Built internal changes --- .vscode/settings.json | 5 +++- lib/Client/Client.js | 2 +- lib/Client/ConnectionState.js | 2 +- lib/Client/InternalClient.js | 30 +++++++++++++++++++++- lib/Client/Resolver/Resolver.js | 20 +++++++++++++-- lib/Constants.js | 5 +++- lib/Structures/Channel.js | 2 +- lib/Structures/ChannelPermissions.js | 2 +- lib/Structures/Invite.js | 36 +++++++++++++-------------- 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 | 2 +- lib/Structures/VoiceChannel.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 +- 25 files changed, 93 insertions(+), 43 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 81c4b4351..74edbd872 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,2 +1,5 @@ // Place your settings in this file to overwrite default and user settings. -{ "editor.wrappingColumn": 0 } \ No newline at end of file +{ + "editor.wrappingColumn": 0, + "editor.formatOnType": true +} \ No newline at end of file diff --git a/lib/Client/Client.js b/lib/Client/Client.js index 3decf989a..c01a4b58b 100644 --- a/lib/Client/Client.js +++ b/lib/Client/Client.js @@ -682,4 +682,4 @@ var Client = (function (_EventEmitter) { return Client; })(EventEmitter); -module.exports = Client; +module.exports = Client; \ No newline at end of file diff --git a/lib/Client/ConnectionState.js b/lib/Client/ConnectionState.js index e0585d77e..86fb95261 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; +exports.DISCONNECTED = 4; \ No newline at end of file diff --git a/lib/Client/InternalClient.js b/lib/Client/InternalClient.js index c0acc7a66..12be1c6b5 100644 --- a/lib/Client/InternalClient.js +++ b/lib/Client/InternalClient.js @@ -142,6 +142,34 @@ var InternalClient = (function () { }); }; + //def joinServer + + InternalClient.prototype.joinServer = function joinServer(invite) { + var self = this; + return new Promise(function (resolve, reject) { + + invite = self.resolver.resolveInvite(invite); + if (invite) { + + request.post(Endpoints.INVITE(invite.id)).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + // valid server, wait until it is received via ws and cached + var inter = setInterval(function () { + if (self.servers.get("id", res.body.guild.id)) { + clearInterval(inter); + resolve(self.servers.get("id", res.body.guild.id)); + } + }, 20); + } + }); + } else { + reject(new Error("Not a valid invite")); + } + }); + }; + //def leaveServer InternalClient.prototype.leaveServer = function leaveServer(srv) { @@ -1459,4 +1487,4 @@ var InternalClient = (function () { return InternalClient; })(); -module.exports = InternalClient; +module.exports = InternalClient; \ No newline at end of file diff --git a/lib/Client/Resolver/Resolver.js b/lib/Client/Resolver/Resolver.js index 5463bb5ad..01f367490 100644 --- a/lib/Client/Resolver/Resolver.js +++ b/lib/Client/Resolver/Resolver.js @@ -11,7 +11,8 @@ var User = require("../../Structures/User.js"), ServerChannel = require("../../Structures/ServerChannel.js"), PMChannel = require("../../Structures/PMChannel.js"), Server = require("../../Structures/Server.js"), - Message = require("../../Structures/Message.js"); + Message = require("../../Structures/Message.js"), + Invite = require("../../Structures/Invite.js"); var Resolver = (function () { function Resolver(internal) { @@ -20,6 +21,21 @@ var Resolver = (function () { this.internal = internal; } + Resolver.prototype.resolveInvite = function resolveInvite(resource) { + if (resource instanceof Invite) { + return resource; + } else if (typeof resource == "string" || resource instanceof String) { + + if (resource.indexOf("http") === 0) { + var split = resource.split("/"); + return split.pop(); + } else { + return resource; + } + } + return null; + }; + Resolver.prototype.resolveServer = function resolveServer(resource) { if (resource instanceof Server) { return resource; @@ -182,4 +198,4 @@ var Resolver = (function () { return Resolver; })(); -module.exports = Resolver; +module.exports = Resolver; \ No newline at end of file diff --git a/lib/Constants.js b/lib/Constants.js index 1b341a0b6..572f3c8f2 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -13,6 +13,9 @@ var Endpoints = { AVATAR: function AVATAR(userID, avatar) { return API + "/users/" + userID + "/avatars/" + avatar + ".jpg"; }, + INVITE: function INVITE(id) { + return API + "/invite/" + id; + }, // servers SERVERS: API + "/guilds", @@ -124,4 +127,4 @@ var PacketType = { exports.API_ENDPOINT = API; exports.Endpoints = Endpoints; exports.PacketType = PacketType; -exports.Permissions = Permissions; +exports.Permissions = Permissions; \ No newline at end of file diff --git a/lib/Structures/Channel.js b/lib/Structures/Channel.js index 1e84d0e96..053bc38ca 100644 --- a/lib/Structures/Channel.js +++ b/lib/Structures/Channel.js @@ -27,4 +27,4 @@ var Channel = (function (_Equality) { return Channel; })(Equality); -module.exports = Channel; +module.exports = Channel; \ No newline at end of file diff --git a/lib/Structures/ChannelPermissions.js b/lib/Structures/ChannelPermissions.js index 0c1b29e93..fe7a039fd 100644 --- a/lib/Structures/ChannelPermissions.js +++ b/lib/Structures/ChannelPermissions.js @@ -72,4 +72,4 @@ var ChannelPermissions = (function () { return ChannelPermissions; })(); -module.exports = ChannelPermissions; +module.exports = ChannelPermissions; \ No newline at end of file diff --git a/lib/Structures/Invite.js b/lib/Structures/Invite.js index 04a125d23..c003ff1dc 100644 --- a/lib/Structures/Invite.js +++ b/lib/Structures/Invite.js @@ -6,27 +6,27 @@ var Server = require("./Server.js"); var ServerChannel = require("./ServerChannel.js"); var Invite = (function () { - function Invite(data, chan, client) { - _classCallCheck(this, Invite); + function Invite(data, chan, client) { + _classCallCheck(this, Invite); - this.maxAge = data.max_age; - this.code = data.code; - this.server = chan.server; - this.channel = chan; - this.revoked = data.revoked; - this.createdAt = Date.parse(data.created_at); - this.temporary = data.temporary; - this.uses = data.uses; - this.maxUses = data.uses; - this.inviter = client.internal.users.get("id", data.inviter.id); - this.xkcd = data.xkcdpass; - } + this.maxAge = data.max_age; + this.code = data.code; + this.server = chan.server; + this.channel = chan; + this.revoked = data.revoked; + this.createdAt = Date.parse(data.created_at); + this.temporary = data.temporary; + this.uses = data.uses; + this.maxUses = data.uses; + this.inviter = client.internal.users.get("id", data.inviter.id); + this.xkcd = data.xkcdpass; + } - Invite.prototype.toString = function toString() { - return "https://discord.gg/" + this.code; - }; + Invite.prototype.toString = function toString() { + return "https://discord.gg/" + this.code; + }; - return Invite; + return Invite; })(); module.exports = Invite; \ No newline at end of file diff --git a/lib/Structures/Message.js b/lib/Structures/Message.js index 73a963741..c1a4ff19d 100644 --- a/lib/Structures/Message.js +++ b/lib/Structures/Message.js @@ -60,4 +60,4 @@ var Message = (function () { return Message; })(); -module.exports = Message; +module.exports = Message; \ No newline at end of file diff --git a/lib/Structures/PMChannel.js b/lib/Structures/PMChannel.js index 5b10a68f3..837c4a378 100644 --- a/lib/Structures/PMChannel.js +++ b/lib/Structures/PMChannel.js @@ -52,4 +52,4 @@ var PMChannel = (function (_Equality) { return PMChannel; })(Equality); -module.exports = PMChannel; +module.exports = PMChannel; \ No newline at end of file diff --git a/lib/Structures/PermissionOverwrite.js b/lib/Structures/PermissionOverwrite.js index 99f82bc0b..f20d61b7a 100644 --- a/lib/Structures/PermissionOverwrite.js +++ b/lib/Structures/PermissionOverwrite.js @@ -83,4 +83,4 @@ var PermissionOverwrite = (function () { return PermissionOverwrite; })(); -module.exports = PermissionOverwrite; +module.exports = PermissionOverwrite; \ No newline at end of file diff --git a/lib/Structures/Role.js b/lib/Structures/Role.js index 21e0f2b88..048c183cb 100644 --- a/lib/Structures/Role.js +++ b/lib/Structures/Role.js @@ -136,4 +136,4 @@ var Role = (function () { return Role; })(); -module.exports = Role; +module.exports = Role; \ No newline at end of file diff --git a/lib/Structures/Server.js b/lib/Structures/Server.js index 1ef9f1cac..7d7320e70 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; +module.exports = Server; \ No newline at end of file diff --git a/lib/Structures/ServerChannel.js b/lib/Structures/ServerChannel.js index dbb697050..29e626f88 100644 --- a/lib/Structures/ServerChannel.js +++ b/lib/Structures/ServerChannel.js @@ -110,4 +110,4 @@ var ServerChannel = (function (_Channel) { return ServerChannel; })(Channel); -module.exports = ServerChannel; +module.exports = ServerChannel; \ No newline at end of file diff --git a/lib/Structures/TextChannel.js b/lib/Structures/TextChannel.js index 08ba7bf28..6e7a8a664 100644 --- a/lib/Structures/TextChannel.js +++ b/lib/Structures/TextChannel.js @@ -57,4 +57,4 @@ var TextChannel = (function (_ServerChannel) { return TextChannel; })(ServerChannel); -module.exports = TextChannel; +module.exports = TextChannel; \ No newline at end of file diff --git a/lib/Structures/User.js b/lib/Structures/User.js index 12260a051..3815089ee 100644 --- a/lib/Structures/User.js +++ b/lib/Structures/User.js @@ -55,4 +55,4 @@ var User = (function (_Equality) { return User; })(Equality); -module.exports = User; +module.exports = User; \ No newline at end of file diff --git a/lib/Structures/VoiceChannel.js b/lib/Structures/VoiceChannel.js index b61a9082e..333786b58 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; +module.exports = VoiceChannel; \ No newline at end of file diff --git a/lib/Util/Cache.js b/lib/Util/Cache.js index b08c517f4..fbe4c5853 100644 --- a/lib/Util/Cache.js +++ b/lib/Util/Cache.js @@ -95,4 +95,4 @@ var Cache = (function (_Array) { return Cache; })(Array); -module.exports = Cache; +module.exports = Cache; \ No newline at end of file diff --git a/lib/Util/Equality.js b/lib/Util/Equality.js index dd5763f74..3288d530a 100644 --- a/lib/Util/Equality.js +++ b/lib/Util/Equality.js @@ -42,4 +42,4 @@ var Equality = (function () { return Equality; })(); -module.exports = Equality; +module.exports = Equality; \ No newline at end of file diff --git a/lib/Voice/AudioEncoder.js b/lib/Voice/AudioEncoder.js index f178f9e2b..517a7cf68 100644 --- a/lib/Voice/AudioEncoder.js +++ b/lib/Voice/AudioEncoder.js @@ -126,4 +126,4 @@ var AudioEncoder = (function () { return AudioEncoder; })(); -module.exports = AudioEncoder; +module.exports = AudioEncoder; \ No newline at end of file diff --git a/lib/Voice/StreamIntent.js b/lib/Voice/StreamIntent.js index aa6bb38c4..97953194c 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; +module.exports = StreamIntent; \ No newline at end of file diff --git a/lib/Voice/VoiceConnection.js b/lib/Voice/VoiceConnection.js index f61b002f6..4dee53b15 100644 --- a/lib/Voice/VoiceConnection.js +++ b/lib/Voice/VoiceConnection.js @@ -329,4 +329,4 @@ var VoiceConnection = (function (_EventEmitter) { return VoiceConnection; })(EventEmitter); -module.exports = VoiceConnection; +module.exports = VoiceConnection; \ No newline at end of file diff --git a/lib/Voice/VoicePacket.js b/lib/Voice/VoicePacket.js index 46797646a..f432bf241 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; +module.exports = VoicePacket; \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index b122e469d..31c91c19c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -14,4 +14,4 @@ module.exports = { TextChannel: require("./Structures/TextChannel"), User: require("./Structures/User"), VoiceChannel: require("./Structures/VoiceChannel") -}; +}; \ No newline at end of file