mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
Fixed invites
This commit is contained in:
@@ -4,6 +4,7 @@ var User = require("./User.js");
|
||||
var Server = require("./Server.js");
|
||||
var Channel = require("./Channel.js");
|
||||
var Message = require("./Message.js");
|
||||
var Invite = require("./Invite.js");
|
||||
|
||||
//node modules
|
||||
var request = require("superagent");
|
||||
@@ -262,6 +263,46 @@ class Client {
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
createInvite(serverOrChannel, options, callback = function (err, invite) { }) {
|
||||
|
||||
var self = this;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
var destination;
|
||||
|
||||
if (serverOrChannel instanceof Server) {
|
||||
destination = serverOrChannel.id;
|
||||
} else if (serverOrChannel instanceof Channel) {
|
||||
destination = serverOrChannel.id;
|
||||
} else {
|
||||
destination = serverOrChannel;
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
options.max_age = options.maxAge || 0;
|
||||
options.max_uses = options.maxUses || 0;
|
||||
options.temporary = options.temporary || false;
|
||||
options.xkcdpass = options.xkcd || false;
|
||||
|
||||
request
|
||||
.post(`${Endpoints.CHANNELS}/${destination}/invites`)
|
||||
.set("authorization", self.token)
|
||||
.send(options)
|
||||
.end(function (err, res) {
|
||||
if(err){
|
||||
callback(err);
|
||||
reject(err);
|
||||
}else{
|
||||
var inv = new Invite(res.body, self);
|
||||
callback(null, inv);
|
||||
resolve(inv);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//def createws
|
||||
createws() {
|
||||
@@ -423,9 +464,15 @@ class Client {
|
||||
|
||||
if (!server) {
|
||||
//if server doesn't already exist because duh
|
||||
|
||||
var serv = self.addServer(data);
|
||||
|
||||
}else if(server.channels.length === 0){
|
||||
|
||||
var srv = new Server(data, self);
|
||||
for(channel of data.channels){
|
||||
srv.channels.push(new Channel(channel, data.id));
|
||||
}
|
||||
self.serverCache[self.serverCache.indexOf(server)] = srv;
|
||||
|
||||
}
|
||||
|
||||
self.trigger("serverCreate", server);
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
var User = require("./user.js").User;
|
||||
|
||||
exports.Invite = function(json){
|
||||
class Invite {
|
||||
constructor(data, client) {
|
||||
this.max_age = data.max_age;
|
||||
this.code = data.code;
|
||||
this.server = client.getServer("id", data.guild.id);
|
||||
this.revoked = data.revoked;
|
||||
this.created_at = Date.parse(data.created_at);
|
||||
this.temporary = data.temporary;
|
||||
this.uses = data.uses;
|
||||
this.max_uses = data.uses;
|
||||
this.inviter = client.addUser(data.inviter);
|
||||
this.xkcd = data.xkcdpass;
|
||||
this.channel = client.getChannel("id", data.channel.id);
|
||||
}
|
||||
|
||||
this.max_age = json.max_age;
|
||||
this.code = json.code;
|
||||
this.server = json.guild;
|
||||
this.revoked = json.revoked;
|
||||
this.created_at = Date.parse(json.created_at);
|
||||
this.temporary = json.temporary;
|
||||
this.uses = json.uses;
|
||||
this.max_uses = json.uses;
|
||||
this.inviter = new User(json.inviter);
|
||||
this.xkcdpass = json.xkcdpass;
|
||||
this.channel = json.channel;
|
||||
get inviteURL() {
|
||||
var code = (this.xkcd ? this.xkcdpass : this.code);
|
||||
return "https://discord.gg/" + code;
|
||||
}
|
||||
}
|
||||
|
||||
exports.Invite.prototype.generateInviteURL = function(xkcd){
|
||||
var code = (xkcd ? this.xkcdpass : this.code);
|
||||
return "https://discord.gg/"+code;
|
||||
}
|
||||
module.exports = Invite;
|
||||
@@ -17,13 +17,14 @@ class Server {
|
||||
}
|
||||
|
||||
for (var member of data.members) {
|
||||
|
||||
|
||||
// first we cache the user in our Discord Client,
|
||||
// then we add it to our list. This way when we
|
||||
// get a user from this server's member list,
|
||||
// it will be identical (unless an async change occurred)
|
||||
// to the client's cache.
|
||||
this.members.push(client.addUser(member.user));
|
||||
if(member.user)
|
||||
this.members.push(client.addUser(member.user));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user