mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-06 22:44:32 +02:00
Add file-based import/export command-leaderboard
This commit is contained in:
@@ -10,6 +10,7 @@ report*.json
|
||||
# Config Files
|
||||
.env
|
||||
config.json
|
||||
command-leaderboard.json
|
||||
|
||||
# In-Development Commands
|
||||
commands/games-sp/puyo-puyo.js
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = class CommandLeaderboardExportCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -30,6 +32,9 @@ module.exports = class CommandLeaderboardExportCommand extends Command {
|
||||
}
|
||||
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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = class CommandLeaderboardImportCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -23,13 +25,24 @@ module.exports = class CommandLeaderboardImportCommand extends Command {
|
||||
{
|
||||
key: 'file',
|
||||
prompt: 'What file do you want to provide?',
|
||||
type: 'json-file'
|
||||
type: 'json-file',
|
||||
default: ''
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "116.1.1",
|
||||
"version": "116.1.2",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user