mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 01:53:30 +01:00
fixed how channels and users are cached
This commit is contained in:
@@ -175,14 +175,16 @@ class Client {
|
||||
|
||||
for(var _server of data.guilds){
|
||||
|
||||
self.addServer(_server);
|
||||
var server = self.addServer(_server);
|
||||
|
||||
for(var channel of _server.channels){
|
||||
server.channels.push( self.addChannel(channel, server.id) );
|
||||
}
|
||||
|
||||
}
|
||||
self.trigger("ready");
|
||||
self.debug(`cached ${self.serverCache.length} servers, ${self.channelCache.length} channels and ${self.userCache.length} users.`);
|
||||
|
||||
console.log(self.channelCache[0]);
|
||||
|
||||
setInterval(function () {
|
||||
self.keepAlive.apply(self);
|
||||
}, data.heartbeat_interval);
|
||||
|
||||
@@ -5,6 +5,7 @@ class Channel {
|
||||
this.name = data.name;
|
||||
this.type = data.type;
|
||||
this.id = data.id;
|
||||
this.messages = [];
|
||||
//this.isPrivate = isPrivate; //not sure about the implementation of this...
|
||||
}
|
||||
|
||||
@@ -15,6 +16,22 @@ class Channel {
|
||||
equals(object) {
|
||||
return object.id === this.id;
|
||||
}
|
||||
|
||||
addMessage(data){
|
||||
if(!this.getMessage("id", data.id)){
|
||||
this.messages.push(data);
|
||||
}
|
||||
return this.getMessage("id", data.id);
|
||||
}
|
||||
|
||||
getMessage(key, value){
|
||||
for(var message of this.messages){
|
||||
if(message[key] === value){
|
||||
return message;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ class Server {
|
||||
this.ownerID = data.owner_id;
|
||||
this.name = data.name;
|
||||
this.id = data.id;
|
||||
this.members = new Set();
|
||||
this.channels = new Set();
|
||||
this.members = [];
|
||||
this.channels = [];
|
||||
this.icon = data.icon;
|
||||
this.afkTimeout = data.afk_timeout;
|
||||
this.afkChannelId = data.afk_channel_id;
|
||||
@@ -18,13 +18,9 @@ class Server {
|
||||
// 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.add(client.addUser(member.user));
|
||||
this.members.push(client.addUser(member.user));
|
||||
|
||||
}
|
||||
|
||||
for (var channel of data.channels) {
|
||||
this.channels.add(client.addChannel(channel, this.id));
|
||||
}
|
||||
}
|
||||
|
||||
get iconURL() {
|
||||
|
||||
Reference in New Issue
Block a user