Merge addRoleToMember(s), merge removeRoleFromMember(s)

This commit is contained in:
abalabahaha
2016-01-29 14:55:07 -08:00
parent be083b717e
commit 2c8747995a
2 changed files with 64 additions and 154 deletions

View File

@@ -711,7 +711,7 @@ var InternalClient = (function () {
// def moveMember
InternalClient.prototype.moveMember = function moveMember(user, channel) {
var _this19 = this;
var _this20 = this;
user = this.resolver.resolveUser(user);
return this.resolver.resolveChannel(channel).then(function (channel) {
@@ -721,7 +721,7 @@ var InternalClient = (function () {
if (channel.type !== "voice") {
throw new Error("Can't moveMember into a non-voice channel");
} else {
return _this19.apiRequest("patch", _Constants.Endpoints.SERVER_MEMBERS(server.id) + "/" + user.id, true, { channel_id: channel.id }).then(function (res) {
return _this20.apiRequest("patch", _Constants.Endpoints.SERVER_MEMBERS(server.id) + "/" + user.id, true, { channel_id: channel.id }).then(function (res) {
user.voiceChannel = channel;
return res;
});
@@ -732,15 +732,15 @@ var InternalClient = (function () {
// def createRole
InternalClient.prototype.createRole = function createRole(server, data) {
var _this20 = this;
var _this21 = this;
server = this.resolver.resolveServer(server);
return this.apiRequest("post", _Constants.Endpoints.SERVER_ROLES(server.id), true).then(function (res) {
var role = server.roles.add(new _StructuresRole2["default"](res, server, _this20.client));
var role = server.roles.add(new _StructuresRole2["default"](res, server, _this21.client));
if (data) {
return _this20.updateRole(role, data);
return _this21.updateRole(role, data);
}
return role;
});
@@ -749,7 +749,7 @@ var InternalClient = (function () {
// def updateRole
InternalClient.prototype.updateRole = function updateRole(role, data) {
var _this21 = this;
var _this22 = this;
var server = this.resolver.resolveServer(role.server);
@@ -785,7 +785,7 @@ var InternalClient = (function () {
}
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, _this21.client));
return server.roles.update(role, new _StructuresRole2["default"](res, server, _this22.client));
});
};
@@ -797,29 +797,7 @@ var InternalClient = (function () {
//def addMemberToRole
InternalClient.prototype.addMemberToRole = function addMemberToRole(member, role) {
member = this.resolver.resolveUser(member);
if (!member || !role) {
return Promise.reject(new Error("member/role not in server"));
}
if (!role.server.memberMap[member.id]) {
return Promise.reject(new Error("member not in server"));
}
var roleIDS = role.server.memberMap[member.id].roles.map(function (r) {
return r.id;
}).concat(role.id);
return this.apiRequest("patch", _Constants.Endpoints.SERVER_MEMBERS(role.server.id) + "/" + member.id, true, {
roles: roleIDS
});
};
//def addMemberToRole
InternalClient.prototype.addMemberToRoles = function addMemberToRoles(member, roles) {
InternalClient.prototype.addMemberToRole = function addMemberToRole(member, roles) {
member = this.resolver.resolveUser(member);
if (!member) {
@@ -827,7 +805,11 @@ var InternalClient = (function () {
}
if (!Array.isArray(roles) || roles.length === 0) {
return Promise.reject(new Error("invalid array of roles"));
if (roles instanceof _StructuresRole2["default"]) {
roles = [roles];
} else {
return Promise.reject(new Error("invalid array of roles"));
}
}
if (roles.some(function (role) {
@@ -853,36 +835,7 @@ var InternalClient = (function () {
//def removeMemberFromRole
InternalClient.prototype.removeMemberFromRole = function removeMemberFromRole(member, role) {
member = this.resolver.resolveUser(member);
if (!member || !role) {
return Promise.reject(new Error("member/role not in server"));
}
if (!role.server.memberMap[member.id]) {
return Promise.reject(new Error("member not in server"));
}
var roleIDS = role.server.memberMap[member.id].roles.map(function (r) {
return r.id;
});
for (var item in roleIDS) {
if (roleIDS[item] === role.id) {
roleIDS.splice(item, 1);
break;
}
}
return this.apiRequest("patch", _Constants.Endpoints.SERVER_MEMBERS(role.server.id) + "/" + member.id, true, {
roles: roleIDS
});
};
//def removeMemberFromRoles
InternalClient.prototype.removeMemberFromRoles = function removeMemberFromRoles(member, roles) {
InternalClient.prototype.removeMemberFromRole = function removeMemberFromRole(member, roles) {
member = this.resolver.resolveUser(member);
if (!member) {
@@ -890,7 +843,11 @@ var InternalClient = (function () {
}
if (!Array.isArray(roles) || roles.length === 0) {
return Promise.reject(new Error("invalid array of roles"));
if (roles instanceof _StructuresRole2["default"]) {
roles = [roles];
} else {
return Promise.reject(new Error("invalid array of roles"));
}
}
var roleIDS = roles[0].server.memberMap[member.id].roles.map(function (r) {
@@ -930,7 +887,7 @@ var InternalClient = (function () {
// def createInvite
InternalClient.prototype.createInvite = function createInvite(chanServ, options) {
var _this22 = this;
var _this23 = this;
if (chanServ instanceof _StructuresChannel2["default"]) {
// do something
@@ -963,7 +920,7 @@ var InternalClient = (function () {
}
return this.apiRequest("post", epoint, true, options).then(function (res) {
return new _StructuresInvite2["default"](res, _this22.channels.get("id", res.channel.id), _this22.client);
return new _StructuresInvite2["default"](res, _this23.channels.get("id", res.channel.id), _this23.client);
});
};
@@ -980,7 +937,7 @@ var InternalClient = (function () {
//def getInvite
InternalClient.prototype.getInvite = function getInvite(invite) {
var _this23 = this;
var _this24 = this;
invite = this.resolver.resolveInviteID(invite);
if (!invite) {
@@ -988,11 +945,11 @@ var InternalClient = (function () {
}
return this.apiRequest("get", _Constants.Endpoints.INVITE(invite), true).then(function (res) {
if (!_this23.channels.has("id", res.channel.id)) {
return new _StructuresInvite2["default"](res, null, _this23.client);
if (!_this24.channels.has("id", res.channel.id)) {
return new _StructuresInvite2["default"](res, null, _this24.client);
}
return _this23.apiRequest("post", _Constants.Endpoints.CHANNEL_INVITES(res.channel.id), true, { validate: invite }).then(function (res2) {
return new _StructuresInvite2["default"](res2, _this23.channels.get("id", res.channel.id), _this23.client);
return _this24.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);
});
});
};
@@ -1000,22 +957,22 @@ var InternalClient = (function () {
//def getInvites
InternalClient.prototype.getInvites = function getInvites(channel) {
var _this24 = this;
var _this25 = this;
if (!(channel instanceof _StructuresChannel2["default"])) {
var server = this.resolver.resolveServer(channel);
if (server) {
return this.apiRequest("get", _Constants.Endpoints.SERVER_INVITES(server.id), true).then(function (res) {
return res.map(function (data) {
return new _StructuresInvite2["default"](data, _this24.channels.get("id", data.channel.id), _this24.client);
return new _StructuresInvite2["default"](data, _this25.channels.get("id", data.channel.id), _this25.client);
});
});
}
}
return this.resolver.resolveChannel(channel).then(function (channel) {
return _this24.apiRequest("get", _Constants.Endpoints.CHANNEL_INVITES(channel.id), true).then(function (res) {
return _this25.apiRequest("get", _Constants.Endpoints.CHANNEL_INVITES(channel.id), true).then(function (res) {
return res.map(function (data) {
return new _StructuresInvite2["default"](data, _this24.channels.get("id", data.channel.id), _this24.client);
return new _StructuresInvite2["default"](data, _this25.channels.get("id", data.channel.id), _this25.client);
});
});
});
@@ -1024,7 +981,7 @@ var InternalClient = (function () {
//def overwritePermissions
InternalClient.prototype.overwritePermissions = function overwritePermissions(channel, role, updated) {
var _this25 = this;
var _this26 = this;
return this.resolver.resolveChannel(channel).then(function (channel) {
var user;
@@ -1065,7 +1022,7 @@ var InternalClient = (function () {
}
}
return _this25.apiRequest("put", _Constants.Endpoints.CHANNEL_PERMISSIONS(channel.id) + "/" + data.id, true, data);
return _this26.apiRequest("put", _Constants.Endpoints.CHANNEL_PERMISSIONS(channel.id) + "/" + data.id, true, data);
});
};
@@ -1101,49 +1058,49 @@ var InternalClient = (function () {
//def sendTyping
InternalClient.prototype.sendTyping = function sendTyping(channel) {
var _this26 = this;
var _this27 = this;
return this.resolver.resolveChannel(channel).then(function (channel) {
return _this26.apiRequest("post", _Constants.Endpoints.CHANNEL(channel.id) + "/typing", true);
return _this27.apiRequest("post", _Constants.Endpoints.CHANNEL(channel.id) + "/typing", true);
});
};
//def startTyping
InternalClient.prototype.startTyping = function startTyping(channel) {
var _this27 = this;
var _this28 = this;
return this.resolver.resolveChannel(channel).then(function (channel) {
if (_this27.intervals.typing[channel.id]) {
if (_this28.intervals.typing[channel.id]) {
// typing interval already exists, leave it alone
throw new Error("Already typing in that channel");
}
_this27.intervals.typing[channel.id] = setInterval(function () {
return _this27.sendTyping(channel)["catch"](function (error) {
return _this27.emit("error", error);
_this28.intervals.typing[channel.id] = setInterval(function () {
return _this28.sendTyping(channel)["catch"](function (error) {
return _this28.emit("error", error);
});
}, 4000);
return _this27.sendTyping(channel);
return _this28.sendTyping(channel);
});
};
//def stopTyping
InternalClient.prototype.stopTyping = function stopTyping(channel) {
var _this28 = this;
var _this29 = this;
return this.resolver.resolveChannel(channel).then(function (channel) {
if (!_this28.intervals.typing[channel.id]) {
if (!_this29.intervals.typing[channel.id]) {
// typing interval doesn"t exist
throw new Error("Not typing in that channel");
}
clearInterval(_this28.intervals.typing[channel.id]);
_this28.intervals.typing[channel.id] = false;
clearInterval(_this29.intervals.typing[channel.id]);
_this29.intervals.typing[channel.id] = false;
});
};
@@ -1177,12 +1134,12 @@ var InternalClient = (function () {
//def setChannelTopic
InternalClient.prototype.setChannelTopic = function setChannelTopic(chann) {
var _this29 = this;
var _this30 = this;
var topic = arguments.length <= 1 || arguments[1] === undefined ? "" : arguments[1];
return this.resolver.resolveChannel(chann).then(function (channel) {
return _this29.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
return _this30.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
name: channel.name,
position: channel.position,
topic: topic
@@ -1195,12 +1152,12 @@ var InternalClient = (function () {
//def setChannelName
InternalClient.prototype.setChannelName = function setChannelName(chann) {
var _this30 = this;
var _this31 = this;
var name = arguments.length <= 1 || arguments[1] === undefined ? "discordjs_is_the_best" : arguments[1];
return this.resolver.resolveChannel(chann).then(function (channel) {
return _this30.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
return _this31.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
name: name,
position: channel.position,
topic: channel.topic
@@ -1213,13 +1170,13 @@ var InternalClient = (function () {
//def setChannelNameAndTopic
InternalClient.prototype.setChannelNameAndTopic = function setChannelNameAndTopic(chann) {
var _this31 = this;
var _this32 = this;
var name = arguments.length <= 1 || arguments[1] === undefined ? "discordjs_is_the_best" : arguments[1];
var topic = arguments.length <= 2 || arguments[2] === undefined ? "" : arguments[2];
return this.resolver.resolveChannel(chann).then(function (channel) {
return _this31.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
return _this32.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
name: name,
position: channel.position,
topic: topic
@@ -1233,12 +1190,12 @@ var InternalClient = (function () {
//def setTopic
InternalClient.prototype.setChannelPosition = function setChannelPosition(chann) {
var _this32 = this;
var _this33 = this;
var position = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
return this.resolver.resolveChannel(chann).then(function (channel) {
return _this32.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
return _this33.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
name: channel.name,
position: position,
topic: channel.topic

View File

@@ -653,31 +653,7 @@ export default class InternalClient {
}
//def addMemberToRole
addMemberToRole(member, role) {
member = this.resolver.resolveUser(member);
if (!member || !role) {
return Promise.reject(new Error("member/role not in server"));
}
if (!role.server.memberMap[member.id]) {
return Promise.reject(new Error("member not in server"));
}
var roleIDS = role.server.memberMap[member.id].roles.map(r => r.id).concat(role.id);
return this.apiRequest(
"patch",
`${Endpoints.SERVER_MEMBERS(role.server.id)}/${member.id}`,
true,
{
roles: roleIDS
}
);
}
//def addMemberToRole
addMemberToRoles(member, roles) {
addMemberToRole(member, roles) {
member = this.resolver.resolveUser(member);
if (!member) {
@@ -685,7 +661,11 @@ export default class InternalClient {
}
if (!Array.isArray(roles) || roles.length === 0) {
return Promise.reject(new Error("invalid array of roles"));
if (roles instanceof Role) {
roles = [roles];
} else {
return Promise.reject(new Error("invalid array of roles"));
}
}
if (roles.some(role => !role.server.memberMap[member.id])) {
@@ -711,38 +691,7 @@ export default class InternalClient {
}
//def removeMemberFromRole
removeMemberFromRole(member, role) {
member = this.resolver.resolveUser(member);
if (!member || !role) {
return Promise.reject(new Error("member/role not in server"));
}
if (!role.server.memberMap[member.id]) {
return Promise.reject(new Error("member not in server"));
}
var roleIDS = role.server.memberMap[member.id].roles.map(r => r.id);
for (var item in roleIDS) {
if (roleIDS[item] === role.id) {
roleIDS.splice(item, 1);
break;
}
}
return this.apiRequest(
"patch",
`${Endpoints.SERVER_MEMBERS(role.server.id)}/${member.id}`,
true,
{
roles: roleIDS
}
);
}
//def removeMemberFromRoles
removeMemberFromRoles(member, roles) {
removeMemberFromRole(member, roles) {
member = this.resolver.resolveUser(member);
if (!member) {
@@ -750,7 +699,11 @@ export default class InternalClient {
}
if (!Array.isArray(roles) || roles.length === 0) {
return Promise.reject(new Error("invalid array of roles"));
if (roles instanceof Role) {
roles = [roles];
} else {
return Promise.reject(new Error("invalid array of roles"));
}
}
var roleIDS = roles[0].server.memberMap[member.id].roles.map(r => r.id);