woomy-v2/bot/commands/Test/retrieve.js
2020-10-10 16:26:27 +11:00

32 lines
972 B
JavaScript

const Command = require("../../base/Command.js");
class Retrieve extends Command {
constructor (client) {
super(client, {
description: "Retrieves a key's value from the Redis DB.",
usage: "retrieve [key]",
guildOnly: true
});
}
async run (message, args, data) { // eslint-disable-line no-unused-vars
if (!args[0]) return message.channel.send("You didn't specify what database to access!");
if (args[0].toLowerCase() !== 'guild' && args[0].toLowerCase() !== 'member' && args[0].toLowerCase() !== 'user') {
return message.channel.send('Invalid database. Valid databases: `guild`, `member`, `user`');
}
if (!args[1]) {
message.channel.send(
`\`\`\`js
${JSON.stringify(data[args[0]])}
\`\`\``
);
} else {
let res = data[args[0]][args[1]];
if (!res) return message.channel.send('Invalid key. Check for typing errors and try again.');
message.channel.send('```' + res + '```');
}
}
}
module.exports = Retrieve;