mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
About to start caching finalised classes
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
//discord.js modules
|
//discord.js modules
|
||||||
var Endpoints = require("./Endpoints.js");
|
var Endpoints = require("./Endpoints.js");
|
||||||
var User = require("./User.js");
|
var User = require("./User.js");
|
||||||
|
var Server = require("./Server.js");
|
||||||
|
var Channel = require("./Channel.js");
|
||||||
|
|
||||||
//node modules
|
//node modules
|
||||||
var request = require("superagent");
|
var request = require("superagent");
|
||||||
@@ -151,6 +153,34 @@ class Client {
|
|||||||
}
|
}
|
||||||
return this.userCache.get(data.id);
|
return this.userCache.get(data.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//def addChannel
|
||||||
|
addChannel(data) {
|
||||||
|
if (!this.channelCache.has(data.id)){
|
||||||
|
this.channelCache.set(data.id, new Channel(data, SERVER));
|
||||||
|
}
|
||||||
|
return this.channelCache.get(data.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
//def addServer
|
||||||
|
addServer(data){
|
||||||
|
if(!this.serverCache.has(data.id)){
|
||||||
|
this.serverCache.set(data.id, new Server(data, this));
|
||||||
|
}
|
||||||
|
return this.serverCache.get(data.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
//def getUser
|
||||||
|
getUser(key, value){
|
||||||
|
for (var userRow of this.userCache) {
|
||||||
|
var user = userRow[1];
|
||||||
|
if (user[key] === value) {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
//def trySendConnData
|
//def trySendConnData
|
||||||
trySendConnData() {
|
trySendConnData() {
|
||||||
|
|||||||
@@ -1,28 +1,21 @@
|
|||||||
var List = require("./list.js").List;
|
class Channel {
|
||||||
|
|
||||||
exports.Channel = function(name, server, type, id, isPrivate){
|
constructor(data, server) {
|
||||||
|
this.server = server;
|
||||||
if(!type){ //there's no second argument
|
this.name = data.name;
|
||||||
var channel = name;
|
this.type = data.type;
|
||||||
name = channel.name;
|
this.id = data.id;
|
||||||
server = server;
|
//this.isPrivate = isPrivate; //not sure about the implementation of this...
|
||||||
type = channel.type;
|
}
|
||||||
id = channel.id;
|
|
||||||
isPrivate = channel.is_private;
|
get client() {
|
||||||
|
return this.server.client;
|
||||||
|
}
|
||||||
|
|
||||||
|
equals(object) {
|
||||||
|
return object.id === this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.name = name;
|
|
||||||
this.server = server;
|
|
||||||
this.type = type;
|
|
||||||
this.id = id;
|
|
||||||
this.isPrivate = isPrivate;
|
|
||||||
this.messages = new List("id", 5000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Channel.equals = function(otherChannel){
|
module.exports = Channel;
|
||||||
if(otherChannel.id === this.id){
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -44,6 +44,10 @@ class Server {
|
|||||||
return this.getChannel("name", "general");
|
return this.getChannel("name", "general");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get owner() {
|
||||||
|
return this.client.getUser("id", this.ownerID);
|
||||||
|
}
|
||||||
|
|
||||||
// get/set
|
// get/set
|
||||||
getChannel(key, value) {
|
getChannel(key, value) {
|
||||||
for (var channel of this.channels) {
|
for (var channel of this.channels) {
|
||||||
|
|||||||
Reference in New Issue
Block a user