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