mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
Simplified awaitResponse
This commit is contained in:
@@ -807,19 +807,54 @@ var Client = (function (_EventEmitter) {
|
||||
// def awaitResponse
|
||||
|
||||
Client.prototype.awaitResponse = function awaitResponse(msg) {
|
||||
var toSend = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
|
||||
|
||||
var _this = this;
|
||||
|
||||
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (e, newMsg) {} : arguments[1];
|
||||
var options = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];
|
||||
var callback = arguments.length <= 3 || arguments[3] === undefined ? function (e, newMsg) {} : arguments[3];
|
||||
|
||||
var self = this;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
_this.internal.awaitResponse(msg).then(function (newMsg) {
|
||||
resolve(newMsg);
|
||||
callback(null, newMsg);
|
||||
})["catch"](function (e) {
|
||||
function error(e) {
|
||||
callback(e);
|
||||
reject(e);
|
||||
});
|
||||
}
|
||||
|
||||
if (toSend) {
|
||||
if (typeof toSend === "function") {
|
||||
// (msg, callback)
|
||||
callback = toSend;
|
||||
final();
|
||||
} else {
|
||||
// (msg, toSend, ...)
|
||||
if (options) {
|
||||
if (typeof options === "function") {
|
||||
//(msg, toSend, callback)
|
||||
callback = options;
|
||||
_this.sendMessage(msg, toSend).then(final)["catch"](error);
|
||||
} else {
|
||||
//(msg, toSend, options, callback)
|
||||
_this.sendMessage(msg, toSend, options).then(final)["catch"](error);
|
||||
}
|
||||
} else {
|
||||
// (msg, toSend) promise
|
||||
_this.sendMessage(msg, toSend).then(final)["catch"](error);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// (msg) promise
|
||||
final();
|
||||
}
|
||||
|
||||
function final() {
|
||||
self.internal.awaitResponse(msg).then(function (newMsg) {
|
||||
resolve(newMsg);
|
||||
callback(null, newMsg);
|
||||
})["catch"](error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user