Files
xiao/commands/readme/generate-credit.js
T
2020-01-14 18:25:35 -05:00

49 lines
1.4 KiB
JavaScript

const Command = require('../../structures/Command');
const request = require('node-superfetch');
module.exports = class GenerateCreditCommand extends Command {
constructor(client) {
super(client, {
name: 'generate-credit',
aliases: ['gen-credit'],
group: 'owner',
memberName: 'generate-credit',
description: 'Generates the credit list for Xiao\'s README.',
ownerOnly: true,
guarded: true,
credit: [
{
name: 'Hastebin',
url: 'https://hastebin.com/about.md',
reason: 'API'
}
]
});
}
async run(msg) {
const credit = [];
const commands = this.client.registry.commands.filter(cmd => cmd.credit && cmd.credit.length > 1);
for (const command of commands.values()) {
for (const cred of command.credit) {
const found = credit.find(c => c.name === cred.name);
if (found) {
found.commands.push(command.name);
continue;
}
if (cred.name === 'Dragon Fire') continue;
credit.push({ ...cred, commands: [command.name] });
}
}
const mapped = credit
.map(c => `- [${c.name}](${c.url})\n${c.commands.map(cmd => {
if (!c.reasonURL) return ` * ${cmd} (${c.reason})`;
return ` * ${cmd} ([${c.reason}](${c.reasonURL}))`;
}).join('\n')}`);
const { body } = await request
.post('https://hastebin.com/documents')
.send(mapped.join('\n'));
return msg.say(`https://hastebin.com/raw/${body.key}`);
}
};