resolveImage backport (#1822)

* add resolveImage

* add groupDMChannel#setIcon + icon getter

* doc fix

* crawl no kill pls

* *whistles*

* channe
This commit is contained in:
Isabella
2017-08-22 22:29:22 -05:00
committed by Crawl
parent a85fc91630
commit 17d7f5c723
8 changed files with 98 additions and 61 deletions

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,
@@ -105,6 +106,23 @@ class GroupDMChannel extends Channel {
return this.client.users.get(this.ownerID);
}
/**
* The URL to this guild's icon
* @type {?string}
* @readonly
*/
get iconURL() {
if (!this.icon) return null;
return Constants.Endpoints.Channel(this).Icon(this.client.options.http.cdn, this.icon);
}
edit(data) {
const _data = {};
if (data.name) _data.name = data.name;
if (data.icon) _data.icon = data.icon;
return this.client.rest.methods.updateGroupDMChannel(this, _data);
}
/**
* 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
@@ -140,6 +158,20 @@ class GroupDMChannel extends Channel {
});
}
/**
* Set a new GroupDMChannel icon.
* @param {Base64Resolvable|BufferResolvable} icon The new icon of the group dm
* @returns {Promise<Guild>}
* @example
* // Edit the group dm icon
* channel.setIcon('./icon.png')
* .then(updated => console.log('Updated the channel icon'))
* .catch(console.error);
*/
setIcon(icon) {
return this.client.resolver.resolveImage(icon).then(data => this.edit({ icon: data }));
}
/**
* When concatenated with a string, this automatically concatenates the channel's name instead of the Channel object.
* @returns {string}