forked from timotejroiko/discord.js-light
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
44 lines (41 loc) · 1.5 KB
/
client.js
File metadata and controls
44 lines (41 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use strict";
require("./init.js");
const Discord = require("./classes.js");
const handlers = require("./actions.js");
const pkg = require("./package.json");
Discord.Client = class Client extends Discord.Client {
constructor(_options = {}) {
const options = {
cacheChannels: false,
cacheGuilds: true,
cachePresences: false,
cacheRoles: false,
cacheOverwrites: false,
cacheEmojis: false,
cacheMembers: false,
disabledEvents: [],
messageEditHistoryMaxSize: 1,
..._options
};
super(options);
handlers(this);
}
sweepUsers(_lifetime = 86400) {
const lifetime = _lifetime * 1000;
this.users.cache.sweep(t => t.id !== this.user.id && (!t.lastMessageID || Date.now() - Discord.SnowflakeUtil.deconstruct(t.lastMessageID).timestamp > lifetime));
for(const guild of this.guilds.cache.values()) {
guild.members.cache.sweep(t => !this.users.cache.has(t.id));
guild.presences.cache.sweep(t => !this.users.cache.has(t.id) && !this.options.cachePresences);
}
}
sweepChannels(_lifetime = 86400) {
const lifetime = _lifetime * 1000;
if(this.options.cacheChannels) { return; }
const connections = this.voice ? this.voice.connections.map(t => t.channel.id) : [];
this.channels.cache.sweep(t => !connections.includes(t.id) && (!t.lastMessageID || Date.now() - Discord.SnowflakeUtil.deconstruct(t.lastMessageID).timestamp > lifetime));
for(const guild of this.guilds.cache.values()) {
guild.channels.cache.sweep(t => !this.channels.cache.has(t.id));
}
}
};
module.exports = Discord;