mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Fixed compiled version
Downgraded babel until a working solution found
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
"use strict"
|
||||
"use strict";
|
||||
/* global Buffer */
|
||||
|
||||
;
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var fs = require("fs");
|
||||
@@ -27,254 +23,215 @@ var Resolver = (function () {
|
||||
this.internal = internal;
|
||||
}
|
||||
|
||||
_createClass(Resolver, [{
|
||||
key: "resolveGameID",
|
||||
value: function resolveGameID(resource) {
|
||||
if (!isNaN(resource) && parseInt(resource) % 1 === 0) {
|
||||
return resource;
|
||||
} else if (typeof resource == "string" || resource instanceof String) {
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
|
||||
for (var _iterator = Games[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var game = _step.value;
|
||||
|
||||
if (game.name.toUpperCase() === resource.toUpperCase()) {
|
||||
return game.id;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}, {
|
||||
key: "resolveToBase64",
|
||||
value: function resolveToBase64(resource) {
|
||||
if (resource instanceof Buffer) {
|
||||
resource = resource.toString("base64");
|
||||
resource = "data:image/jpg;base64," + resource;
|
||||
}
|
||||
Resolver.prototype.resolveGameID = function resolveGameID(resource) {
|
||||
if (!isNaN(resource) && parseInt(resource) % 1 === 0) {
|
||||
return resource;
|
||||
}
|
||||
}, {
|
||||
key: "resolveInviteID",
|
||||
value: function resolveInviteID(resource) {
|
||||
if (resource instanceof Invite) {
|
||||
return resource.id;
|
||||
} else if (typeof resource == "string" || resource instanceof String) {
|
||||
} else if (typeof resource == "string" || resource instanceof String) {
|
||||
|
||||
if (resource.indexOf("http") === 0) {
|
||||
var split = resource.split("/");
|
||||
return split.pop();
|
||||
for (var _iterator = Games, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
return resource;
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var game = _ref;
|
||||
|
||||
if (game.name.toUpperCase() === resource.toUpperCase()) {
|
||||
return game.id;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}, {
|
||||
key: "resolveServer",
|
||||
value: function resolveServer(resource) {
|
||||
if (resource instanceof Server) {
|
||||
return resource;
|
||||
} else if (resource instanceof ServerChannel) {
|
||||
return resource.server;
|
||||
} else if (resource instanceof String || typeof resource === "string") {
|
||||
return this.internal.servers.get("id", resource);
|
||||
} else if (resource instanceof Message) {
|
||||
if (resource.channel instanceof TextChannel) {
|
||||
return resource.server;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveToBase64 = function resolveToBase64(resource) {
|
||||
if (resource instanceof Buffer) {
|
||||
resource = resource.toString("base64");
|
||||
resource = "data:image/jpg;base64," + resource;
|
||||
}
|
||||
}, {
|
||||
key: "resolveFile",
|
||||
value: function resolveFile(resource) {
|
||||
if (typeof resource === "string" || resource instanceof String) {
|
||||
return fs.createReadStream(resource);
|
||||
return resource;
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveInviteID = function resolveInviteID(resource) {
|
||||
if (resource instanceof Invite) {
|
||||
return resource.id;
|
||||
} else if (typeof resource == "string" || resource instanceof String) {
|
||||
|
||||
if (resource.indexOf("http") === 0) {
|
||||
var split = resource.split("/");
|
||||
return split.pop();
|
||||
} else {
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "resolveMentions",
|
||||
value: function resolveMentions(resource) {
|
||||
// resource is a string
|
||||
var _mentions = [];
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
return null;
|
||||
};
|
||||
|
||||
try {
|
||||
for (var _iterator2 = (resource.match(/<@[^>]*>/g) || [])[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
var mention = _step2.value;
|
||||
Resolver.prototype.resolveServer = function resolveServer(resource) {
|
||||
if (resource instanceof Server) {
|
||||
return resource;
|
||||
} else if (resource instanceof ServerChannel) {
|
||||
return resource.server;
|
||||
} else if (resource instanceof String || typeof resource === "string") {
|
||||
return this.internal.servers.get("id", resource);
|
||||
} else if (resource instanceof Message) {
|
||||
if (resource.channel instanceof TextChannel) {
|
||||
return resource.server;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
_mentions.push(mention.substring(2, mention.length - 1));
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
||||
_iterator2.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
Resolver.prototype.resolveFile = function resolveFile(resource) {
|
||||
if (typeof resource === "string" || resource instanceof String) {
|
||||
return fs.createReadStream(resource);
|
||||
} else {
|
||||
return resource;
|
||||
}
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveMentions = function resolveMentions(resource) {
|
||||
// resource is a string
|
||||
var _mentions = [];
|
||||
for (var _iterator2 = resource.match(/<@[^>]*>/g) || [], _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
return _mentions;
|
||||
var mention = _ref2;
|
||||
|
||||
_mentions.push(mention.substring(2, mention.length - 1));
|
||||
}
|
||||
}, {
|
||||
key: "resolveString",
|
||||
value: function resolveString(resource) {
|
||||
return _mentions;
|
||||
};
|
||||
|
||||
// accepts Array, Channel, Server, User, Message, String and anything
|
||||
// toString()-able
|
||||
Resolver.prototype.resolveString = function resolveString(resource) {
|
||||
|
||||
var final = resource;
|
||||
if (resource instanceof Array) {
|
||||
final = resource.join("\n");
|
||||
// accepts Array, Channel, Server, User, Message, String and anything
|
||||
// toString()-able
|
||||
|
||||
var final = resource;
|
||||
if (resource instanceof Array) {
|
||||
final = resource.join("\n");
|
||||
}
|
||||
|
||||
return final.toString();
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveUser = function resolveUser(resource) {
|
||||
/*
|
||||
accepts a Message, Channel, Server, String ID, User, PMChannel
|
||||
*/
|
||||
var found = null;
|
||||
if (resource instanceof User) {
|
||||
found = resource;
|
||||
} else if (resource instanceof Message) {
|
||||
found = resource.author;
|
||||
} else if (resource instanceof TextChannel) {
|
||||
var lmsg = resource.lastMessage;
|
||||
if (lmsg) {
|
||||
found = lmsg.author;
|
||||
}
|
||||
|
||||
return final.toString();
|
||||
} else if (resource instanceof Server) {
|
||||
found = resource.owner;
|
||||
} else if (resource instanceof PMChannel) {
|
||||
found = resource.recipient;
|
||||
} else if (resource instanceof String || typeof resource === "string") {
|
||||
found = this.client.internal.users.get("id", resource);
|
||||
}
|
||||
}, {
|
||||
key: "resolveUser",
|
||||
value: function resolveUser(resource) {
|
||||
/*
|
||||
accepts a Message, Channel, Server, String ID, User, PMChannel
|
||||
|
||||
return found;
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveMessage = function resolveMessage(resource) {
|
||||
// accepts a Message, PMChannel & TextChannel
|
||||
var found = null;
|
||||
|
||||
if (resource instanceof TextChannel || resource instanceof PMChannel) {
|
||||
found = resource.lastMessage;
|
||||
} else if (resource instanceof Message) {
|
||||
found = resource;
|
||||
}
|
||||
|
||||
return found;
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveVoiceChannel = function resolveVoiceChannel(resource) {
|
||||
// resolveChannel will also work but this is more apt
|
||||
if (resource instanceof VoiceChannel) {
|
||||
return resource;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveChannel = function resolveChannel(resource) {
|
||||
/*
|
||||
accepts a Message, Channel, Server, String ID, User
|
||||
*/
|
||||
var self = this;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
var found = null;
|
||||
if (resource instanceof User) {
|
||||
if (resource instanceof Message) {
|
||||
found = resource.channel;
|
||||
} else if (resource instanceof Channel) {
|
||||
found = resource;
|
||||
} else if (resource instanceof Message) {
|
||||
found = resource.author;
|
||||
} else if (resource instanceof TextChannel) {
|
||||
var lmsg = resource.lastMessage;
|
||||
if (lmsg) {
|
||||
found = lmsg.author;
|
||||
}
|
||||
} else if (resource instanceof Server) {
|
||||
found = resource.owner;
|
||||
} else if (resource instanceof PMChannel) {
|
||||
found = resource.recipient;
|
||||
found = resource.channels.get("id", resource.id);
|
||||
} else if (resource instanceof String || typeof resource === "string") {
|
||||
found = this.client.internal.users.get("id", resource);
|
||||
}
|
||||
found = self.internal.channels.get("id", resource);
|
||||
} else if (resource instanceof User) {
|
||||
// see if a PM exists
|
||||
var chatFound = false;
|
||||
for (var _iterator3 = self.internal.private_channels, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
||||
var _ref3;
|
||||
|
||||
return found;
|
||||
}
|
||||
}, {
|
||||
key: "resolveMessage",
|
||||
value: function resolveMessage(resource) {
|
||||
// accepts a Message, PMChannel & TextChannel
|
||||
var found = null;
|
||||
|
||||
if (resource instanceof TextChannel || resource instanceof PMChannel) {
|
||||
found = resource.lastMessage;
|
||||
} else if (resource instanceof Message) {
|
||||
found = resource;
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
}, {
|
||||
key: "resolveVoiceChannel",
|
||||
value: function resolveVoiceChannel(resource) {
|
||||
// resolveChannel will also work but this is more apt
|
||||
if (resource instanceof VoiceChannel) {
|
||||
return resource;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}, {
|
||||
key: "resolveChannel",
|
||||
value: function resolveChannel(resource) {
|
||||
/*
|
||||
accepts a Message, Channel, Server, String ID, User
|
||||
*/
|
||||
var self = this;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
var found = null;
|
||||
if (resource instanceof Message) {
|
||||
found = resource.channel;
|
||||
} else if (resource instanceof Channel) {
|
||||
found = resource;
|
||||
} else if (resource instanceof Server) {
|
||||
found = resource.channels.get("id", resource.id);
|
||||
} else if (resource instanceof String || typeof resource === "string") {
|
||||
found = self.internal.channels.get("id", resource);
|
||||
} else if (resource instanceof User) {
|
||||
// see if a PM exists
|
||||
var chatFound = false;
|
||||
var _iteratorNormalCompletion3 = true;
|
||||
var _didIteratorError3 = false;
|
||||
var _iteratorError3 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator3 = self.internal.private_channels[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
||||
var pmchat = _step3.value;
|
||||
|
||||
if (pmchat.recipient.equals(resource)) {
|
||||
chatFound = pmchat;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError3 = true;
|
||||
_iteratorError3 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
||||
_iterator3.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError3) {
|
||||
throw _iteratorError3;
|
||||
}
|
||||
}
|
||||
if (_isArray3) {
|
||||
if (_i3 >= _iterator3.length) break;
|
||||
_ref3 = _iterator3[_i3++];
|
||||
} else {
|
||||
_i3 = _iterator3.next();
|
||||
if (_i3.done) break;
|
||||
_ref3 = _i3.value;
|
||||
}
|
||||
|
||||
if (chatFound) {
|
||||
// a PM already exists!
|
||||
found = chatFound;
|
||||
} else {
|
||||
// PM does not exist :\
|
||||
self.internal.startPM(resource).then(function (pmchannel) {
|
||||
return resolve(pmchannel);
|
||||
}).catch(function (e) {
|
||||
return reject(e);
|
||||
});
|
||||
return;
|
||||
var pmchat = _ref3;
|
||||
|
||||
if (pmchat.recipient.equals(resource)) {
|
||||
chatFound = pmchat;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) resolve(found);else reject(new Error("Didn't found anything"));
|
||||
});
|
||||
}
|
||||
}]);
|
||||
if (chatFound) {
|
||||
// a PM already exists!
|
||||
found = chatFound;
|
||||
} else {
|
||||
// PM does not exist :\
|
||||
self.internal.startPM(resource).then(function (pmchannel) {
|
||||
return resolve(pmchannel);
|
||||
})["catch"](function (e) {
|
||||
return reject(e);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (found) resolve(found);else reject(new Error("Didn't found anything"));
|
||||
});
|
||||
};
|
||||
|
||||
return Resolver;
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user