Fix for GroupDMChannel#addUser and added removeUser, setName and edit (#1576)

* fixed GroupDMChannel#addUser, added setName and removeUser

and changed every `the Group DM`to `this Group DM`, for consistency

* added edit method

* delete method comes already with the Channel class

* brackets

* removed empty line
This commit is contained in:
SpaceEEC
2017-07-16 14:15:54 +02:00
committed by Crawl
parent 8580380541
commit b7bbd395e8

View File

@@ -47,7 +47,7 @@ class GroupDMChannel extends Channel {
this.name = data.name;
/**
* A hash of the Group DM icon.
* A hash of this Group DM icon
* @type {string}
*/
this.icon = data.icon;
@@ -125,20 +125,58 @@ class GroupDMChannel extends Channel {
}
/**
* Add a user to the DM
* @param {UserResolvable|string} accessTokenOrUser Access token or user resolvable
* @param {string} [nick] Permanent nickname to give the user (only available if a bot is creating the DM)
* Edits this Group DM.
* @param {Object} data New data for this Group DM
* @param {string} [reason] Reason for editing this Group DM
* @returns {Promise<GroupDMChannel>}
*/
addUser(accessTokenOrUser, nick) {
const id = this.client.resolver.resolveUserID(accessTokenOrUser);
edit(data, reason) {
return this.client.api.channels[this.id].patch({
data: {
name: (data.name || this.name).trim(),
},
reason,
}).then(() => this);
}
/**
* Sets a new name for this Group DM.
* @param {string} name New name for this Group DM
* @returns {Promise<GroupDMChannel>}
*/
setName(name) {
return this.edit({ name });
}
/**
* Adds an user to this Group DM.
* @param {Object} options Options for this method
* @param {UserResolveable} options.user User to add to this Group DM
* @param {string} [options.accessToken] Access token to use to add the user to this Group DM
* (only available under a bot account)
* @param {string} [options.nick] Permanent nickname to give the user (only available under a bot account)
* @returns {Promise<GroupDMChannel>}
*/
addUser({ user, accessToken, nick }) {
const id = this.client.resolver.resolveUserID(user);
const data = this.client.user.bot ?
{ nick, access_token: accessTokenOrUser } :
{ nick, access_token: accessToken } :
{ recipient: id };
return this.client.api.channels[this.id].recipients[id].put({ data })
.then(() => this);
}
/**
* Removes an user from this Group DM.
* @param {UserResolveable} user User to remove
* @returns {Promise<GroupDMChannel>}
*/
removeUser(user) {
const id = this.client.resolver.resolveUserID(user);
return this.client.api.channels[this.id].recipients[id].delete()
.then(() => this);
}
/**
* When concatenated with a string, this automatically concatenates the channel's name instead of the Channel object.
* @returns {string}