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

This commit is contained in:
Amish Shah
2016-10-26 16:06:58 +01:00
5 changed files with 43 additions and 2 deletions

View File

@@ -8,6 +8,6 @@ install: npm install
script: bash ./docs/deploy/deploy.sh
env:
global:
- ENCRYPTION_LABEL: "be0b3b658a36"
- ENCRYPTION_LABEL: "af862fa96d3e"
- COMMIT_AUTHOR_EMAIL: "amishshah.2k@gmail.com"

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@@ -205,6 +205,26 @@ class RESTMethods {
});
}
createGuild(options) {
options.icon = this.rest.client.resolver.resolveBase64(options.icon) || null;
options.region = options.region || 'us-central';
return new Promise((resolve, reject) => {
this.rest.makeRequest('post', Constants.Endpoints.guilds, true, options)
.then(data => {
if (this.rest.client.guilds.has(data.id)) resolve(this.rest.client.guilds.get(data.id));
const handleGuild = guild => {
if (guild.id === data.id) resolve(guild);
this.rest.client.removeListener('guildCreate', handleGuild);
};
this.rest.client.on('guildCreate', handleGuild);
this.rest.client.setTimeout(() => {
this.rest.client.removeListener('guildCreate', handleGuild);
reject(new Error('Took too long to receive guild data'));
}, 10000);
}).catch(reject);
});
}
// untested but probably will work
deleteGuild(guild) {
return new Promise((resolve, reject) => {

View File

@@ -163,6 +163,27 @@ class ClientUser extends User {
return this.client.rest.methods.removeFriend(user);
}
/**
* Creates a guild
* <warn>This is only available for user accounts, not bot accounts!</warn>
* @param {string} name The name of the guild
* @param {string} region The region for the server
* @param {FileResolvable|Base64Resolvable} [icon=null] The icon for the guild
* @returns {Promise<Guild>} The guild that was created
*/
createGuild(name, region, icon = null) {
return new Promise(resolve => {
if (!icon) resolve(this.client.rest.methods.createGuild({ name, icon, region }));
if (icon.startsWith('data:')) {
resolve(this.client.rest.methods.createGuild({ name, icon, region }));
} else {
this.client.resolver.resolveFile(icon).then(data => {
resolve(this.client.rest.methods.createGuild({ name, icon: data, region }));
});
}
});
}
/**
* Set the full presence of the current user.
* @param {Object} data the data to provide