mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 12:33:30 +01:00
Resolve role IDs
This commit is contained in:
@@ -751,6 +751,7 @@ var InternalClient = (function () {
|
|||||||
InternalClient.prototype.updateRole = function updateRole(role, data) {
|
InternalClient.prototype.updateRole = function updateRole(role, data) {
|
||||||
var _this22 = this;
|
var _this22 = this;
|
||||||
|
|
||||||
|
role = this.resolver.resolveRole(role);
|
||||||
var server = this.resolver.resolveServer(role.server);
|
var server = this.resolver.resolveServer(role.server);
|
||||||
|
|
||||||
var newData = {
|
var newData = {
|
||||||
@@ -798,6 +799,8 @@ var InternalClient = (function () {
|
|||||||
//def addMemberToRole
|
//def addMemberToRole
|
||||||
|
|
||||||
InternalClient.prototype.addMemberToRole = function addMemberToRole(member, roles) {
|
InternalClient.prototype.addMemberToRole = function addMemberToRole(member, roles) {
|
||||||
|
var _this23 = this;
|
||||||
|
|
||||||
member = this.resolver.resolveUser(member);
|
member = this.resolver.resolveUser(member);
|
||||||
|
|
||||||
if (!member) {
|
if (!member) {
|
||||||
@@ -805,11 +808,16 @@ var InternalClient = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!Array.isArray(roles) || roles.length === 0) {
|
if (!Array.isArray(roles) || roles.length === 0) {
|
||||||
if (roles instanceof _StructuresRole2["default"]) {
|
roles = this.resolve.resolveRole(roles);
|
||||||
|
if (roles) {
|
||||||
roles = [roles];
|
roles = [roles];
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject(new Error("invalid array of roles"));
|
return Promise.reject(new Error("invalid array of roles"));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
roles = roles.map(function (r) {
|
||||||
|
return _this23.resolver.resolveRole(r);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (roles.some(function (role) {
|
if (roles.some(function (role) {
|
||||||
@@ -834,8 +842,12 @@ var InternalClient = (function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
InternalClient.prototype.memberHasRole = function memberHasRole(member, role) {
|
InternalClient.prototype.memberHasRole = function memberHasRole(member, role) {
|
||||||
|
role = this.resolver.resolveRole(role);
|
||||||
member = this.resolver.resolveUser(member);
|
member = this.resolver.resolveUser(member);
|
||||||
|
|
||||||
|
if (!role) {
|
||||||
|
throw new Error("invalid role");
|
||||||
|
}
|
||||||
if (!member) {
|
if (!member) {
|
||||||
throw new Error("user not found");
|
throw new Error("user not found");
|
||||||
}
|
}
|
||||||
@@ -848,6 +860,8 @@ var InternalClient = (function () {
|
|||||||
//def removeMemberFromRole
|
//def removeMemberFromRole
|
||||||
|
|
||||||
InternalClient.prototype.removeMemberFromRole = function removeMemberFromRole(member, roles) {
|
InternalClient.prototype.removeMemberFromRole = function removeMemberFromRole(member, roles) {
|
||||||
|
var _this24 = this;
|
||||||
|
|
||||||
member = this.resolver.resolveUser(member);
|
member = this.resolver.resolveUser(member);
|
||||||
|
|
||||||
if (!member) {
|
if (!member) {
|
||||||
@@ -855,11 +869,16 @@ var InternalClient = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!Array.isArray(roles) || roles.length === 0) {
|
if (!Array.isArray(roles) || roles.length === 0) {
|
||||||
if (roles instanceof _StructuresRole2["default"]) {
|
roles = this.resolve.resolveRole(roles);
|
||||||
|
if (roles) {
|
||||||
roles = [roles];
|
roles = [roles];
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject(new Error("invalid array of roles"));
|
return Promise.reject(new Error("invalid array of roles"));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
roles = roles.map(function (r) {
|
||||||
|
return _this24.resolver.resolveRole(r);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var roleIDS = roles[0].server.memberMap[member.id].roles.map(function (r) {
|
var roleIDS = roles[0].server.memberMap[member.id].roles.map(function (r) {
|
||||||
@@ -899,7 +918,7 @@ var InternalClient = (function () {
|
|||||||
// def createInvite
|
// def createInvite
|
||||||
|
|
||||||
InternalClient.prototype.createInvite = function createInvite(chanServ, options) {
|
InternalClient.prototype.createInvite = function createInvite(chanServ, options) {
|
||||||
var _this23 = this;
|
var _this25 = this;
|
||||||
|
|
||||||
if (chanServ instanceof _StructuresChannel2["default"]) {
|
if (chanServ instanceof _StructuresChannel2["default"]) {
|
||||||
// do something
|
// do something
|
||||||
@@ -932,7 +951,7 @@ var InternalClient = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return this.apiRequest("post", epoint, true, options).then(function (res) {
|
return this.apiRequest("post", epoint, true, options).then(function (res) {
|
||||||
return new _StructuresInvite2["default"](res, _this23.channels.get("id", res.channel.id), _this23.client);
|
return new _StructuresInvite2["default"](res, _this25.channels.get("id", res.channel.id), _this25.client);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -949,7 +968,7 @@ var InternalClient = (function () {
|
|||||||
//def getInvite
|
//def getInvite
|
||||||
|
|
||||||
InternalClient.prototype.getInvite = function getInvite(invite) {
|
InternalClient.prototype.getInvite = function getInvite(invite) {
|
||||||
var _this24 = this;
|
var _this26 = this;
|
||||||
|
|
||||||
invite = this.resolver.resolveInviteID(invite);
|
invite = this.resolver.resolveInviteID(invite);
|
||||||
if (!invite) {
|
if (!invite) {
|
||||||
@@ -957,11 +976,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 (!_this24.channels.has("id", res.channel.id)) {
|
if (!_this26.channels.has("id", res.channel.id)) {
|
||||||
return new _StructuresInvite2["default"](res, null, _this24.client);
|
return new _StructuresInvite2["default"](res, null, _this26.client);
|
||||||
}
|
}
|
||||||
return _this24.apiRequest("post", _Constants.Endpoints.CHANNEL_INVITES(res.channel.id), true, { validate: invite }).then(function (res2) {
|
return _this26.apiRequest("post", _Constants.Endpoints.CHANNEL_INVITES(res.channel.id), true, { validate: invite }).then(function (res2) {
|
||||||
return new _StructuresInvite2["default"](res2, _this24.channels.get("id", res.channel.id), _this24.client);
|
return new _StructuresInvite2["default"](res2, _this26.channels.get("id", res.channel.id), _this26.client);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -969,22 +988,22 @@ var InternalClient = (function () {
|
|||||||
//def getInvites
|
//def getInvites
|
||||||
|
|
||||||
InternalClient.prototype.getInvites = function getInvites(channel) {
|
InternalClient.prototype.getInvites = function getInvites(channel) {
|
||||||
var _this25 = this;
|
var _this27 = 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, _this25.channels.get("id", data.channel.id), _this25.client);
|
return new _StructuresInvite2["default"](data, _this27.channels.get("id", data.channel.id), _this27.client);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||||
return _this25.apiRequest("get", _Constants.Endpoints.CHANNEL_INVITES(channel.id), true).then(function (res) {
|
return _this27.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, _this25.channels.get("id", data.channel.id), _this25.client);
|
return new _StructuresInvite2["default"](data, _this27.channels.get("id", data.channel.id), _this27.client);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -993,12 +1012,14 @@ var InternalClient = (function () {
|
|||||||
//def overwritePermissions
|
//def overwritePermissions
|
||||||
|
|
||||||
InternalClient.prototype.overwritePermissions = function overwritePermissions(channel, role, updated) {
|
InternalClient.prototype.overwritePermissions = function overwritePermissions(channel, role, updated) {
|
||||||
var _this26 = this;
|
var _this28 = this;
|
||||||
|
|
||||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||||
var user;
|
var user;
|
||||||
if (role instanceof _StructuresUser2["default"]) {
|
if (role instanceof _StructuresUser2["default"]) {
|
||||||
user = role;
|
user = role;
|
||||||
|
} else {
|
||||||
|
role = _this28.resolver.resolveRole(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = {};
|
var data = {};
|
||||||
@@ -1034,7 +1055,7 @@ var InternalClient = (function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _this26.apiRequest("put", _Constants.Endpoints.CHANNEL_PERMISSIONS(channel.id) + "/" + data.id, true, data);
|
return _this28.apiRequest("put", _Constants.Endpoints.CHANNEL_PERMISSIONS(channel.id) + "/" + data.id, true, data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1070,49 +1091,49 @@ var InternalClient = (function () {
|
|||||||
//def sendTyping
|
//def sendTyping
|
||||||
|
|
||||||
InternalClient.prototype.sendTyping = function sendTyping(channel) {
|
InternalClient.prototype.sendTyping = function sendTyping(channel) {
|
||||||
var _this27 = this;
|
var _this29 = this;
|
||||||
|
|
||||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||||
return _this27.apiRequest("post", _Constants.Endpoints.CHANNEL(channel.id) + "/typing", true);
|
return _this29.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 _this28 = this;
|
var _this30 = this;
|
||||||
|
|
||||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||||
|
|
||||||
if (_this28.intervals.typing[channel.id]) {
|
if (_this30.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");
|
||||||
}
|
}
|
||||||
|
|
||||||
_this28.intervals.typing[channel.id] = setInterval(function () {
|
_this30.intervals.typing[channel.id] = setInterval(function () {
|
||||||
return _this28.sendTyping(channel)["catch"](function (error) {
|
return _this30.sendTyping(channel)["catch"](function (error) {
|
||||||
return _this28.emit("error", error);
|
return _this30.emit("error", error);
|
||||||
});
|
});
|
||||||
}, 4000);
|
}, 4000);
|
||||||
|
|
||||||
return _this28.sendTyping(channel);
|
return _this30.sendTyping(channel);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//def stopTyping
|
//def stopTyping
|
||||||
|
|
||||||
InternalClient.prototype.stopTyping = function stopTyping(channel) {
|
InternalClient.prototype.stopTyping = function stopTyping(channel) {
|
||||||
var _this29 = this;
|
var _this31 = this;
|
||||||
|
|
||||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||||
|
|
||||||
if (!_this29.intervals.typing[channel.id]) {
|
if (!_this31.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(_this29.intervals.typing[channel.id]);
|
clearInterval(_this31.intervals.typing[channel.id]);
|
||||||
_this29.intervals.typing[channel.id] = false;
|
_this31.intervals.typing[channel.id] = false;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1146,12 +1167,12 @@ var InternalClient = (function () {
|
|||||||
//def setChannelTopic
|
//def setChannelTopic
|
||||||
|
|
||||||
InternalClient.prototype.setChannelTopic = function setChannelTopic(chann) {
|
InternalClient.prototype.setChannelTopic = function setChannelTopic(chann) {
|
||||||
var _this30 = this;
|
var _this32 = this;
|
||||||
|
|
||||||
var topic = arguments.length <= 1 || arguments[1] === undefined ? "" : arguments[1];
|
var topic = arguments.length <= 1 || arguments[1] === undefined ? "" : arguments[1];
|
||||||
|
|
||||||
return this.resolver.resolveChannel(chann).then(function (channel) {
|
return this.resolver.resolveChannel(chann).then(function (channel) {
|
||||||
return _this30.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
|
return _this32.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
|
||||||
name: channel.name,
|
name: channel.name,
|
||||||
position: channel.position,
|
position: channel.position,
|
||||||
topic: topic
|
topic: topic
|
||||||
@@ -1164,12 +1185,12 @@ var InternalClient = (function () {
|
|||||||
//def setChannelName
|
//def setChannelName
|
||||||
|
|
||||||
InternalClient.prototype.setChannelName = function setChannelName(chann) {
|
InternalClient.prototype.setChannelName = function setChannelName(chann) {
|
||||||
var _this31 = this;
|
var _this33 = this;
|
||||||
|
|
||||||
var name = arguments.length <= 1 || arguments[1] === undefined ? "discordjs_is_the_best" : arguments[1];
|
var name = arguments.length <= 1 || arguments[1] === undefined ? "discordjs_is_the_best" : arguments[1];
|
||||||
|
|
||||||
return this.resolver.resolveChannel(chann).then(function (channel) {
|
return this.resolver.resolveChannel(chann).then(function (channel) {
|
||||||
return _this31.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
|
return _this33.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
|
||||||
name: name,
|
name: name,
|
||||||
position: channel.position,
|
position: channel.position,
|
||||||
topic: channel.topic
|
topic: channel.topic
|
||||||
@@ -1182,13 +1203,13 @@ var InternalClient = (function () {
|
|||||||
//def setChannelNameAndTopic
|
//def setChannelNameAndTopic
|
||||||
|
|
||||||
InternalClient.prototype.setChannelNameAndTopic = function setChannelNameAndTopic(chann) {
|
InternalClient.prototype.setChannelNameAndTopic = function setChannelNameAndTopic(chann) {
|
||||||
var _this32 = this;
|
var _this34 = this;
|
||||||
|
|
||||||
var name = arguments.length <= 1 || arguments[1] === undefined ? "discordjs_is_the_best" : arguments[1];
|
var name = arguments.length <= 1 || arguments[1] === undefined ? "discordjs_is_the_best" : arguments[1];
|
||||||
var topic = arguments.length <= 2 || arguments[2] === undefined ? "" : arguments[2];
|
var topic = arguments.length <= 2 || arguments[2] === undefined ? "" : arguments[2];
|
||||||
|
|
||||||
return this.resolver.resolveChannel(chann).then(function (channel) {
|
return this.resolver.resolveChannel(chann).then(function (channel) {
|
||||||
return _this32.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
|
return _this34.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
|
||||||
name: name,
|
name: name,
|
||||||
position: channel.position,
|
position: channel.position,
|
||||||
topic: topic
|
topic: topic
|
||||||
@@ -1202,12 +1223,12 @@ var InternalClient = (function () {
|
|||||||
//def setTopic
|
//def setTopic
|
||||||
|
|
||||||
InternalClient.prototype.setChannelPosition = function setChannelPosition(chann) {
|
InternalClient.prototype.setChannelPosition = function setChannelPosition(chann) {
|
||||||
var _this33 = this;
|
var _this35 = this;
|
||||||
|
|
||||||
var position = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
|
var position = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
|
||||||
|
|
||||||
return this.resolver.resolveChannel(chann).then(function (channel) {
|
return this.resolver.resolveChannel(chann).then(function (channel) {
|
||||||
return _this33.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
|
return _this35.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
|
||||||
name: channel.name,
|
name: channel.name,
|
||||||
position: position,
|
position: position,
|
||||||
topic: channel.topic
|
topic: channel.topic
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ var _StructuresPMChannel = require("../../Structures/PMChannel");
|
|||||||
|
|
||||||
var _StructuresPMChannel2 = _interopRequireDefault(_StructuresPMChannel);
|
var _StructuresPMChannel2 = _interopRequireDefault(_StructuresPMChannel);
|
||||||
|
|
||||||
|
var _StructuresRole = require("../../Structures/Role");
|
||||||
|
|
||||||
|
var _StructuresRole2 = _interopRequireDefault(_StructuresRole);
|
||||||
|
|
||||||
var _StructuresServer = require("../../Structures/Server");
|
var _StructuresServer = require("../../Structures/Server");
|
||||||
|
|
||||||
var _StructuresServer2 = _interopRequireDefault(_StructuresServer);
|
var _StructuresServer2 = _interopRequireDefault(_StructuresServer);
|
||||||
@@ -94,6 +98,36 @@ var Resolver = (function () {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Resolver.prototype.resolveRole = function resolveRole(resource) {
|
||||||
|
if (resource instanceof _StructuresRole2["default"]) {
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
if (resource instanceof String || typeof resource === "string") {
|
||||||
|
var role = null;
|
||||||
|
for (var _iterator = this.internal.servers, _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 {
|
||||||
|
_i = _iterator.next();
|
||||||
|
if (_i.done) break;
|
||||||
|
_ref = _i.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var server = _ref;
|
||||||
|
|
||||||
|
if (role = server.roles.find(function (r) {
|
||||||
|
return r.id == resource;
|
||||||
|
})) {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
Resolver.prototype.resolveFile = function resolveFile(resource) {
|
Resolver.prototype.resolveFile = function resolveFile(resource) {
|
||||||
if (typeof resource === "string" || resource instanceof String) {
|
if (typeof resource === "string" || resource instanceof String) {
|
||||||
return _fs2["default"].createReadStream(resource);
|
return _fs2["default"].createReadStream(resource);
|
||||||
@@ -105,19 +139,19 @@ var Resolver = (function () {
|
|||||||
// resource is a string
|
// resource is a string
|
||||||
var _mentions = [];
|
var _mentions = [];
|
||||||
var changed = resource;
|
var changed = resource;
|
||||||
for (var _iterator = resource.match(/<@[^>]*>/g) || [], _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
for (var _iterator2 = resource.match(/<@[^>]*>/g) || [], _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||||
var _ref;
|
var _ref2;
|
||||||
|
|
||||||
if (_isArray) {
|
if (_isArray2) {
|
||||||
if (_i >= _iterator.length) break;
|
if (_i2 >= _iterator2.length) break;
|
||||||
_ref = _iterator[_i++];
|
_ref2 = _iterator2[_i2++];
|
||||||
} else {
|
} else {
|
||||||
_i = _iterator.next();
|
_i2 = _iterator2.next();
|
||||||
if (_i.done) break;
|
if (_i2.done) break;
|
||||||
_ref = _i.value;
|
_ref2 = _i2.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mention = _ref;
|
var mention = _ref2;
|
||||||
|
|
||||||
var userID = mention.substring(2, mention.length - 1);
|
var userID = mention.substring(2, mention.length - 1);
|
||||||
_mentions.push(userID);
|
_mentions.push(userID);
|
||||||
@@ -209,19 +243,19 @@ var Resolver = (function () {
|
|||||||
if (resource instanceof _StructuresUser2["default"]) {
|
if (resource instanceof _StructuresUser2["default"]) {
|
||||||
// see if a PM exists
|
// see if a PM exists
|
||||||
var chatFound = false;
|
var chatFound = false;
|
||||||
for (var _iterator2 = this.internal.private_channels, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
for (var _iterator3 = this.internal.private_channels, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
||||||
var _ref2;
|
var _ref3;
|
||||||
|
|
||||||
if (_isArray2) {
|
if (_isArray3) {
|
||||||
if (_i2 >= _iterator2.length) break;
|
if (_i3 >= _iterator3.length) break;
|
||||||
_ref2 = _iterator2[_i2++];
|
_ref3 = _iterator3[_i3++];
|
||||||
} else {
|
} else {
|
||||||
_i2 = _iterator2.next();
|
_i3 = _iterator3.next();
|
||||||
if (_i2.done) break;
|
if (_i3.done) break;
|
||||||
_ref2 = _i2.value;
|
_ref3 = _i3.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pmchat = _ref2;
|
var pmchat = _ref3;
|
||||||
|
|
||||||
if (pmchat.recipient.equals(resource)) {
|
if (pmchat.recipient.equals(resource)) {
|
||||||
chatFound = pmchat;
|
chatFound = pmchat;
|
||||||
|
|||||||
@@ -621,6 +621,7 @@ export default class InternalClient {
|
|||||||
// def updateRole
|
// def updateRole
|
||||||
updateRole(role, data) {
|
updateRole(role, data) {
|
||||||
|
|
||||||
|
role = this.resolver.resolveRole(role);
|
||||||
var server = this.resolver.resolveServer(role.server);
|
var server = this.resolver.resolveServer(role.server);
|
||||||
|
|
||||||
var newData = {
|
var newData = {
|
||||||
@@ -661,11 +662,14 @@ export default class InternalClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!Array.isArray(roles) || roles.length === 0) {
|
if (!Array.isArray(roles) || roles.length === 0) {
|
||||||
if (roles instanceof Role) {
|
roles = this.resolve.resolveRole(roles);
|
||||||
|
if (roles) {
|
||||||
roles = [roles];
|
roles = [roles];
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject(new Error("invalid array of roles"));
|
return Promise.reject(new Error("invalid array of roles"));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
roles = roles.map(r => this.resolver.resolveRole(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (roles.some(role => !role.server.memberMap[member.id])) {
|
if (roles.some(role => !role.server.memberMap[member.id])) {
|
||||||
@@ -691,8 +695,12 @@ export default class InternalClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
memberHasRole(member, role) {
|
memberHasRole(member, role) {
|
||||||
|
role = this.resolver.resolveRole(role);
|
||||||
member = this.resolver.resolveUser(member);
|
member = this.resolver.resolveUser(member);
|
||||||
|
|
||||||
|
if (!role) {
|
||||||
|
throw new Error("invalid role");
|
||||||
|
}
|
||||||
if (!member) {
|
if (!member) {
|
||||||
throw new Error("user not found");
|
throw new Error("user not found");
|
||||||
}
|
}
|
||||||
@@ -709,11 +717,14 @@ export default class InternalClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!Array.isArray(roles) || roles.length === 0) {
|
if (!Array.isArray(roles) || roles.length === 0) {
|
||||||
if (roles instanceof Role) {
|
roles = this.resolve.resolveRole(roles);
|
||||||
|
if (roles) {
|
||||||
roles = [roles];
|
roles = [roles];
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject(new Error("invalid array of roles"));
|
return Promise.reject(new Error("invalid array of roles"));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
roles = roles.map(r => this.resolver.resolveRole(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
var roleIDS = roles[0].server.memberMap[member.id].roles.map(r => r.id);
|
var roleIDS = roles[0].server.memberMap[member.id].roles.map(r => r.id);
|
||||||
@@ -829,6 +840,8 @@ export default class InternalClient {
|
|||||||
var user;
|
var user;
|
||||||
if (role instanceof User) {
|
if (role instanceof User) {
|
||||||
user = role;
|
user = role;
|
||||||
|
} else {
|
||||||
|
role = this.resolver.resolveRole(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = {};
|
var data = {};
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import TextChannel from "../../Structures/TextChannel";
|
|||||||
import VoiceChannel from "../../Structures/VoiceChannel";
|
import VoiceChannel from "../../Structures/VoiceChannel";
|
||||||
import ServerChannel from "../../Structures/ServerChannel";
|
import ServerChannel from "../../Structures/ServerChannel";
|
||||||
import PMChannel from "../../Structures/PMChannel";
|
import PMChannel from "../../Structures/PMChannel";
|
||||||
|
import Role from "../../Structures/Role";
|
||||||
import Server from "../../Structures/Server";
|
import Server from "../../Structures/Server";
|
||||||
import Message from "../../Structures/Message";
|
import Message from "../../Structures/Message";
|
||||||
import Invite from "../../Structures/Invite";
|
import Invite from "../../Structures/Invite";
|
||||||
@@ -58,6 +59,21 @@ export default class Resolver {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resolveRole(resource) {
|
||||||
|
if (resource instanceof Role) {
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
if (resource instanceof String || typeof resource === "string") {
|
||||||
|
var role = null;
|
||||||
|
for (var server of this.internal.servers) {
|
||||||
|
if (role = server.roles.find(r => r.id == resource)) {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
resolveFile(resource) {
|
resolveFile(resource) {
|
||||||
if (typeof resource === "string" || resource instanceof String) {
|
if (typeof resource === "string" || resource instanceof String) {
|
||||||
return fs.createReadStream(resource);
|
return fs.createReadStream(resource);
|
||||||
|
|||||||
Reference in New Issue
Block a user