Merge branch 'master' into indev-prism

This commit is contained in:
Amish Shah
2017-01-15 14:20:32 +00:00
8 changed files with 82 additions and 20 deletions

View File

@@ -287,11 +287,12 @@ class Client extends EventEmitter {
* Caches a user, or obtains it from the cache if it's already cached.
* <warn>This is only available when using a bot account.</warn>
* @param {string} id The ID of the user to obtain
* @param {boolean} [cache=true] Insert the user into the users cache
* @returns {Promise<User>}
*/
fetchUser(id) {
fetchUser(id, cache = true) {
if (this.users.has(id)) return Promise.resolve(this.users.get(id));
return this.rest.methods.getUser(id);
return this.rest.methods.getUser(id, cache);
}
/**

View File

@@ -12,7 +12,9 @@ class GuildDeleteAction extends Action {
let guild = client.guilds.get(data.id);
if (guild) {
for (const channel of guild.channels.values()) channel.stopTyping(true);
for (const channel of guild.channels.values()) {
if (channel.type === 'text') channel.stopTyping(true);
}
if (guild.available && data.unavailable) {
// guild is unavailable

View File

@@ -5,6 +5,7 @@ const splitMessage = require('../../util/SplitMessage');
const parseEmoji = require('../../util/ParseEmoji');
const escapeMarkdown = require('../../util/EscapeMarkdown');
const transformSearchOptions = require('../../util/TransformSearchOptions');
const Snowflake = require('../../util/Snowflake');
const User = require('../../structures/User');
const GuildMember = require('../../structures/GuildMember');
@@ -136,7 +137,12 @@ class RESTMethods {
);
}
bulkDeleteMessages(channel, messages) {
bulkDeleteMessages(channel, messages, filterOld) {
if (filterOld) {
messages = messages.filter(id =>
Date.now() - Snowflake.deconstruct(id).date.getTime() < 1209600000
);
}
return this.rest.makeRequest('post', `${Constants.Endpoints.channelMessages(channel.id)}/bulk_delete`, true, {
messages,
}).then(() =>
@@ -258,10 +264,14 @@ class RESTMethods {
);
}
getUser(userID) {
return this.rest.makeRequest('get', Constants.Endpoints.user(userID), true).then(data =>
this.client.actions.UserGet.handle(data).user
);
getUser(userID, cache) {
return this.rest.makeRequest('get', Constants.Endpoints.user(userID), true).then(data => {
if (cache) {
return this.client.actions.UserGet.handle(data).user;
} else {
return new User(this.client, data);
}
});
}
updateCurrentUser(_data, password) {
@@ -351,10 +361,14 @@ class RESTMethods {
return this.rest.makeRequest('get', Constants.Endpoints.channelMessage(channel.id, messageID), true);
}
getGuildMember(guild, user) {
return this.rest.makeRequest('get', Constants.Endpoints.guildMember(guild.id, user.id), true).then(data =>
this.client.actions.GuildMemberGet.handle(guild, data).member
);
getGuildMember(guild, user, cache) {
return this.rest.makeRequest('get', Constants.Endpoints.guildMember(guild.id, user.id), true).then(data => {
if (cache) {
return this.client.actions.GuildMemberGet.handle(guild, data).member;
} else {
return new GuildMember(guild, data);
}
});
}
updateGuildMember(member, data) {
@@ -701,6 +715,25 @@ class RESTMethods {
setNote(user, note) {
return this.rest.makeRequest('put', Constants.Endpoints.note(user.id), true, { note }).then(() => user);
}
acceptInvite(code) {
if (code.id) code = code.id;
return new Promise((resolve, reject) =>
this.rest.makeRequest('post', Constants.Endpoints.invite(code), true).then((res) => {
const handler = guild => {
if (guild.id === res.id) {
resolve(guild);
this.client.removeListener('guildCreate', handler);
}
};
this.client.on('guildCreate', handler);
this.client.setTimeout(() => {
this.client.removeListener('guildCreate', handler);
reject(new Error('Accepting invite timed out'));
}, 120e3);
})
);
}
}
module.exports = RESTMethods;

View File

@@ -79,7 +79,13 @@ class ClientVoiceManager {
joinChannel(channel) {
return new Promise((resolve, reject) => {
if (this.pending.get(channel.guild.id)) throw new Error('Already connecting to this guild\'s voice server.');
if (!channel.joinable) throw new Error('You do not have permission to join this voice channel.');
if (!channel.joinable) {
if (channel.full) {
throw new Error('You do not have permission to join this voice channel; it is full.');
} else {
throw new Error('You do not have permission to join this voice channel.');
}
}
const existingConnection = this.connections.get(channel.guild.id);
if (existingConnection) {