mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
resolveImage backport (#1822)
* add resolveImage * add groupDMChannel#setIcon + icon getter * doc fix * crawl no kill pls * *whistles* * channe
This commit is contained in:
@@ -152,13 +152,9 @@ class ClientUser extends User {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setAvatar(avatar) {
|
||||
if (typeof avatar === 'string' && avatar.startsWith('data:')) {
|
||||
return this.client.rest.methods.updateCurrentUser({ avatar });
|
||||
} else {
|
||||
return this.client.resolver.resolveBuffer(avatar).then(data =>
|
||||
this.client.rest.methods.updateCurrentUser({ avatar: data })
|
||||
);
|
||||
}
|
||||
return this.client.resolver.resolveImage(avatar).then(data =>
|
||||
this.client.rest.methods.updateCurrentUser({ avatar: data })
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -337,7 +333,7 @@ class ClientUser extends User {
|
||||
}, reject)
|
||||
);
|
||||
} else {
|
||||
return this.client.resolver.resolveBuffer(icon)
|
||||
return this.client.resolver.resolveFile(icon)
|
||||
.then(data => this.createGuild(name, { region, icon: this.client.resolver.resolveBase64(data) || null }));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -615,9 +615,9 @@ class Guild {
|
||||
if (data.afkChannel) _data.afk_channel_id = this.client.resolver.resolveChannel(data.afkChannel).id;
|
||||
if (data.systemChannel) _data.system_channel_id = this.client.resolver.resolveChannel(data.systemChannel).id;
|
||||
if (data.afkTimeout) _data.afk_timeout = Number(data.afkTimeout);
|
||||
if (data.icon) _data.icon = this.client.resolver.resolveBase64(data.icon);
|
||||
if (data.icon) _data.icon = data.icon;
|
||||
if (data.owner) _data.owner_id = this.client.resolver.resolveUser(data.owner).id;
|
||||
if (data.splash) _data.splash = this.client.resolver.resolveBase64(data.splash);
|
||||
if (data.splash) _data.splash = data.splash;
|
||||
if (typeof data.explicitContentFilter !== 'undefined') {
|
||||
_data.explicit_content_filter = Number(data.explicitContentFilter);
|
||||
}
|
||||
@@ -627,7 +627,7 @@ class Guild {
|
||||
/**
|
||||
* Edit the level of the explicit content filter.
|
||||
* @param {number} explicitContentFilter The new level of the explicit content filter
|
||||
* @param {string} [reason] Reason for changing the level of the guild's explicit content filter
|
||||
* @param {string} [reason] Reason for changing the level of the guild's explicit content filter
|
||||
* @returns {Promise<Guild>}
|
||||
*/
|
||||
setExplicitContentFilter(explicitContentFilter, reason) {
|
||||
@@ -637,7 +637,7 @@ class Guild {
|
||||
/**
|
||||
* Edit the name of the guild.
|
||||
* @param {string} name The new name of the guild
|
||||
* @param {string} [reason] Reason for changing the guild's name
|
||||
* @param {string} [reason] Reason for changing the guild's name
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* // Edit the guild name
|
||||
@@ -697,7 +697,7 @@ class Guild {
|
||||
/**
|
||||
* Edit the system channel of the guild.
|
||||
* @param {ChannelResolvable} systemChannel The new system channel
|
||||
* @param {string} [reason] Reason for changing the guild's system channel
|
||||
* @param {string} [reason] Reason for changing the guild's system channel
|
||||
* @returns {Promise<Guild>}
|
||||
*/
|
||||
setSystemChannel(systemChannel, reason) {
|
||||
@@ -721,17 +721,17 @@ class Guild {
|
||||
|
||||
/**
|
||||
* Set a new guild icon.
|
||||
* @param {Base64Resolvable} icon The new icon of the guild
|
||||
* @param {Base64Resolvable|BufferResolvable} icon The new icon of the guild
|
||||
* @param {string} [reason] Reason for changing the guild's icon
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* // Edit the guild icon
|
||||
* guild.setIcon(fs.readFileSync('./icon.png'))
|
||||
* guild.setIcon('./icon.png')
|
||||
* .then(updated => console.log('Updated the guild icon'))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setIcon(icon, reason) {
|
||||
return this.edit({ icon }, reason);
|
||||
return this.client.resolver.resolveImage(icon).then(data => this.edit({ icon: data, reason }));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -751,17 +751,17 @@ class Guild {
|
||||
|
||||
/**
|
||||
* Set a new guild splash screen.
|
||||
* @param {Base64Resolvable} splash The new splash screen of the guild
|
||||
* @param {BufferResolvable|Base64Resolvable} splash The new splash screen of the guild
|
||||
* @param {string} [reason] Reason for changing the guild's splash screen
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* // Edit the guild splash
|
||||
* guild.setIcon(fs.readFileSync('./splash.png'))
|
||||
* guild.setSplash('./splash.png')
|
||||
* .then(updated => console.log('Updated the guild splash'))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setSplash(splash, reason) {
|
||||
return this.edit({ splash }, reason);
|
||||
setSplash(splash) {
|
||||
return this.client.resolver.resolveImage(splash).then(data => this.edit({ splash: data }));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -952,7 +952,7 @@ class Guild {
|
||||
if (typeof attachment === 'string' && attachment.startsWith('data:')) {
|
||||
resolve(this.client.rest.methods.createEmoji(this, attachment, name, roles, reason));
|
||||
} else {
|
||||
this.client.resolver.resolveBuffer(attachment).then(data => {
|
||||
this.client.resolver.resolveFile(attachment).then(data => {
|
||||
const dataURI = this.client.resolver.resolveBase64(data);
|
||||
resolve(this.client.rest.methods.createEmoji(this, dataURI, name, roles, reason));
|
||||
});
|
||||
|
||||
@@ -73,7 +73,7 @@ class TextChannel extends GuildChannel {
|
||||
if (typeof avatar === 'string' && avatar.startsWith('data:')) {
|
||||
resolve(this.client.rest.methods.createWebhook(this, name, avatar, reason));
|
||||
} else {
|
||||
this.client.resolver.resolveBuffer(avatar).then(data =>
|
||||
this.client.resolver.resolveFile(avatar).then(data =>
|
||||
resolve(this.client.rest.methods.createWebhook(this, name, data, reason))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ class Webhook {
|
||||
*/
|
||||
edit(name = this.name, avatar) {
|
||||
if (avatar) {
|
||||
return this.client.resolver.resolveBuffer(avatar).then(file => {
|
||||
return this.client.resolver.resolveFile(avatar).then(file => {
|
||||
const dataURI = this.client.resolver.resolveBase64(file);
|
||||
return this.client.rest.methods.editWebhook(this, name, dataURI);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user