Rebuilt lib for dev and getInvite

This commit is contained in:
abalabahaha
2016-01-02 18:24:55 -08:00
parent 9c8e6eed24
commit 718f0b9543
29 changed files with 5104 additions and 248 deletions

View File

@@ -337,6 +337,12 @@ export default class Client extends EventEmitter {
.then(dataCallback(callback), errorCallback(callback));
}
// def getInvite
getInvite(invite, callback = (/*err, inv*/) => { }) {
return this.internal.getInvite(invite)
.then(dataCallback(callback), errorCallback(callback));
}
// def overwritePermissions
overwritePermissions(channel, role, options = {}, callback = (/*err, {}*/) => { }) {
return this.internal.overwritePermissions(channel, role, options)

View File

@@ -255,12 +255,12 @@ export default class InternalClient {
if(!invite) {
return Promise.reject(new Error("Not a valid invite"));
}
return this.apiRequest("post", Endpoints.INVITE(invite), true)
.then(res => {
// valid server, wait until it is received via ws and cached
return waitFor(() => this.servers.get("id", res.guild.id));
});
}
//def leaveServer
@@ -762,7 +762,6 @@ export default class InternalClient {
//def deleteInvite
deleteInvite(invite) {
invite = this.resolver.resolveInviteID(invite);
if(!invite) {
throw new Error("Not a valid invite");
@@ -770,6 +769,17 @@ export default class InternalClient {
return this.apiRequest("del", Endpoints.INVITE(invite), true);
}
//def getInvite
getInvite(invite) {
invite = this.resolver.resolveInviteID(invite);
if(!invite) {
return Promise.reject(new Error("Not a valid invite"));
}
return this.apiRequest("get", Endpoints.INVITE(invite), true)
.then(res => new Invite(res, this.channels.get("id", res.channel.id), this.client));
}
//def overwritePermissions
overwritePermissions(channel, role, updated) {
return this.resolver.resolveChannel(channel)

View File

@@ -4,14 +4,21 @@ export default class Invite {
constructor(data, chan, client){
this.maxAge = data.max_age;
this.code = data.code;
this.server = chan.server;
this.channel = chan;
if (data.chan) {
this.channel = chan;
this.server = chan.server;
} else {
this.channel = data.channel;
this.server = data.guild;
}
this.revoked = data.revoked;
this.createdAt = Date.parse(data.created_at);
this.temporary = data.temporary;
this.uses = data.uses;
this.maxUses = data.uses;
this.inviter = client.internal.users.get("id", data.inviter.id);
this.maxUses = data.max_uses;
if (data.inviter) {
this.inviter = client.internal.users.get("id", data.inviter.id);
}
this.xkcd = data.xkcdpass;
}