* Add reasons

* How could I forget

* Hopefully fix conflicts
This commit is contained in:
Pg Biel
2017-07-26 22:14:04 -03:00
committed by Crawl
parent 27196c2f9f
commit eef87e5d97
6 changed files with 78 additions and 50 deletions

View File

@@ -132,10 +132,11 @@ class Emoji {
/** /**
* Set the name of the emoji. * Set the name of the emoji.
* @param {string} name The new name for the emoji * @param {string} name The new name for the emoji
* @param {string} [reason] Reason for changing the emoji's name
* @returns {Promise<Emoji>} * @returns {Promise<Emoji>}
*/ */
setName(name) { setName(name, reason) {
return this.edit({ name }); return this.edit({ name }, reason);
} }
/** /**

View File

@@ -604,15 +604,17 @@ class Guild {
/** /**
* Edit the level of the explicit content filter. * Edit the level of the explicit content filter.
* @param {number} explicitContentFilter The new 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
* @returns {Promise<Guild>} * @returns {Promise<Guild>}
*/ */
setExplicitContentFilter(explicitContentFilter) { setExplicitContentFilter(explicitContentFilter, reason) {
return this.edit({ explicitContentFilter }); return this.edit({ explicitContentFilter }, reason);
} }
/** /**
* Edit the name of the guild. * Edit the name of the guild.
* @param {string} name The new name of the guild * @param {string} name The new name of the guild
* @param {string} [reason] Reason for changing the guild's name
* @returns {Promise<Guild>} * @returns {Promise<Guild>}
* @example * @example
* // Edit the guild name * // Edit the guild name
@@ -620,13 +622,14 @@ class Guild {
* .then(updated => console.log(`Updated guild name to ${guild.name}`)) * .then(updated => console.log(`Updated guild name to ${guild.name}`))
* .catch(console.error); * .catch(console.error);
*/ */
setName(name) { setName(name, reason) {
return this.edit({ name }); return this.edit({ name }, reason);
} }
/** /**
* Edit the region of the guild. * Edit the region of the guild.
* @param {string} region The new region of the guild * @param {string} region The new region of the guild
* @param {string} [reason] Reason for changing the guild's region
* @returns {Promise<Guild>} * @returns {Promise<Guild>}
* @example * @example
* // Edit the guild region * // Edit the guild region
@@ -634,13 +637,14 @@ class Guild {
* .then(updated => console.log(`Updated guild region to ${guild.region}`)) * .then(updated => console.log(`Updated guild region to ${guild.region}`))
* .catch(console.error); * .catch(console.error);
*/ */
setRegion(region) { setRegion(region, reason) {
return this.edit({ region }); return this.edit({ region }, reason);
} }
/** /**
* Edit the verification level of the guild. * Edit the verification level of the guild.
* @param {number} verificationLevel The new verification level of the guild * @param {number} verificationLevel The new verification level of the guild
* @param {string} [reason] Reason for changing the guild's verification level
* @returns {Promise<Guild>} * @returns {Promise<Guild>}
* @example * @example
* // Edit the guild verification level * // Edit the guild verification level
@@ -648,13 +652,14 @@ class Guild {
* .then(updated => console.log(`Updated guild verification level to ${guild.verificationLevel}`)) * .then(updated => console.log(`Updated guild verification level to ${guild.verificationLevel}`))
* .catch(console.error); * .catch(console.error);
*/ */
setVerificationLevel(verificationLevel) { setVerificationLevel(verificationLevel, reason) {
return this.edit({ verificationLevel }); return this.edit({ verificationLevel }, reason);
} }
/** /**
* Edit the AFK channel of the guild. * Edit the AFK channel of the guild.
* @param {ChannelResolvable} afkChannel The new AFK channel * @param {ChannelResolvable} afkChannel The new AFK channel
* @param {string} [reason] Reason for changing the guild's AFK channel
* @returns {Promise<Guild>} * @returns {Promise<Guild>}
* @example * @example
* // Edit the guild AFK channel * // Edit the guild AFK channel
@@ -662,13 +667,14 @@ class Guild {
* .then(updated => console.log(`Updated guild AFK channel to ${guild.afkChannel}`)) * .then(updated => console.log(`Updated guild AFK channel to ${guild.afkChannel}`))
* .catch(console.error); * .catch(console.error);
*/ */
setAFKChannel(afkChannel) { setAFKChannel(afkChannel, reason) {
return this.edit({ afkChannel }); return this.edit({ afkChannel }, reason);
} }
/** /**
* Edit the AFK timeout of the guild. * Edit the AFK timeout of the guild.
* @param {number} afkTimeout The time in seconds that a user must be idle to be considered AFK * @param {number} afkTimeout The time in seconds that a user must be idle to be considered AFK
* @param {string} [reason] Reason for changing the guild's AFK timeout
* @returns {Promise<Guild>} * @returns {Promise<Guild>}
* @example * @example
* // Edit the guild AFK channel * // Edit the guild AFK channel
@@ -676,13 +682,14 @@ class Guild {
* .then(updated => console.log(`Updated guild AFK timeout to ${guild.afkTimeout}`)) * .then(updated => console.log(`Updated guild AFK timeout to ${guild.afkTimeout}`))
* .catch(console.error); * .catch(console.error);
*/ */
setAFKTimeout(afkTimeout) { setAFKTimeout(afkTimeout, reason) {
return this.edit({ afkTimeout }); return this.edit({ afkTimeout }, reason);
} }
/** /**
* Set a new guild icon. * Set a new guild icon.
* @param {Base64Resolvable} icon The new icon of the guild * @param {Base64Resolvable} icon The new icon of the guild
* @param {string} [reason] Reason for changing the guild's icon
* @returns {Promise<Guild>} * @returns {Promise<Guild>}
* @example * @example
* // Edit the guild icon * // Edit the guild icon
@@ -690,13 +697,14 @@ class Guild {
* .then(updated => console.log('Updated the guild icon')) * .then(updated => console.log('Updated the guild icon'))
* .catch(console.error); * .catch(console.error);
*/ */
setIcon(icon) { setIcon(icon, reason) {
return this.edit({ icon }); return this.edit({ icon }, reason);
} }
/** /**
* Sets a new owner of the guild. * Sets a new owner of the guild.
* @param {GuildMemberResolvable} owner The new owner of the guild * @param {GuildMemberResolvable} owner The new owner of the guild
* @param {string} [reason] Reason for setting the new owner
* @returns {Promise<Guild>} * @returns {Promise<Guild>}
* @example * @example
* // Edit the guild owner * // Edit the guild owner
@@ -704,13 +712,14 @@ class Guild {
* .then(updated => console.log(`Updated the guild owner to ${updated.owner.username}`)) * .then(updated => console.log(`Updated the guild owner to ${updated.owner.username}`))
* .catch(console.error); * .catch(console.error);
*/ */
setOwner(owner) { setOwner(owner, reason) {
return this.edit({ owner }); return this.edit({ owner }, reason);
} }
/** /**
* Set a new guild splash screen. * Set a new guild splash screen.
* @param {Base64Resolvable} splash The new splash screen of the guild * @param {Base64Resolvable} splash The new splash screen of the guild
* @param {string} [reason] Reason for changing the guild's splash screen
* @returns {Promise<Guild>} * @returns {Promise<Guild>}
* @example * @example
* // Edit the guild splash * // Edit the guild splash
@@ -718,8 +727,8 @@ class Guild {
* .then(updated => console.log('Updated the guild splash')) * .then(updated => console.log('Updated the guild splash'))
* .catch(console.error); * .catch(console.error);
*/ */
setSplash(splash) { setSplash(splash, reason) {
return this.edit({ splash }); return this.edit({ splash }, reason);
} }
/** /**
@@ -948,7 +957,9 @@ class Guild {
* Creates a new custom emoji in the guild. * Creates a new custom emoji in the guild.
* @param {BufferResolvable|Base64Resolvable} attachment The image for the emoji * @param {BufferResolvable|Base64Resolvable} attachment The image for the emoji
* @param {string} name The name for the emoji * @param {string} name The name for the emoji
* @param {Collection<Snowflake, Role>|Role[]} [roles] Roles to limit the emoji to * @param {Object} [options] Options
* @param {Collection<Snowflake, Role>|Role[]} [options.roles] Roles to limit the emoji to
* @param {string} [options.reason] Reason for creating the emoji
* @returns {Promise<Emoji>} The created emoji * @returns {Promise<Emoji>} The created emoji
* @example * @example
* // Create a new emoji from a url * // Create a new emoji from a url
@@ -961,11 +972,11 @@ class Guild {
* .then(emoji => console.log(`Created new emoji with name ${emoji.name}!`)) * .then(emoji => console.log(`Created new emoji with name ${emoji.name}!`))
* .catch(console.error); * .catch(console.error);
*/ */
createEmoji(attachment, name, roles) { createEmoji(attachment, name, { roles, reason } = {}) {
if (typeof attachment === 'string' && attachment.startsWith('data:')) { if (typeof attachment === 'string' && attachment.startsWith('data:')) {
const data = { image: attachment, name }; const data = { image: attachment, name };
if (roles) data.roles = roles.map(r => r.id ? r.id : r); if (roles) data.roles = roles.map(r => r.id ? r.id : r);
return this.client.api.guilds(this.id).emojis.post({ data }) return this.client.api.guilds(this.id).emojis.post({ data, reason })
.then(emoji => this.client.actions.GuildEmojiCreate.handle(this, emoji).emoji); .then(emoji => this.client.actions.GuildEmojiCreate.handle(this, emoji).emoji);
} else { } else {
return this.client.resolver.resolveBuffer(attachment) return this.client.resolver.resolveBuffer(attachment)
@@ -979,11 +990,12 @@ class Guild {
/** /**
* Delete an emoji. * Delete an emoji.
* @param {Emoji|string} emoji The emoji to delete * @param {Emoji|string} emoji The emoji to delete
* @param {string} [reason] Reason for deleting the emoji
* @returns {Promise} * @returns {Promise}
*/ */
deleteEmoji(emoji) { deleteEmoji(emoji, reason) {
if (!(emoji instanceof Emoji)) emoji = this.emojis.get(emoji); if (!(emoji instanceof Emoji)) emoji = this.emojis.get(emoji);
return this.client.api.guilds(this.id).emojis(emoji.id).delete() return this.client.api.guilds(this.id).emojis(emoji.id).delete({ reason })
.then(() => this.client.actions.GuildEmojiDelete.handle(emoji).data); .then(() => this.client.actions.GuildEmojiDelete.handle(emoji).data);
} }

View File

@@ -231,6 +231,7 @@ class GuildChannel extends Channel {
/** /**
* Set a new name for the guild channel. * Set a new name for the guild channel.
* @param {string} name The new name for the guild channel * @param {string} name The new name for the guild channel
* @param {string} [reason] Reason for changing the guild channel's name
* @returns {Promise<GuildChannel>} * @returns {Promise<GuildChannel>}
* @example * @example
* // Set a new channel name * // Set a new channel name
@@ -238,8 +239,8 @@ class GuildChannel extends Channel {
* .then(newChannel => console.log(`Channel's new name is ${newChannel.name}`)) * .then(newChannel => console.log(`Channel's new name is ${newChannel.name}`))
* .catch(console.error); * .catch(console.error);
*/ */
setName(name) { setName(name, reason) {
return this.edit({ name }); return this.edit({ name }, reason);
} }
/** /**
@@ -260,6 +261,7 @@ class GuildChannel extends Channel {
/** /**
* Set a new topic for the guild channel. * Set a new topic for the guild channel.
* @param {string} topic The new topic for the guild channel * @param {string} topic The new topic for the guild channel
* @param {string} [reason] Reason for changing the guild channel's topic
* @returns {Promise<GuildChannel>} * @returns {Promise<GuildChannel>}
* @example * @example
* // Set a new channel topic * // Set a new channel topic
@@ -267,8 +269,8 @@ class GuildChannel extends Channel {
* .then(newChannel => console.log(`Channel's new topic is ${newChannel.topic}`)) * .then(newChannel => console.log(`Channel's new topic is ${newChannel.topic}`))
* .catch(console.error); * .catch(console.error);
*/ */
setTopic(topic) { setTopic(topic, reason) {
return this.edit({ topic }); return this.edit({ topic }, reason);
} }
/** /**
@@ -297,13 +299,18 @@ class GuildChannel extends Channel {
/** /**
* Clone this channel. * Clone this channel.
* @param {string} [name=this.name] Optional name for the new channel, otherwise it has the name of this channel * @param {Object} [options] The options
* @param {boolean} [withPermissions=true] Whether to clone the channel with this channel's permission overwrites * @param {string} [options.name=this.name] Optional name for the new channel, otherwise it has the name
* @param {boolean} [withTopic=true] Whether to clone the channel with this channel's topic * of this channel
* @param {boolean} [options.withPermissions=true] Whether to clone the channel with this channel's
* permission overwrites
* @param {boolean} [options.withTopic=true] Whether to clone the channel with this channel's topic
* @param {string} [options.reason] Reason for cloning this channel
* @returns {Promise<GuildChannel>} * @returns {Promise<GuildChannel>}
*/ */
clone(name = this.name, withPermissions = true, withTopic = true) { clone({ name = this.name, withPermissions = true, withTopic = true, reason } = {}) {
return this.guild.createChannel(name, this.type, { overwrites: withPermissions ? this.permissionOverwrites : [] }) const options = { overwrites: withPermissions ? this.permissionOverwrites : [], reason };
return this.guild.createChannel(name, this.type, options)
.then(channel => withTopic ? channel.setTopic(this.topic) : channel); .then(channel => withTopic ? channel.setTopic(this.topic) : channel);
} }

View File

@@ -218,6 +218,7 @@ class Role {
/** /**
* Set a new name for the role. * Set a new name for the role.
* @param {string} name The new name of the role * @param {string} name The new name of the role
* @param {string} [reason] Reason for changing the role's name
* @returns {Promise<Role>} * @returns {Promise<Role>}
* @example * @example
* // Set the name of the role * // Set the name of the role
@@ -225,13 +226,14 @@ class Role {
* .then(r => console.log(`Edited name of role ${r}`)) * .then(r => console.log(`Edited name of role ${r}`))
* .catch(console.error); * .catch(console.error);
*/ */
setName(name) { setName(name, reason) {
return this.edit({ name }); return this.edit({ name }, reason);
} }
/** /**
* Set a new color for the role. * Set a new color for the role.
* @param {ColorResolvable} color The color of the role * @param {ColorResolvable} color The color of the role
* @param {string} [reason] Reason for changing the role's color
* @returns {Promise<Role>} * @returns {Promise<Role>}
* @example * @example
* // Set the color of a role * // Set the color of a role
@@ -239,13 +241,14 @@ class Role {
* .then(r => console.log(`Set color of role ${r}`)) * .then(r => console.log(`Set color of role ${r}`))
* .catch(console.error); * .catch(console.error);
*/ */
setColor(color) { setColor(color, reason) {
return this.edit({ color }); return this.edit({ color }, reason);
} }
/** /**
* Set whether or not the role should be hoisted. * Set whether or not the role should be hoisted.
* @param {boolean} hoist Whether or not to hoist the role * @param {boolean} hoist Whether or not to hoist the role
* @param {string} [reason] Reason for setting whether or not the role should be hoisted
* @returns {Promise<Role>} * @returns {Promise<Role>}
* @example * @example
* // Set the hoist of the role * // Set the hoist of the role
@@ -253,8 +256,8 @@ class Role {
* .then(r => console.log(`Role hoisted: ${r.hoist}`)) * .then(r => console.log(`Role hoisted: ${r.hoist}`))
* .catch(console.error); * .catch(console.error);
*/ */
setHoist(hoist) { setHoist(hoist, reason) {
return this.edit({ hoist }); return this.edit({ hoist }, reason);
} }
/** /**
@@ -275,6 +278,7 @@ class Role {
/** /**
* Set the permissions of the role. * Set the permissions of the role.
* @param {string[]} permissions The permissions of the role * @param {string[]} permissions The permissions of the role
* @param {string} [reason] Reason for changing the role's permissions
* @returns {Promise<Role>} * @returns {Promise<Role>}
* @example * @example
* // Set the permissions of the role * // Set the permissions of the role
@@ -282,13 +286,14 @@ class Role {
* .then(r => console.log(`Role updated ${r}`)) * .then(r => console.log(`Role updated ${r}`))
* .catch(console.error); * .catch(console.error);
*/ */
setPermissions(permissions) { setPermissions(permissions, reason) {
return this.edit({ permissions }); return this.edit({ permissions }, reason);
} }
/** /**
* Set whether this role is mentionable. * Set whether this role is mentionable.
* @param {boolean} mentionable Whether this role should be mentionable * @param {boolean} mentionable Whether this role should be mentionable
* @param {string} [reason] Reason for setting whether or not this role should be mentionable
* @returns {Promise<Role>} * @returns {Promise<Role>}
* @example * @example
* // Make the role mentionable * // Make the role mentionable
@@ -296,8 +301,8 @@ class Role {
* .then(r => console.log(`Role updated ${r}`)) * .then(r => console.log(`Role updated ${r}`))
* .catch(console.error); * .catch(console.error);
*/ */
setMentionable(mentionable) { setMentionable(mentionable, reason) {
return this.edit({ mentionable }); return this.edit({ mentionable }, reason);
} }
/** /**

View File

@@ -66,17 +66,18 @@ class TextChannel extends GuildChannel {
* Create a webhook for the channel. * Create a webhook for the channel.
* @param {string} name The name of the webhook * @param {string} name The name of the webhook
* @param {BufferResolvable|Base64Resolvable} avatar The avatar for the webhook * @param {BufferResolvable|Base64Resolvable} avatar The avatar for the webhook
* @param {string} [reason] Reason for creating this webhook
* @returns {Promise<Webhook>} webhook The created webhook * @returns {Promise<Webhook>} webhook The created webhook
* @example * @example
* channel.createWebhook('Snek', 'http://snek.s3.amazonaws.com/topSnek.png') * channel.createWebhook('Snek', 'http://snek.s3.amazonaws.com/topSnek.png')
* .then(webhook => console.log(`Created webhook ${webhook}`)) * .then(webhook => console.log(`Created webhook ${webhook}`))
* .catch(console.error) * .catch(console.error)
*/ */
createWebhook(name, avatar) { createWebhook(name, avatar, reason) {
if (typeof avatar === 'string' && avatar.startsWith('data:')) { if (typeof avatar === 'string' && avatar.startsWith('data:')) {
return this.client.api.channels[this.id].webhooks.post({ data: { return this.client.api.channels[this.id].webhooks.post({ data: {
name, avatar, name, avatar,
} }).then(data => new Webhook(this.client, data)); }, reason }).then(data => new Webhook(this.client, data));
} else { } else {
return this.client.resolver.resolveBuffer(avatar).then(data => return this.client.resolver.resolveBuffer(avatar).then(data =>
this.createWebhook(name, this.client.resolver.resolveBase64(data) || null)); this.createWebhook(name, this.client.resolver.resolveBase64(data) || null));

View File

@@ -79,6 +79,7 @@ class VoiceChannel extends GuildChannel {
/** /**
* Sets the bitrate of the channel (in kbps). * Sets the bitrate of the channel (in kbps).
* @param {number} bitrate The new bitrate * @param {number} bitrate The new bitrate
* @param {string} [reason] Reason for changing the channel's bitrate
* @returns {Promise<VoiceChannel>} * @returns {Promise<VoiceChannel>}
* @example * @example
* // Set the bitrate of a voice channel * // Set the bitrate of a voice channel
@@ -86,14 +87,15 @@ class VoiceChannel extends GuildChannel {
* .then(vc => console.log(`Set bitrate to ${vc.bitrate}kbps for ${vc.name}`)) * .then(vc => console.log(`Set bitrate to ${vc.bitrate}kbps for ${vc.name}`))
* .catch(console.error); * .catch(console.error);
*/ */
setBitrate(bitrate) { setBitrate(bitrate, reason) {
bitrate *= 1000; bitrate *= 1000;
return this.edit({ bitrate }); return this.edit({ bitrate }, reason);
} }
/** /**
* Sets the user limit of the channel. * Sets the user limit of the channel.
* @param {number} userLimit The new user limit * @param {number} userLimit The new user limit
* @param {string} [reason] Reason for changing the user limit
* @returns {Promise<VoiceChannel>} * @returns {Promise<VoiceChannel>}
* @example * @example
* // Set the user limit of a voice channel * // Set the user limit of a voice channel
@@ -101,8 +103,8 @@ class VoiceChannel extends GuildChannel {
* .then(vc => console.log(`Set user limit to ${vc.userLimit} for ${vc.name}`)) * .then(vc => console.log(`Set user limit to ${vc.userLimit} for ${vc.name}`))
* .catch(console.error); * .catch(console.error);
*/ */
setUserLimit(userLimit) { setUserLimit(userLimit, reason) {
return this.edit({ userLimit }); return this.edit({ userLimit }, reason);
} }
/** /**