mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
Export command leaderboard every 30 minutes
This commit is contained in:
@@ -50,16 +50,22 @@ client.registry
|
||||
|
||||
client.on('ready', () => {
|
||||
client.logger.info(`[READY] Logged in as ${client.user.tag}! ID: ${client.user.id}`);
|
||||
|
||||
// Push client-related activities
|
||||
client.activities.push(
|
||||
{ text: () => `${formatNumber(client.guilds.cache.size)} servers`, type: 'WATCHING' },
|
||||
{ text: () => `with ${formatNumber(client.registry.commands.size)} commands`, type: 'PLAYING' },
|
||||
{ text: () => `${formatNumber(client.channels.cache.size)} channels`, type: 'WATCHING' }
|
||||
);
|
||||
|
||||
// Interval to change activity every minute
|
||||
client.setInterval(() => {
|
||||
const activity = client.activities[Math.floor(Math.random() * client.activities.length)];
|
||||
const text = typeof activity.text === 'function' ? activity.text() : activity.text;
|
||||
client.user.setActivity(text, { type: activity.type });
|
||||
}, 60000);
|
||||
|
||||
// Set up meme poster interval
|
||||
if (client.memePoster) {
|
||||
client.setInterval(async () => {
|
||||
try {
|
||||
@@ -70,12 +76,23 @@ client.on('ready', () => {
|
||||
}
|
||||
}, client.memePoster.postInterval);
|
||||
}
|
||||
|
||||
// Import command-leaderboard.json
|
||||
try {
|
||||
const results = client.importCommandLeaderboard();
|
||||
if (!results) client.logger.error('[LEADERBOARD] command-leaderboard.json is not formatted correctly.');
|
||||
} catch (err) {
|
||||
client.logger.error(`[LEADERBOARD] Could not parse command-leaderboard.json:\n${err.stack}`);
|
||||
}
|
||||
|
||||
// Export command-leaderboard.json every 30 minutes
|
||||
client.setInterval(() => {
|
||||
try {
|
||||
client.exportCommandLeaderboard();
|
||||
} catch (err) {
|
||||
client.logger.error(`[LEADERBOARD] Failed to export command-leaderboard.json:\n${err.stack}`);
|
||||
}
|
||||
}, 1.8e+6);
|
||||
});
|
||||
|
||||
client.on('message', async msg => {
|
||||
@@ -113,6 +130,7 @@ client.on('guildMemberRemove', async member => {
|
||||
|
||||
client.on('disconnect', event => {
|
||||
client.logger.error(`[DISCONNECT] Disconnected with code ${event.code}.`);
|
||||
client.exportCommandLeaderboard();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
|
||||
@@ -25,16 +25,7 @@ module.exports = class CommandLeaderboardExportCommand extends Command {
|
||||
}
|
||||
|
||||
run(msg) {
|
||||
let text = '{';
|
||||
for (const command of this.client.registry.commands.values()) {
|
||||
if (command.uses === undefined) continue;
|
||||
text += `"${command.name}":${command.uses},`;
|
||||
}
|
||||
text = text.slice(0, -1);
|
||||
text += '}';
|
||||
fs.writeFileSync(path.join(__dirname, '..', '..', 'command-leaderboard.json'), Buffer.from(text), {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
return msg.say({ files: [{ attachment: Buffer.from(text), name: 'command-leaderboard.json' }] });
|
||||
const result = this.client.exportCommandLeaderboard();
|
||||
return msg.say({ files: [{ attachment: result, name: 'command-leaderboard.json' }] });
|
||||
}
|
||||
};
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "116.1.6",
|
||||
"version": "116.1.7",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -54,4 +54,19 @@ module.exports = class XiaoClient extends CommandoClient {
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
exportCommandLeaderboard() {
|
||||
let text = '{';
|
||||
for (const command of this.registry.commands.values()) {
|
||||
if (command.uses === undefined) continue;
|
||||
text += `"${command.name}":${command.uses},`;
|
||||
}
|
||||
text = text.slice(0, -1);
|
||||
text += '}';
|
||||
const buf = Buffer.from(text);
|
||||
fs.writeFileSync(path.join(__dirname, '..', 'command-leaderboard.json'), buf, {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
return buf;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user