mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
Validate invite if possible
This commit is contained in:
@@ -929,7 +929,12 @@ var InternalClient = (function () {
|
||||
}
|
||||
|
||||
return this.apiRequest("get", _Constants.Endpoints.INVITE(invite), true).then(function (res) {
|
||||
return new _StructuresInvite2["default"](res, _this21.channels.get("id", res.channel.id), _this21.client);
|
||||
if (!_this21.channels.has("id", res.channel.id)) {
|
||||
return new _StructuresInvite2["default"](res, null, _this21.client);
|
||||
}
|
||||
return _this21.apiRequest("post", _Constants.Endpoints.CHANNEL_INVITES(res.channel.id), true, { validate: invite }).then(function (res2) {
|
||||
return new _StructuresInvite2["default"](res2, _this21.channels.get("id", res.channel.id), _this21.client);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ var Invite = (function () {
|
||||
|
||||
this.maxAge = data.max_age;
|
||||
this.code = data.code;
|
||||
if (data.chan) {
|
||||
if (chan) {
|
||||
this.channel = chan;
|
||||
this.server = chan.server;
|
||||
} else {
|
||||
|
||||
@@ -763,7 +763,7 @@ export default class InternalClient {
|
||||
//def deleteInvite
|
||||
deleteInvite(invite) {
|
||||
invite = this.resolver.resolveInviteID(invite);
|
||||
if(!invite) {
|
||||
if (!invite) {
|
||||
throw new Error("Not a valid invite");
|
||||
}
|
||||
return this.apiRequest("del", Endpoints.INVITE(invite), true);
|
||||
@@ -772,12 +772,18 @@ export default class InternalClient {
|
||||
//def getInvite
|
||||
getInvite(invite) {
|
||||
invite = this.resolver.resolveInviteID(invite);
|
||||
if(!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));
|
||||
.then(res => {
|
||||
if (!this.channels.has("id", res.channel.id)) {
|
||||
return new Invite(res, null, this.client);
|
||||
}
|
||||
return this.apiRequest("post", Endpoints.CHANNEL_INVITES(res.channel.id), true, {validate: invite})
|
||||
.then(res2 => new Invite(res2, this.channels.get("id", res.channel.id), this.client));
|
||||
});
|
||||
}
|
||||
|
||||
//def overwritePermissions
|
||||
|
||||
@@ -4,7 +4,7 @@ export default class Invite {
|
||||
constructor(data, chan, client){
|
||||
this.maxAge = data.max_age;
|
||||
this.code = data.code;
|
||||
if (data.chan) {
|
||||
if (chan) {
|
||||
this.channel = chan;
|
||||
this.server = chan.server;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user