Merge branch 'indev-rewrite' of https://github.com/hydrabolt/discord.js into indev-rewrite

This commit is contained in:
Amish Shah
2016-08-27 15:41:42 +01:00
5 changed files with 43 additions and 4 deletions

View File

@@ -135,6 +135,16 @@ class Client extends EventEmitter {
return this.rest.methods.loginToken(email);
}
/**
* Forces a user to be cached.
* @param {String} id The ID of the user to cache
* @return {Promise<User>}
*/
cacheUser(id) {
if (this.users.has(id)) return Promise.resolve(this.users.get(id));
return this.rest.methods.getUser(id);
}
/**
* Returns a Collection, mapping Guild ID to Voice Connections.
* @readonly

View File

@@ -17,6 +17,7 @@ class ActionsManager {
this.register('GuildRoleCreate');
this.register('GuildRoleDelete');
this.register('GuildRoleUpdate');
this.register('UserGet');
this.register('UserUpdate');
}

View File

@@ -0,0 +1,15 @@
const Action = require('./Action');
class UserGetAction extends Action {
handle(data) {
const client = this.client;
const user = client.dataManager.newUser(data);
return {
user,
};
}
}
module.exports = UserGetAction;

View File

@@ -193,6 +193,16 @@ class RESTMethods {
});
}
getUser(userID) {
return new Promise((resolve, reject) => {
this.rest.makeRequest('get', Constants.Endpoints.user(userID), true)
.then((data) => {
resolve(this.rest.client.actions.UserGet.handle(data).user);
})
.catch(reject);
});
}
updateCurrentUser(_data) {
return new Promise((resolve, reject) => {
const user = this.rest.client.user;

View File

@@ -75,12 +75,15 @@ const Endpoints = exports.Endpoints = {
// general endpoints
login: `${API}/auth/login`,
logout: `${API}/auth/logout`,
gateway: `${API}/gateway`,
invite: (id) => `${API}/invite/${id}`,
// users
user: (userID) => `${API}/users/${userID}`,
userChannels: (userID) => `${Endpoints.user(userID)}/channels`,
avatar: (userID, avatar) => `${Endpoints.user(userID)}/avatars/${avatar}.jpg`,
me: `${API}/users/@me`,
meGuild: (guildID) => `${Endpoints.me}/guilds/${guildID}`,
gateway: `${API}/gateway`,
userChannels: (userID) => `${API}/users/${userID}/channels`,
avatar: (userID, avatar) => `${API}/users/${userID}/avatars/${avatar}.jpg`,
invite: (id) => `${API}/invite/${id}`,
// guilds
guilds: `${API}/guilds`,