Interval discord activities, support cross-shard guild fetching for activities, and allow for expandability for more statuses.

This commit is contained in:
nolan 2021-06-17 22:07:11 -07:00
parent a4216cba59
commit d6337126c0

View File

@ -48,8 +48,13 @@ class DiscordClient extends Client {
process.on('message', this._handleMessage.bind(this)); process.on('message', this._handleMessage.bind(this));
if (this._options.libDebug) this.on('debug', this.logger.debug.bind(this.logger)); if (this._options.libDebug) this.on('debug', this.logger.debug.bind(this.logger));
this.on('ready', () => {
this.user.setActivity(`over ${this.guilds.cache.size} servers.`, { type: 'WATCHING' }); this._activity = 0;
this.once('ready', () => {
this._setActivity();
this.setInterval(this._setActivity, 1800000); // I think this is 30 minutes. I could be wrong.
}); });
} }
@ -183,7 +188,24 @@ class DiscordClient extends Client {
return this.storageManager; return this.storageManager;
} }
async aggregateStatistics() { async _setActivity() {
const activities = {
0: async () => {
const guildCount = (await this.shard.broadcastEval('this.guilds.cache.size')).reduce((p, v) => p+v, 0);
this.user.setActivity(`${guildCount} servers`, { type: 'WATCHING' });
},
1: async () => {
const userCount = (await this.shard.broadcastEval('this.users.cache.size')).reduce((p, v) => p+v, 0);
this.user.setActivity(`to ${userCount} users`, { type: 'LISTENING' });
},
2: async () => {
this.user.setActivity("to -help", { type: 'LISTENING' });
}
};
await activities[this._activity]();
if(this._activity === Math.max(...Object.keys(activities))) this._activity = 0;
else this._activity++;
} }