mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-27 14:18:36 +02:00
Auto-Import Command Leaderboard
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = class CommandLeaderboardImportCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -20,36 +18,17 @@ module.exports = class CommandLeaderboardImportCommand extends Command {
|
||||
description: 'Imports a command leaderboard JSON file.',
|
||||
details: 'Only the bot owner(s) may use this command.',
|
||||
ownerOnly: true,
|
||||
guarded: true,
|
||||
args: [
|
||||
{
|
||||
key: 'file',
|
||||
prompt: 'What file do you want to provide?',
|
||||
type: 'json-file',
|
||||
default: ''
|
||||
}
|
||||
]
|
||||
guarded: true
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { file }) {
|
||||
if (!file) {
|
||||
try {
|
||||
const read = fs.readFileSync(path.join(__dirname, '..', '..', 'command-leaderboard.json'), {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
file = JSON.parse(read);
|
||||
} catch (err) {
|
||||
return msg.say(`Could not read \`command-leaderboard.json\`: \`${err.message}\`.`);
|
||||
}
|
||||
run(msg) {
|
||||
try {
|
||||
const results = this.client.importCommandLeaderboard();
|
||||
if (!results) return msg.reply('The JSON file provided is invalid.');
|
||||
return msg.say('Successfully imported command leaderboard.');
|
||||
} catch (err) {
|
||||
return msg.reply(`Could not read \`command-leaderboard.json\`: \`${err.message}\`.`);
|
||||
}
|
||||
if (typeof file !== 'object' || Array.isArray(file)) return msg.reply('Please provide a valid JSON file.');
|
||||
for (const [id, value] of Object.entries(file)) {
|
||||
if (typeof value !== 'number') continue;
|
||||
const found = this.client.registry.commands.get(id);
|
||||
if (!found || found.uses === undefined) continue;
|
||||
found.uses = value;
|
||||
}
|
||||
return msg.say('Successfully imported command leaderboard.');
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user