Fixed ClientUser#createGroupDM on user accounts and added some more GroupDMChannel stuff (#1747)

* ClientUser#createGroupDM now works like the docs states on user accounts

* Added GroupDMChannel#setIcon and fixed null handling for the channel name

* Added an s

* Don't resolve when icon is falsy and removed useless name trimming

* Removed now unnecessary name constant

* vscode being great

* Added GroupDMChannel#iconURL
This commit is contained in:
SpaceEEC
2017-08-04 09:17:46 +02:00
committed by Crawl
parent a30fc87816
commit abfda7c3cc
3 changed files with 36 additions and 3 deletions

View File

@@ -345,7 +345,6 @@ class ClientUser extends User {
* An object containing either a user or access token, and an optional nickname.
* @typedef {Object} GroupDMRecipientOptions
* @property {UserResolvable} [user] User to add to the Group DM
* (only available if a user is creating the DM)
* @property {string} [accessToken] Access token to use to add a user to the Group DM
* (only available if a bot is creating the DM)
* @property {string} [nick] Permanent nickname (only available if a bot is creating the DM)
@@ -365,7 +364,7 @@ class ClientUser extends User {
if (r.nick) o[r.user ? r.user.id : r.id] = r.nick;
return o;
}, {}),
} : { recipients: recipients.map(u => this.client.resolver.resolveUserID(u)) };
} : { recipients: recipients.map(u => this.client.resolver.resolveUserID(u.user || u.id)) };
return this.client.api.users('@me').channels.post({ data })
.then(res => new GroupDMChannel(this.client, res));
}

View File

@@ -1,6 +1,7 @@
const Channel = require('./Channel');
const TextBasedChannel = require('./interfaces/TextBasedChannel');
const Collection = require('../util/Collection');
const Constants = require('../util/Constants');
/*
{ type: 3,
@@ -103,6 +104,18 @@ class GroupDMChannel extends Channel {
return this.client.users.get(this.ownerID);
}
/**
* Gets the URL to this Group DM's icon
* @param {Object} [options={}] Options for the icon url
* @param {string} [options.format='webp'] One of `webp`, `png`, `jpg`
* @param {number} [options.size=128] One of `128`, '256', `512`, `1024`, `2048`
* @returns {?string}
*/
iconURL({ format, size } = {}) {
if (!this.icon) return null;
return Constants.Endpoints.CDN(this.client.options.http.cdn).GDMIcon(this.id, this.icon, format, size);
}
/**
* Whether this channel equals another channel. It compares all properties, so for most operations
* it is advisable to just compare `channel.id === channel2.id` as it is much faster and is often
@@ -133,12 +146,29 @@ class GroupDMChannel extends Channel {
edit(data, reason) {
return this.client.api.channels[this.id].patch({
data: {
name: (data.name || this.name).trim(),
icon: data.icon,
name: data.name === null ? null : data.name || this.name,
},
reason,
}).then(() => this);
}
/**
* Sets a new icon for this Group DM.
* @param {Base64Resolvable} icon The new icon of this Group DM
* @returns {Promise<GroupDMChannel>}
*/
setIcon(icon) {
if (typeof icon === 'string' && icon.startsWith('data:')) {
return this.edit({ icon });
} else if (!icon) {
return this.edit({ icon: null });
} else {
return this.client.resolver.resolveBuffer(icon)
.then(data => this.edit({ icon: this.client.resolver.resolveBase64(data) }));
}
}
/**
* Sets a new name for this Group DM.
* @param {string} name New name for this Group DM

View File

@@ -119,6 +119,10 @@ exports.Endpoints = {
checkImage({ size, format });
return `${root}/app-icons/${clientID}/${hash}.${format}${size ? `?size=${size}` : ''}`;
},
GDMIcon: (channelID, hash, format = 'webp', size) => {
checkImage({ size, format });
return `${root}/channel-icons/${channelID}/${hash}.${format}${size ? `?size=${size}` : ''}`;
},
Splash: (guildID, hash, format = 'webp', size) => {
checkImage({ size, format });
return `${root}/splashes/${guildID}/${hash}.${format}${size ? `?size=${size}` : ''}`;