mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Client now emits unknown and hidden some properties of Cache
Cache.discrim and Cache.discrimCache are now hidden from for..in
This commit is contained in:
@@ -1548,6 +1548,9 @@ var InternalClient = (function () {
|
||||
client.emit("warn", "user unbanned but user/server not in cache.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
client.emit("unknown", packet);
|
||||
break;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1370,6 +1370,9 @@ export default class InternalClient {
|
||||
client.emit("warn", "user unbanned but user/server not in cache.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
client.emit("unknown", packet);
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
var discrimS = Symbol();
|
||||
var discrimCacheS = Symbol();
|
||||
|
||||
export default class Cache extends Array {
|
||||
constructor(discrim, limit) {
|
||||
super();
|
||||
this["discrim"] = discrim || "id";
|
||||
this["discrimCache"] = {};
|
||||
this[discrimS] = discrim || "id";
|
||||
this[discrimCacheS] = {};
|
||||
}
|
||||
|
||||
get(key, value) {
|
||||
if (key === this.discrim)
|
||||
return this.discrimCache[value] || null;
|
||||
if (key === this[discrimS])
|
||||
return this[discrimCacheS][value] || null;
|
||||
|
||||
var l = this.length;
|
||||
for (var i = 0; i < l; i++)
|
||||
@@ -19,11 +22,11 @@ export default class Cache extends Array {
|
||||
}
|
||||
|
||||
has(object) {
|
||||
return !!this.get(this.discrim, object[this.discrim]);
|
||||
return !!this.get(this[discrimS], object[this[discrimS]]);
|
||||
}
|
||||
|
||||
getAll(key, value) {
|
||||
var found = new Cache(this.discrim);
|
||||
var found = new Cache(this[discrimS]);
|
||||
this.forEach((val, index, array) => {
|
||||
if (val.hasOwnProperty(key) && val[key] == value) {
|
||||
found.push(val);
|
||||
@@ -34,24 +37,24 @@ export default class Cache extends Array {
|
||||
}
|
||||
|
||||
add(data) {
|
||||
var cacheKey = this.discrim === "id" ? data.id : data[this.discrim];
|
||||
if (this.discrimCache[cacheKey]) {
|
||||
return this.discrimCache[cacheKey];
|
||||
var cacheKey = this[discrimS] === "id" ? data.id : data[this[discrimS]];
|
||||
if (this[discrimCacheS][cacheKey]) {
|
||||
return this[discrimCacheS][cacheKey];
|
||||
}
|
||||
if (this.limit && this.length >= this.limit) {
|
||||
this.splice(0, 1);
|
||||
}
|
||||
this.push(data);
|
||||
this.discrimCache[cacheKey] = data;
|
||||
this[discrimCacheS][cacheKey] = data;
|
||||
return data;
|
||||
}
|
||||
|
||||
update(old, data) {
|
||||
var item = this.get(this.discrim, old[this.discrim]);
|
||||
var item = this.get(this[discrimS], old[this[discrimS]]);
|
||||
if (item) {
|
||||
var index = this.indexOf(item);
|
||||
this[index] = data;
|
||||
this.discrimCache[data[this.discrim]] = this[index];
|
||||
this[discrimCacheS][data[this[discrimS]]] = this[index];
|
||||
return this[index];
|
||||
} else {
|
||||
return false;
|
||||
@@ -63,12 +66,12 @@ export default class Cache extends Array {
|
||||
}
|
||||
|
||||
remove(data) {
|
||||
delete this.discrimCache[data[this.discrim]];
|
||||
delete this[discrimCacheS][data[this[discrimS]]];
|
||||
var index = this.indexOf(data);
|
||||
if (~index) {
|
||||
this.splice(index, 1);
|
||||
} else {
|
||||
var item = this.get(this.discrim, data[this.discrim]);
|
||||
var item = this.get(this[discrimS], data[this[discrimS]]);
|
||||
if (item) {
|
||||
this.splice(this.indexOf(item), 1);
|
||||
}
|
||||
|
||||
@@ -7,15 +7,9 @@ var request = require("superagent");
|
||||
|
||||
client.on("ready", () => {
|
||||
console.log("ready");
|
||||
for (var server of client.servers) {
|
||||
if (!(server instanceof Discord.Server)) {
|
||||
console.log("FOUNDED");
|
||||
}
|
||||
for (var server in client.servers) {
|
||||
console.log(server);
|
||||
}
|
||||
setTimeout(() => {
|
||||
if(client.internal.websocket)
|
||||
client.internal.websocket.close();
|
||||
}, 5000);
|
||||
|
||||
});
|
||||
|
||||
@@ -53,7 +47,11 @@ client.on("message", msg => {
|
||||
|
||||
console.log("INIT");
|
||||
|
||||
client.on("debug", console.log)
|
||||
client.on("debug", console.log);
|
||||
|
||||
client.on("unknown", p => {
|
||||
console.log(p);
|
||||
});
|
||||
|
||||
client.login(process.env["ds_email"], process.env["ds_password"]).catch(console.log);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user