Merge pull request #519 from Hackzzila/indev

Added nonce support to 'sendMessage'
This commit is contained in:
Amish Shah
2016-08-15 22:28:22 +01:00
committed by GitHub
4 changed files with 137 additions and 132 deletions

View File

@@ -80,6 +80,7 @@ var Client = (function (_EventEmitter) {
this.options.shardId = options.shardId || 0; this.options.shardId = options.shardId || 0;
this.options.shardCount = options.shardCount || 0; this.options.shardCount = options.shardCount || 0;
this.options.disableEveryone = options.disableEveryone || false; this.options.disableEveryone = options.disableEveryone || false;
this.options.bot = options.bot === undefined || options.bot === true ? true : false;
if (typeof options.shardCount === "number" && typeof options.shardId === "number" && options.shardCount > 0) { if (typeof options.shardCount === "number" && typeof options.shardId === "number" && options.shardCount > 0) {
this.options.shard = [options.shardId, options.shardCount]; this.options.shard = [options.shardId, options.shardCount];

View File

@@ -631,8 +631,6 @@ var InternalClient = (function () {
// email and password are optional // email and password are optional
InternalClient.prototype.loginWithToken = function loginWithToken(token, email, password) { InternalClient.prototype.loginWithToken = function loginWithToken(token, email, password) {
var _this9 = this;
this.setup(); this.setup();
this.state = _ConnectionState2["default"].LOGGED_IN; this.state = _ConnectionState2["default"].LOGGED_IN;
@@ -640,23 +638,25 @@ var InternalClient = (function () {
this.email = email; this.email = email;
this.password = password; this.password = password;
var self = this;
return this.getGateway().then(function (url) { return this.getGateway().then(function (url) {
_this9.createWS(url); self.token = self.client.options.bot && !self.token.startsWith("Bot ") ? "Bot " + self.token : self.token;
return token; self.createWS(url);
return self.token;
}); });
}; };
// def login // def login
InternalClient.prototype.login = function login(email, password) { InternalClient.prototype.login = function login(email, password) {
var _this10 = this; var _this9 = this;
var client = this.client; var client = this.client;
if (!this.tokenCacher.done) { if (!this.tokenCacher.done) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
setTimeout(function () { setTimeout(function () {
_this10.login(email, password).then(resolve)["catch"](reject); _this9.login(email, password).then(resolve)["catch"](reject);
}, 20); }, 20);
}); });
} else { } else {
@@ -677,16 +677,16 @@ var InternalClient = (function () {
email: email, email: email,
password: password password: password
}).then(function (res) { }).then(function (res) {
_this10.client.emit("debug", "direct API login, cached token was unavailable"); _this9.client.emit("debug", "direct API login, cached token was unavailable");
var token = res.token; var token = res.token;
_this10.tokenCacher.setToken(email, password, token); _this9.tokenCacher.setToken(email, password, token);
return _this10.loginWithToken(token, email, password); return _this9.loginWithToken(token, email, password);
}, function (error) { }, function (error) {
_this10.websocket = null; _this9.websocket = null;
throw error; throw error;
})["catch"](function (error) { })["catch"](function (error) {
_this10.websocket = null; _this9.websocket = null;
_this10.state = _ConnectionState2["default"].DISCONNECTED; _this9.state = _ConnectionState2["default"].DISCONNECTED;
client.emit("disconnected"); client.emit("disconnected");
throw error; throw error;
}); });
@@ -695,21 +695,21 @@ var InternalClient = (function () {
// def logout // def logout
InternalClient.prototype.logout = function logout() { InternalClient.prototype.logout = function logout() {
var _this11 = this; var _this10 = this;
if (this.state === _ConnectionState2["default"].DISCONNECTED || this.state === _ConnectionState2["default"].IDLE) { if (this.state === _ConnectionState2["default"].DISCONNECTED || this.state === _ConnectionState2["default"].IDLE) {
return Promise.reject(new Error("Client is not logged in!")); return Promise.reject(new Error("Client is not logged in!"));
} }
var disconnect = function disconnect() { var disconnect = function disconnect() {
if (_this11.websocket) { if (_this10.websocket) {
_this11.websocket.close(1000); _this10.websocket.close(1000);
_this11.websocket = null; _this10.websocket = null;
} }
_this11.token = null; _this10.token = null;
_this11.email = null; _this10.email = null;
_this11.password = null; _this10.password = null;
_this11.state = _ConnectionState2["default"].DISCONNECTED; _this10.state = _ConnectionState2["default"].DISCONNECTED;
return Promise.resolve(); return Promise.resolve();
}; };
@@ -723,7 +723,7 @@ var InternalClient = (function () {
// def startPM // def startPM
InternalClient.prototype.startPM = function startPM(resUser) { InternalClient.prototype.startPM = function startPM(resUser) {
var _this12 = this; var _this11 = this;
var user = this.resolver.resolveUser(resUser); var user = this.resolver.resolveUser(resUser);
if (!user) { if (!user) {
@@ -733,27 +733,27 @@ var InternalClient = (function () {
return this.apiRequest("post", _Constants.Endpoints.ME_CHANNELS, true, { return this.apiRequest("post", _Constants.Endpoints.ME_CHANNELS, true, {
recipient_id: user.id recipient_id: user.id
}).then(function (res) { }).then(function (res) {
return _this12.private_channels.add(new _StructuresPMChannel2["default"](res, _this12.client)); return _this11.private_channels.add(new _StructuresPMChannel2["default"](res, _this11.client));
}); });
}; };
// def getGateway // def getGateway
InternalClient.prototype.getGateway = function getGateway() { InternalClient.prototype.getGateway = function getGateway() {
var _this13 = this; var _this12 = this;
if (this.gatewayURL) { if (this.gatewayURL) {
return Promise.resolve(this.gatewayURL); return Promise.resolve(this.gatewayURL);
} }
return this.apiRequest("get", _Constants.Endpoints.GATEWAY, true).then(function (res) { return this.apiRequest("get", _Constants.Endpoints.GATEWAY, true).then(function (res) {
return _this13.gatewayURL = res.url; return _this12.gatewayURL = res.url;
}); });
}; };
// def sendMessage // def sendMessage
InternalClient.prototype.sendMessage = function sendMessage(where, _content) { InternalClient.prototype.sendMessage = function sendMessage(where, _content) {
var _this14 = this; var _this13 = this;
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
@@ -776,30 +776,32 @@ var InternalClient = (function () {
} }
return this.resolver.resolveChannel(where).then(function (destination) { return this.resolver.resolveChannel(where).then(function (destination) {
var content = _this14.resolver.resolveString(_content); var content = _this13.resolver.resolveString(_content);
if (_this14.client.options.disableEveryone || options.disableEveryone) { if (_this13.client.options.disableEveryone || options.disableEveryone) {
content = content.replace(/(@)(everyone|here)/g, "$1$2"); content = content.replace(/(@)(everyone|here)/g, "$1$2");
} }
if (options.file) { if (options.file) {
return _this14.resolver.resolveFile(options.file.file).then(function (file) { return _this13.resolver.resolveFile(options.file.file).then(function (file) {
return _this14.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(destination.id), true, { return _this13.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(destination.id), true, {
content: content, content: content,
tts: options.tts tts: options.tts,
nonce: options.nonce
}, { }, {
name: options.file.name, name: options.file.name,
file: file file: file
}).then(function (res) { }).then(function (res) {
return destination.messages.add(new _StructuresMessage2["default"](res, destination, _this14.client)); return destination.messages.add(new _StructuresMessage2["default"](res, destination, _this13.client));
}); });
}); });
} else { } else {
return _this14.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(destination.id), true, { return _this13.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(destination.id), true, {
content: content, content: content,
tts: options.tts tts: options.tts,
nonce: options.nonce
}).then(function (res) { }).then(function (res) {
return destination.messages.add(new _StructuresMessage2["default"](res, destination, _this14.client)); return destination.messages.add(new _StructuresMessage2["default"](res, destination, _this13.client));
}); });
} }
}); });
@@ -808,7 +810,7 @@ var InternalClient = (function () {
// def sendFile // def sendFile
InternalClient.prototype.sendFile = function sendFile(where, _file, name, content) { InternalClient.prototype.sendFile = function sendFile(where, _file, name, content) {
var _this15 = this; var _this14 = this;
if (!name) { if (!name) {
if (_file instanceof String || typeof _file === "string") { if (_file instanceof String || typeof _file === "string") {
@@ -831,12 +833,12 @@ var InternalClient = (function () {
} }
return this.resolver.resolveChannel(where).then(function (channel) { return this.resolver.resolveChannel(where).then(function (channel) {
return _this15.resolver.resolveFile(_file).then(function (file) { return _this14.resolver.resolveFile(_file).then(function (file) {
return _this15.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id), true, content, { return _this14.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id), true, content, {
name: name, name: name,
file: file file: file
}).then(function (res) { }).then(function (res) {
return channel.messages.add(new _StructuresMessage2["default"](res, channel, _this15.client)); return channel.messages.add(new _StructuresMessage2["default"](res, channel, _this14.client));
}); });
}); });
}); });
@@ -845,7 +847,7 @@ var InternalClient = (function () {
// def deleteMessage // def deleteMessage
InternalClient.prototype.deleteMessage = function deleteMessage(_message) { InternalClient.prototype.deleteMessage = function deleteMessage(_message) {
var _this16 = this; var _this15 = this;
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
@@ -856,7 +858,7 @@ var InternalClient = (function () {
var chain = options.wait ? delay(options.wait) : Promise.resolve(); var chain = options.wait ? delay(options.wait) : Promise.resolve();
return chain.then(function () { return chain.then(function () {
return _this16.apiRequest("del", _Constants.Endpoints.CHANNEL_MESSAGE(message.channel.id, message.id), true); return _this15.apiRequest("del", _Constants.Endpoints.CHANNEL_MESSAGE(message.channel.id, message.id), true);
}).then(function () { }).then(function () {
return message.channel.messages.remove(message); return message.channel.messages.remove(message);
}); });
@@ -912,7 +914,7 @@ var InternalClient = (function () {
// def updateMessage // def updateMessage
InternalClient.prototype.updateMessage = function updateMessage(msg, _content) { InternalClient.prototype.updateMessage = function updateMessage(msg, _content) {
var _this17 = this; var _this16 = this;
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
@@ -928,14 +930,14 @@ var InternalClient = (function () {
content: content, content: content,
tts: options.tts tts: options.tts
}).then(function (res) { }).then(function (res) {
return message.channel.messages.update(message, new _StructuresMessage2["default"](res, message.channel, _this17.client)); return message.channel.messages.update(message, new _StructuresMessage2["default"](res, message.channel, _this16.client));
}); });
}; };
// def getChannelLogs // def getChannelLogs
InternalClient.prototype.getChannelLogs = function getChannelLogs(_channel) { InternalClient.prototype.getChannelLogs = function getChannelLogs(_channel) {
var _this18 = this; var _this17 = this;
var limit = arguments.length <= 1 || arguments[1] === undefined ? 50 : arguments[1]; var limit = arguments.length <= 1 || arguments[1] === undefined ? 50 : arguments[1];
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
@@ -943,27 +945,27 @@ var InternalClient = (function () {
return this.resolver.resolveChannel(_channel).then(function (channel) { return this.resolver.resolveChannel(_channel).then(function (channel) {
var qsObject = { limit: limit }; var qsObject = { limit: limit };
if (options.before) { if (options.before) {
var res = _this18.resolver.resolveMessage(options.before); var res = _this17.resolver.resolveMessage(options.before);
if (res) { if (res) {
qsObject.before = res.id; qsObject.before = res.id;
} }
} }
if (options.after) { if (options.after) {
var res = _this18.resolver.resolveMessage(options.after); var res = _this17.resolver.resolveMessage(options.after);
if (res) { if (res) {
qsObject.after = res.id; qsObject.after = res.id;
} }
} }
if (options.around) { if (options.around) {
var res = _this18.resolver.resolveMessage(options.around); var res = _this17.resolver.resolveMessage(options.around);
if (res) { if (res) {
qsObject.around = res.id; qsObject.around = res.id;
} }
} }
return _this18.apiRequest("get", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id) + "?" + _querystring2["default"].stringify(qsObject), true).then(function (res) { return _this17.apiRequest("get", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id) + "?" + _querystring2["default"].stringify(qsObject), true).then(function (res) {
return res.map(function (msg) { return res.map(function (msg) {
return channel.messages.add(new _StructuresMessage2["default"](msg, channel, _this18.client)); return channel.messages.add(new _StructuresMessage2["default"](msg, channel, _this17.client));
}); });
}); });
}); });
@@ -972,10 +974,10 @@ var InternalClient = (function () {
// def getMessage // def getMessage
InternalClient.prototype.getMessage = function getMessage(_channel, messageID) { InternalClient.prototype.getMessage = function getMessage(_channel, messageID) {
var _this19 = this; var _this18 = this;
return this.resolver.resolveChannel(_channel).then(function (channel) { return this.resolver.resolveChannel(_channel).then(function (channel) {
if (!_this19.user.bot) { if (!_this18.user.bot) {
return Promise.reject(new Error("Only OAuth bot accounts can use this function")); return Promise.reject(new Error("Only OAuth bot accounts can use this function"));
} }
@@ -988,8 +990,8 @@ var InternalClient = (function () {
return Promise.resolve(msg); return Promise.resolve(msg);
} }
return _this19.apiRequest("get", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id) + "/" + messageID, true).then(function (res) { return _this18.apiRequest("get", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id) + "/" + messageID, true).then(function (res) {
return channel.messages.add(new _StructuresMessage2["default"](res, channel, _this19.client)); return channel.messages.add(new _StructuresMessage2["default"](res, channel, _this18.client));
}); });
}); });
}; };
@@ -1025,12 +1027,12 @@ var InternalClient = (function () {
// def getPinnedMessages // def getPinnedMessages
InternalClient.prototype.getPinnedMessages = function getPinnedMessages(_channel) { InternalClient.prototype.getPinnedMessages = function getPinnedMessages(_channel) {
var _this20 = this; var _this19 = this;
return this.resolver.resolveChannel(_channel).then(function (channel) { return this.resolver.resolveChannel(_channel).then(function (channel) {
return _this20.apiRequest("get", "" + _Constants.Endpoints.CHANNEL_PINS(channel.id), true).then(function (res) { return _this19.apiRequest("get", "" + _Constants.Endpoints.CHANNEL_PINS(channel.id), true).then(function (res) {
return res.map(function (msg) { return res.map(function (msg) {
return channel.messages.add(new _StructuresMessage2["default"](msg, channel, _this20.client)); return channel.messages.add(new _StructuresMessage2["default"](msg, channel, _this19.client));
}); });
}); });
}); });
@@ -1039,13 +1041,13 @@ var InternalClient = (function () {
// def getBans // def getBans
InternalClient.prototype.getBans = function getBans(server) { InternalClient.prototype.getBans = function getBans(server) {
var _this21 = this; var _this20 = this;
server = this.resolver.resolveServer(server); server = this.resolver.resolveServer(server);
return this.apiRequest("get", _Constants.Endpoints.SERVER_BANS(server.id), true).then(function (res) { return this.apiRequest("get", _Constants.Endpoints.SERVER_BANS(server.id), true).then(function (res) {
return res.map(function (ban) { return res.map(function (ban) {
return _this21.users.add(new _StructuresUser2["default"](ban.user, _this21.client)); return _this20.users.add(new _StructuresUser2["default"](ban.user, _this20.client));
}); });
}); });
}; };
@@ -1053,7 +1055,7 @@ var InternalClient = (function () {
// def createChannel // def createChannel
InternalClient.prototype.createChannel = function createChannel(server, name) { InternalClient.prototype.createChannel = function createChannel(server, name) {
var _this22 = this; var _this21 = this;
var type = arguments.length <= 2 || arguments[2] === undefined ? "text" : arguments[2]; var type = arguments.length <= 2 || arguments[2] === undefined ? "text" : arguments[2];
@@ -1065,26 +1067,26 @@ var InternalClient = (function () {
}).then(function (res) { }).then(function (res) {
var channel; var channel;
if (res.type === "text") { if (res.type === "text") {
channel = new _StructuresTextChannel2["default"](res, _this22.client, server); channel = new _StructuresTextChannel2["default"](res, _this21.client, server);
} else { } else {
channel = new _StructuresVoiceChannel2["default"](res, _this22.client, server); channel = new _StructuresVoiceChannel2["default"](res, _this21.client, server);
} }
return server.channels.add(_this22.channels.add(channel)); return server.channels.add(_this21.channels.add(channel));
}); });
}; };
// def deleteChannel // def deleteChannel
InternalClient.prototype.deleteChannel = function deleteChannel(_channel) { InternalClient.prototype.deleteChannel = function deleteChannel(_channel) {
var _this23 = this; var _this22 = this;
return this.resolver.resolveChannel(_channel).then(function (channel) { return this.resolver.resolveChannel(_channel).then(function (channel) {
return _this23.apiRequest("del", _Constants.Endpoints.CHANNEL(channel.id), true).then(function () { return _this22.apiRequest("del", _Constants.Endpoints.CHANNEL(channel.id), true).then(function () {
if (channel.server) { if (channel.server) {
channel.server.channels.remove(channel); channel.server.channels.remove(channel);
_this23.channels.remove(channel); _this22.channels.remove(channel);
} else { } else {
_this23.private_channels.remove(channel); _this22.private_channels.remove(channel);
} }
}); });
}); });
@@ -1123,7 +1125,7 @@ var InternalClient = (function () {
// def moveMember // def moveMember
InternalClient.prototype.moveMember = function moveMember(user, channel) { InternalClient.prototype.moveMember = function moveMember(user, channel) {
var _this24 = this; var _this23 = this;
user = this.resolver.resolveUser(user); user = this.resolver.resolveUser(user);
return this.resolver.resolveChannel(channel).then(function (channel) { return this.resolver.resolveChannel(channel).then(function (channel) {
@@ -1133,7 +1135,7 @@ var InternalClient = (function () {
if (channel.type !== "voice") { if (channel.type !== "voice") {
throw new Error("Can't moveMember into a non-voice channel"); throw new Error("Can't moveMember into a non-voice channel");
} else { } else {
return _this24.apiRequest("patch", _Constants.Endpoints.SERVER_MEMBERS(server.id) + "/" + user.id, true, { channel_id: channel.id }).then(function (res) { return _this23.apiRequest("patch", _Constants.Endpoints.SERVER_MEMBERS(server.id) + "/" + user.id, true, { channel_id: channel.id }).then(function (res) {
user.voiceChannel = channel; user.voiceChannel = channel;
return res; return res;
}); });
@@ -1198,15 +1200,15 @@ var InternalClient = (function () {
// def createRole // def createRole
InternalClient.prototype.createRole = function createRole(server, data) { InternalClient.prototype.createRole = function createRole(server, data) {
var _this25 = this; var _this24 = this;
server = this.resolver.resolveServer(server); server = this.resolver.resolveServer(server);
return this.apiRequest("post", _Constants.Endpoints.SERVER_ROLES(server.id), true).then(function (res) { return this.apiRequest("post", _Constants.Endpoints.SERVER_ROLES(server.id), true).then(function (res) {
var role = server.roles.add(new _StructuresRole2["default"](res, server, _this25.client)); var role = server.roles.add(new _StructuresRole2["default"](res, server, _this24.client));
if (data) { if (data) {
return _this25.updateRole(role, data); return _this24.updateRole(role, data);
} }
return role; return role;
}); });
@@ -1215,7 +1217,7 @@ var InternalClient = (function () {
// def updateRole // def updateRole
InternalClient.prototype.updateRole = function updateRole(role, data) { InternalClient.prototype.updateRole = function updateRole(role, data) {
var _this26 = this; var _this25 = this;
role = this.resolver.resolveRole(role); role = this.resolver.resolveRole(role);
var server = this.resolver.resolveServer(role.server); var server = this.resolver.resolveServer(role.server);
@@ -1254,7 +1256,7 @@ var InternalClient = (function () {
} }
return this.apiRequest("patch", _Constants.Endpoints.SERVER_ROLES(server.id) + "/" + role.id, true, newData).then(function (res) { return this.apiRequest("patch", _Constants.Endpoints.SERVER_ROLES(server.id) + "/" + role.id, true, newData).then(function (res) {
return server.roles.update(role, new _StructuresRole2["default"](res, server, _this26.client)); return server.roles.update(role, new _StructuresRole2["default"](res, server, _this25.client));
}); });
}; };
@@ -1271,7 +1273,7 @@ var InternalClient = (function () {
//def addMemberToRole //def addMemberToRole
InternalClient.prototype.addMemberToRole = function addMemberToRole(member, roles) { InternalClient.prototype.addMemberToRole = function addMemberToRole(member, roles) {
var _this27 = this; var _this26 = this;
member = this.resolver.resolveUser(member); member = this.resolver.resolveUser(member);
@@ -1288,7 +1290,7 @@ var InternalClient = (function () {
} }
} else { } else {
roles = roles.map(function (r) { roles = roles.map(function (r) {
return _this27.resolver.resolveRole(r); return _this26.resolver.resolveRole(r);
}); });
} }
@@ -1351,7 +1353,7 @@ var InternalClient = (function () {
//def removeMemberFromRole //def removeMemberFromRole
InternalClient.prototype.removeMemberFromRole = function removeMemberFromRole(member, roles) { InternalClient.prototype.removeMemberFromRole = function removeMemberFromRole(member, roles) {
var _this28 = this; var _this27 = this;
member = this.resolver.resolveUser(member); member = this.resolver.resolveUser(member);
@@ -1368,7 +1370,7 @@ var InternalClient = (function () {
} }
} else { } else {
roles = roles.map(function (r) { roles = roles.map(function (r) {
return _this28.resolver.resolveRole(r); return _this27.resolver.resolveRole(r);
}); });
} }
@@ -1409,7 +1411,7 @@ var InternalClient = (function () {
// def createInvite // def createInvite
InternalClient.prototype.createInvite = function createInvite(chanServ, options) { InternalClient.prototype.createInvite = function createInvite(chanServ, options) {
var _this29 = this; var _this28 = this;
return this.resolver.resolveChannel(chanServ).then(function (channel) { return this.resolver.resolveChannel(chanServ).then(function (channel) {
if (!options) { if (!options) {
@@ -1423,8 +1425,8 @@ var InternalClient = (function () {
options.xkcdpass = options.xkcd || false; options.xkcdpass = options.xkcd || false;
} }
return _this29.apiRequest("post", _Constants.Endpoints.CHANNEL_INVITES(channel.id), true, options).then(function (res) { return _this28.apiRequest("post", _Constants.Endpoints.CHANNEL_INVITES(channel.id), true, options).then(function (res) {
return new _StructuresInvite2["default"](res, _this29.channels.get("id", res.channel.id), _this29.client); return new _StructuresInvite2["default"](res, _this28.channels.get("id", res.channel.id), _this28.client);
}); });
}); });
}; };
@@ -1442,7 +1444,7 @@ var InternalClient = (function () {
//def getInvite //def getInvite
InternalClient.prototype.getInvite = function getInvite(invite) { InternalClient.prototype.getInvite = function getInvite(invite) {
var _this30 = this; var _this29 = this;
invite = this.resolver.resolveInviteID(invite); invite = this.resolver.resolveInviteID(invite);
if (!invite) { if (!invite) {
@@ -1450,11 +1452,11 @@ var InternalClient = (function () {
} }
return this.apiRequest("get", _Constants.Endpoints.INVITE(invite), true).then(function (res) { return this.apiRequest("get", _Constants.Endpoints.INVITE(invite), true).then(function (res) {
if (!_this30.channels.has("id", res.channel.id)) { if (!_this29.channels.has("id", res.channel.id)) {
return new _StructuresInvite2["default"](res, null, _this30.client); return new _StructuresInvite2["default"](res, null, _this29.client);
} }
return _this30.apiRequest("post", _Constants.Endpoints.CHANNEL_INVITES(res.channel.id), true, { validate: invite }).then(function (res2) { return _this29.apiRequest("post", _Constants.Endpoints.CHANNEL_INVITES(res.channel.id), true, { validate: invite }).then(function (res2) {
return new _StructuresInvite2["default"](res2, _this30.channels.get("id", res.channel.id), _this30.client); return new _StructuresInvite2["default"](res2, _this29.channels.get("id", res.channel.id), _this29.client);
}); });
}); });
}; };
@@ -1462,22 +1464,22 @@ var InternalClient = (function () {
//def getInvites //def getInvites
InternalClient.prototype.getInvites = function getInvites(channel) { InternalClient.prototype.getInvites = function getInvites(channel) {
var _this31 = this; var _this30 = this;
if (!(channel instanceof _StructuresChannel2["default"])) { if (!(channel instanceof _StructuresChannel2["default"])) {
var server = this.resolver.resolveServer(channel); var server = this.resolver.resolveServer(channel);
if (server) { if (server) {
return this.apiRequest("get", _Constants.Endpoints.SERVER_INVITES(server.id), true).then(function (res) { return this.apiRequest("get", _Constants.Endpoints.SERVER_INVITES(server.id), true).then(function (res) {
return res.map(function (data) { return res.map(function (data) {
return new _StructuresInvite2["default"](data, _this31.channels.get("id", data.channel.id), _this31.client); return new _StructuresInvite2["default"](data, _this30.channels.get("id", data.channel.id), _this30.client);
}); });
}); });
} }
} }
return this.resolver.resolveChannel(channel).then(function (channel) { return this.resolver.resolveChannel(channel).then(function (channel) {
return _this31.apiRequest("get", _Constants.Endpoints.CHANNEL_INVITES(channel.id), true).then(function (res) { return _this30.apiRequest("get", _Constants.Endpoints.CHANNEL_INVITES(channel.id), true).then(function (res) {
return res.map(function (data) { return res.map(function (data) {
return new _StructuresInvite2["default"](data, _this31.channels.get("id", data.channel.id), _this31.client); return new _StructuresInvite2["default"](data, _this30.channels.get("id", data.channel.id), _this30.client);
}); });
}); });
}); });
@@ -1486,7 +1488,7 @@ var InternalClient = (function () {
//def overwritePermissions //def overwritePermissions
InternalClient.prototype.overwritePermissions = function overwritePermissions(channel, role, updated) { InternalClient.prototype.overwritePermissions = function overwritePermissions(channel, role, updated) {
var _this32 = this; var _this31 = this;
return this.resolver.resolveChannel(channel).then(function (channel) { return this.resolver.resolveChannel(channel).then(function (channel) {
if (!channel instanceof _StructuresServerChannel2["default"]) { if (!channel instanceof _StructuresServerChannel2["default"]) {
@@ -1499,7 +1501,7 @@ var InternalClient = (function () {
}; };
if (role instanceof String || typeof role === "string") { if (role instanceof String || typeof role === "string") {
role = _this32.resolver.resolveUser(role) || _this32.resolver.resolveRole(role); role = _this31.resolver.resolveUser(role) || _this31.resolver.resolveRole(role);
} }
if (role instanceof _StructuresUser2["default"]) { if (role instanceof _StructuresUser2["default"]) {
@@ -1532,7 +1534,7 @@ var InternalClient = (function () {
} }
} }
return _this32.apiRequest("put", _Constants.Endpoints.CHANNEL_PERMISSIONS(channel.id) + "/" + data.id, true, data); return _this31.apiRequest("put", _Constants.Endpoints.CHANNEL_PERMISSIONS(channel.id) + "/" + data.id, true, data);
}); });
}; };
@@ -1572,49 +1574,49 @@ var InternalClient = (function () {
//def sendTyping //def sendTyping
InternalClient.prototype.sendTyping = function sendTyping(channel) { InternalClient.prototype.sendTyping = function sendTyping(channel) {
var _this33 = this; var _this32 = this;
return this.resolver.resolveChannel(channel).then(function (channel) { return this.resolver.resolveChannel(channel).then(function (channel) {
return _this33.apiRequest("post", _Constants.Endpoints.CHANNEL(channel.id) + "/typing", true); return _this32.apiRequest("post", _Constants.Endpoints.CHANNEL(channel.id) + "/typing", true);
}); });
}; };
//def startTyping //def startTyping
InternalClient.prototype.startTyping = function startTyping(channel) { InternalClient.prototype.startTyping = function startTyping(channel) {
var _this34 = this; var _this33 = this;
return this.resolver.resolveChannel(channel).then(function (channel) { return this.resolver.resolveChannel(channel).then(function (channel) {
if (_this34.intervals.typing[channel.id]) { if (_this33.intervals.typing[channel.id]) {
// typing interval already exists, leave it alone // typing interval already exists, leave it alone
throw new Error("Already typing in that channel"); throw new Error("Already typing in that channel");
} }
_this34.intervals.typing[channel.id] = setInterval(function () { _this33.intervals.typing[channel.id] = setInterval(function () {
return _this34.sendTyping(channel)["catch"](function (error) { return _this33.sendTyping(channel)["catch"](function (error) {
return _this34.emit("error", error); return _this33.emit("error", error);
}); });
}, 4000); }, 4000);
return _this34.sendTyping(channel); return _this33.sendTyping(channel);
}); });
}; };
//def stopTyping //def stopTyping
InternalClient.prototype.stopTyping = function stopTyping(channel) { InternalClient.prototype.stopTyping = function stopTyping(channel) {
var _this35 = this; var _this34 = this;
return this.resolver.resolveChannel(channel).then(function (channel) { return this.resolver.resolveChannel(channel).then(function (channel) {
if (!_this35.intervals.typing[channel.id]) { if (!_this34.intervals.typing[channel.id]) {
// typing interval doesn"t exist // typing interval doesn"t exist
throw new Error("Not typing in that channel"); throw new Error("Not typing in that channel");
} }
clearInterval(_this35.intervals.typing[channel.id]); clearInterval(_this34.intervals.typing[channel.id]);
_this35.intervals.typing[channel.id] = false; _this34.intervals.typing[channel.id] = false;
}); });
}; };
@@ -1696,7 +1698,7 @@ var InternalClient = (function () {
//def updateChannel //def updateChannel
InternalClient.prototype.updateChannel = function updateChannel(channel, data) { InternalClient.prototype.updateChannel = function updateChannel(channel, data) {
var _this36 = this; var _this35 = this;
return this.resolver.resolveChannel(channel).then(function (channel) { return this.resolver.resolveChannel(channel).then(function (channel) {
if (!channel) { if (!channel) {
@@ -1727,7 +1729,7 @@ var InternalClient = (function () {
data.bitrate *= 1000; // convert to bits before sending data.bitrate *= 1000; // convert to bits before sending
} }
return _this36.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, data).then(function (res) { return _this35.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, data).then(function (res) {
channel.name = data.name; channel.name = data.name;
channel.topic = data.topic; channel.topic = data.topic;
channel.position = data.position; channel.position = data.position;
@@ -1791,7 +1793,7 @@ var InternalClient = (function () {
}; };
InternalClient.prototype.createWS = function createWS(url) { InternalClient.prototype.createWS = function createWS(url) {
var _this37 = this; var _this36 = this;
var self = this; var self = this;
var client = self.client; var client = self.client;
@@ -1846,7 +1848,7 @@ var InternalClient = (function () {
}if (event.code === 4006 || event.code === 4009) { }if (event.code === 4006 || event.code === 4009) {
err = new Error("Invalid session"); err = new Error("Invalid session");
} else if (event.code === 4007) { } else if (event.code === 4007) {
_this37.seq = 0; _this36.seq = 0;
err = new Error("Invalid sequence number"); err = new Error("Invalid sequence number");
} else if (event.code === 4008) { } else if (event.code === 4008) {
err = new Error("Gateway connection was ratelimited"); err = new Error("Gateway connection was ratelimited");
@@ -1857,14 +1859,14 @@ var InternalClient = (function () {
client.emit("error", err); client.emit("error", err);
} }
} }
self.disconnected(_this37.client.options.autoReconnect); self.disconnected(_this36.client.options.autoReconnect);
}; };
this.websocket.onerror = function (e) { this.websocket.onerror = function (e) {
client.emit("error", e); client.emit("error", e);
self.websocket = null; self.websocket = null;
self.state = _ConnectionState2["default"].DISCONNECTED; self.state = _ConnectionState2["default"].DISCONNECTED;
self.disconnected(_this37.client.options.autoReconnect); self.disconnected(_this36.client.options.autoReconnect);
}; };
this.websocket.onmessage = function (e) { this.websocket.onmessage = function (e) {
@@ -1893,11 +1895,11 @@ var InternalClient = (function () {
self.user = self.users.add(new _StructuresUser2["default"](data.user, client)); self.user = self.users.add(new _StructuresUser2["default"](data.user, client));
_this37.forceFetchCount = {}; _this36.forceFetchCount = {};
_this37.forceFetchQueue = []; _this36.forceFetchQueue = [];
_this37.forceFetchLength = 1; _this36.forceFetchLength = 1;
_this37.autoReconnectInterval = 1000; _this36.autoReconnectInterval = 1000;
_this37.sessionID = data.session_id; _this36.sessionID = data.session_id;
data.guilds.forEach(function (server) { data.guilds.forEach(function (server) {
if (!server.unavailable) { if (!server.unavailable) {
@@ -2362,7 +2364,7 @@ var InternalClient = (function () {
data.id = data.id || user.id; data.id = data.id || user.id;
data.avatar = data.avatar || user.avatar; data.avatar = data.avatar || user.avatar;
data.discriminator = data.discriminator || user.discriminator; data.discriminator = data.discriminator || user.discriminator;
_this37.email = data.email || _this37.email; _this36.email = data.email || _this36.email;
var presenceUser = new _StructuresUser2["default"](data, client); var presenceUser = new _StructuresUser2["default"](data, client);
@@ -2420,7 +2422,7 @@ var InternalClient = (function () {
} }
break; break;
case _Constants.PacketType.USER_NOTE_UPDATE: case _Constants.PacketType.USER_NOTE_UPDATE:
if (_this37.user.bot) { if (_this36.user.bot) {
return; return;
} }
var user = self.users.get("id", data.id); var user = self.users.get("id", data.id);
@@ -2524,7 +2526,7 @@ var InternalClient = (function () {
break; break;
case _Constants.PacketType.FRIEND_ADD: case _Constants.PacketType.FRIEND_ADD:
if (_this37.user.bot) { if (_this36.user.bot) {
return; return;
} }
if (data.type === 1) { if (data.type === 1) {
@@ -2555,7 +2557,7 @@ var InternalClient = (function () {
} }
break; break;
case _Constants.PacketType.FRIEND_REMOVE: case _Constants.PacketType.FRIEND_REMOVE:
if (_this37.user.bot) { if (_this36.user.bot) {
return; return;
} }
var user = self.friends.get("id", data.id); var user = self.friends.get("id", data.id);

View File

@@ -6,23 +6,23 @@ exports.__esModule = true;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var TokenCacher = (function () { var TokenCacher = (function () {
function TokenCacher() { function TokenCacher() {
_classCallCheck(this, TokenCacher); _classCallCheck(this, TokenCacher);
} }
TokenCacher.prototype.setToken = function setToken() {}; TokenCacher.prototype.setToken = function setToken() {};
TokenCacher.prototype.save = function save() {}; TokenCacher.prototype.save = function save() {};
TokenCacher.prototype.getToken = function getToken() { TokenCacher.prototype.getToken = function getToken() {
return null; return null;
}; };
TokenCacher.prototype.init = function init(ind) { TokenCacher.prototype.init = function init(ind) {
this.done = true; this.done = true;
}; };
return TokenCacher; return TokenCacher;
})(); })();
exports["default"] = TokenCacher; exports["default"] = TokenCacher;

View File

@@ -658,7 +658,8 @@ export default class InternalClient {
.then(file => .then(file =>
this.apiRequest("post", Endpoints.CHANNEL_MESSAGES(destination.id), true, { this.apiRequest("post", Endpoints.CHANNEL_MESSAGES(destination.id), true, {
content: content, content: content,
tts: options.tts tts: options.tts,
nonce: options.nonce
}, { }, {
name: options.file.name, name: options.file.name,
file: file file: file
@@ -667,7 +668,8 @@ export default class InternalClient {
} else { } else {
return this.apiRequest("post", Endpoints.CHANNEL_MESSAGES(destination.id), true, { return this.apiRequest("post", Endpoints.CHANNEL_MESSAGES(destination.id), true, {
content: content, content: content,
tts: options.tts tts: options.tts,
nonce: options.nonce
}) })
.then(res => destination.messages.add(new Message(res, destination, this.client))); .then(res => destination.messages.add(new Message(res, destination, this.client)));
} }