This commit is contained in:
Travis CI 2016-12-30 21:51:26 +00:00
parent 7b8260eced
commit a090ada9ca
2 changed files with 71 additions and 75 deletions

View file

@ -2730,7 +2730,7 @@ class TextBasedChannel {
} }
/** /**
* Performs a search * Performs a search within the channel.
* @param {MessageSearchOptions} [options={}] Options to pass to the search * @param {MessageSearchOptions} [options={}] Options to pass to the search
* @returns {Promise<Array<Message[]>>} * @returns {Promise<Array<Message[]>>}
* An array containing arrays of messages. Each inner array is a search context cluster. * An array containing arrays of messages. Each inner array is a search context cluster.
@ -2739,12 +2739,10 @@ class TextBasedChannel {
* channel.search({ * channel.search({
* content: 'discord.js', * content: 'discord.js',
* before: '2016-11-17' * before: '2016-11-17'
* }) * }).then(res => {
* .then(res => {
* const hit = res[0].find(m => m.hit).content; * const hit = res[0].find(m => m.hit).content;
* console.log(`I found: **${hit}**`); * console.log(`I found: **${hit}**`);
* }) * }).catch(console.error);
* .catch(console.error);
*/ */
search(options) { search(options) {
return this.client.rest.methods.search(this, options); return this.client.rest.methods.search(this, options);
@ -3282,6 +3280,25 @@ class Guild {
}); });
} }
/**
* Performs a search within the entire guild.
* @param {MessageSearchOptions} [options={}] Options to pass to the search
* @returns {Promise<Array<Message[]>>}
* An array containing arrays of messages. Each inner array is a search context cluster.
* The message which has triggered the result will have the `hit` property set to `true`.
* @example
* guild.search({
* content: 'discord.js',
* before: '2016-11-17'
* }).then(res => {
* const hit = res[0].find(m => m.hit).content;
* console.log(`I found: **${hit}**`);
* }).catch(console.error);
*/
search(options) {
return this.client.rest.methods.search(this, options);
}
/** /**
* The data for editing a guild * The data for editing a guild
* @typedef {Object} GuildEditData * @typedef {Object} GuildEditData
@ -3520,9 +3537,48 @@ class Guild {
return create.then(role => role.edit(data)); return create.then(role => role.edit(data));
} }
/**
* Set the position of a role in this guild
* @param {string|Role} role the role to edit, can be a role object or a role ID.
* @param {number} position the new position of the role
* @returns {Promise<Guild>}
*/
setRolePosition(role, position) {
if (typeof role === 'string') {
role = this.roles.get(role);
if (!role) return Promise.reject(new Error('Supplied role is not a role or string.'));
}
position = Number(position);
if (isNaN(position)) return Promise.reject(new Error('Supplied position is not a number.'));
const lowestAffected = Math.min(role.position, position);
const highestAffected = Math.max(role.position, position);
const rolesToUpdate = this.roles.filter(r => r.position >= lowestAffected && r.position <= highestAffected);
// stop role positions getting stupidly inflated
if (position > role.position) {
position = rolesToUpdate.first().position;
} else {
position = rolesToUpdate.last().position;
}
const updatedRoles = [];
for (const uRole of rolesToUpdate.values()) {
updatedRoles.push({
id: uRole.id,
position: uRole.id === role.id ? position : uRole.position + (position < role.position ? 1 : -1),
});
}
return this.client.rest.methods.setRolePositions(this.id, updatedRoles);
}
/** /**
* Creates a new custom emoji in the guild. * Creates a new custom emoji in the guild.
* @param {BufferResolvable} 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.
* @returns {Promise<Emoji>} The created emoji. * @returns {Promise<Emoji>} The created emoji.
* @example * @example
@ -3538,7 +3594,7 @@ class Guild {
*/ */
createEmoji(attachment, name) { createEmoji(attachment, name) {
return new Promise(resolve => { return new Promise(resolve => {
if (attachment.startsWith('data:')) { if (typeof attachment === 'string' && attachment.startsWith('data:')) {
resolve(this.client.rest.methods.createEmoji(this, attachment, name)); resolve(this.client.rest.methods.createEmoji(this, attachment, name));
} else { } else {
this.client.resolver.resolveBuffer(attachment).then(data => this.client.resolver.resolveBuffer(attachment).then(data =>
@ -3584,66 +3640,6 @@ class Guild {
return this.client.rest.methods.deleteGuild(this); return this.client.rest.methods.deleteGuild(this);
} }
/**
* Set the position of a role in this guild
* @param {string|Role} role the role to edit, can be a role object or a role ID.
* @param {number} position the new position of the role
* @returns {Promise<Guild>}
*/
setRolePosition(role, position) {
if (typeof role === 'string') {
role = this.roles.get(role);
if (!role) return Promise.reject(new Error('Supplied role is not a role or string.'));
}
position = Number(position);
if (isNaN(position)) return Promise.reject(new Error('Supplied position is not a number.'));
const lowestAffected = Math.min(role.position, position);
const highestAffected = Math.max(role.position, position);
const rolesToUpdate = this.roles.filter(r => r.position >= lowestAffected && r.position <= highestAffected);
// stop role positions getting stupidly inflated
if (position > role.position) {
position = rolesToUpdate.first().position;
} else {
position = rolesToUpdate.last().position;
}
const updatedRoles = [];
for (const uRole of rolesToUpdate.values()) {
updatedRoles.push({
id: uRole.id,
position: uRole.id === role.id ? position : uRole.position + (position < role.position ? 1 : -1),
});
}
return this.client.rest.methods.setRolePositions(this.id, updatedRoles);
}
/**
* Performs a search
* @param {MessageSearchOptions} [options={}] Options to pass to the search
* @returns {Promise<Array<Message[]>>}
* An array containing arrays of messages. Each inner array is a search context cluster.
* The message which has triggered the result will have the `hit` property set to `true`.
* @example
* guild.search({
* content: 'discord.js',
* before: '2016-11-17'
* })
* .then(res => {
* const hit = res[0].find(m => m.hit).content;
* console.log(`I found: **${hit}**`);
* })
* .catch(console.error);
*/
search(options) {
return this.client.rest.methods.search(this, options);
}
/** /**
* Whether this Guild equals another Guild. It compares all properties, so for most operations * Whether this Guild equals another Guild. It compares all properties, so for most operations
* it is advisable to just compare `guild.id === guild2.id` as it is much faster and is often * it is advisable to just compare `guild.id === guild2.id` as it is much faster and is often
@ -8760,7 +8756,7 @@ class ClientUser extends User {
*/ */
createGuild(name, region, icon = null) { createGuild(name, region, icon = null) {
if (!icon) return this.client.rest.methods.createGuild({ name, icon, region }); if (!icon) return this.client.rest.methods.createGuild({ name, icon, region });
if (icon.startsWith('data:')) { if (typeof icon === 'string' && icon.startsWith('data:')) {
return this.client.rest.methods.createGuild({ name, icon, region }); return this.client.rest.methods.createGuild({ name, icon, region });
} else { } else {
return this.client.resolver.resolveBuffer(icon).then(data => return this.client.resolver.resolveBuffer(icon).then(data =>
@ -8824,6 +8820,7 @@ class DMChannel extends Channel {
fetchMessage() { return; } fetchMessage() { return; }
fetchMessages() { return; } fetchMessages() { return; }
fetchPinnedMessages() { return; } fetchPinnedMessages() { return; }
search() { return; }
startTyping() { return; } startTyping() { return; }
stopTyping() { return; } stopTyping() { return; }
get typing() { return; } get typing() { return; }
@ -8832,7 +8829,6 @@ class DMChannel extends Channel {
awaitMessages() { return; } awaitMessages() { return; }
bulkDelete() { return; } bulkDelete() { return; }
_cacheMessage() { return; } _cacheMessage() { return; }
search() { return; }
} }
TextBasedChannel.applyToClass(DMChannel, true); TextBasedChannel.applyToClass(DMChannel, true);
@ -8975,6 +8971,7 @@ class GroupDMChannel extends Channel {
fetchMessage() { return; } fetchMessage() { return; }
fetchMessages() { return; } fetchMessages() { return; }
fetchPinnedMessages() { return; } fetchPinnedMessages() { return; }
search() { return; }
startTyping() { return; } startTyping() { return; }
stopTyping() { return; } stopTyping() { return; }
get typing() { return; } get typing() { return; }
@ -8983,7 +8980,6 @@ class GroupDMChannel extends Channel {
awaitMessages() { return; } awaitMessages() { return; }
bulkDelete() { return; } bulkDelete() { return; }
_cacheMessage() { return; } _cacheMessage() { return; }
search() { return; }
} }
TextBasedChannel.applyToClass(GroupDMChannel, true); TextBasedChannel.applyToClass(GroupDMChannel, true);
@ -10087,7 +10083,7 @@ 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} avatar The avatar for the webhook. * @param {BufferResolvable|Base64Resolvable} avatar The avatar for the 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')
@ -10096,7 +10092,7 @@ class TextChannel extends GuildChannel {
*/ */
createWebhook(name, avatar) { createWebhook(name, avatar) {
return new Promise(resolve => { return new Promise(resolve => {
if (avatar.startsWith('data:')) { if (typeof avatar === 'string' && avatar.startsWith('data:')) {
resolve(this.client.rest.methods.createWebhook(this, name, avatar)); resolve(this.client.rest.methods.createWebhook(this, name, avatar));
} else { } else {
this.client.resolver.resolveBuffer(avatar).then(data => this.client.resolver.resolveBuffer(avatar).then(data =>
@ -10115,6 +10111,7 @@ class TextChannel extends GuildChannel {
fetchMessage() { return; } fetchMessage() { return; }
fetchMessages() { return; } fetchMessages() { return; }
fetchPinnedMessages() { return; } fetchPinnedMessages() { return; }
search() { return; }
startTyping() { return; } startTyping() { return; }
stopTyping() { return; } stopTyping() { return; }
get typing() { return; } get typing() { return; }
@ -10123,7 +10120,6 @@ class TextChannel extends GuildChannel {
awaitMessages() { return; } awaitMessages() { return; }
bulkDelete() { return; } bulkDelete() { return; }
_cacheMessage() { return; } _cacheMessage() { return; }
search() { return; }
} }
TextBasedChannel.applyToClass(TextChannel, true); TextBasedChannel.applyToClass(TextChannel, true);

File diff suppressed because one or more lines are too long