mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
const Command = require('../../framework/Command');
|
|
const request = require('node-superfetch');
|
|
|
|
module.exports = class ShieldsIoBadgeCommand extends Command {
|
|
constructor(client) {
|
|
super(client, {
|
|
name: 'shields-io-badge',
|
|
aliases: ['shields-io'],
|
|
group: 'edit-image-text',
|
|
memberName: 'shields-io-badge',
|
|
description: 'Creates a badge from shields.io.',
|
|
clientPermissions: ['ATTACH_FILES'],
|
|
credit: [
|
|
{
|
|
name: 'Shields.io',
|
|
url: 'https://shields.io/',
|
|
reason: 'API'
|
|
}
|
|
],
|
|
args: [
|
|
{
|
|
key: 'subject',
|
|
prompt: 'What is the subject of the badge?',
|
|
type: 'string',
|
|
parse: subject => encodeURIComponent(subject.replaceAll('-', '--').replaceAll('_', '__'))
|
|
},
|
|
{
|
|
key: 'status',
|
|
prompt: 'What is the status of the badge?',
|
|
type: 'string',
|
|
parse: status => encodeURIComponent(status.replaceAll('-', '--').replaceAll('_', '__'))
|
|
},
|
|
{
|
|
key: 'color',
|
|
prompt: 'What is the color of the badge?',
|
|
type: 'string',
|
|
default: 'brightgreen'
|
|
}
|
|
]
|
|
});
|
|
}
|
|
|
|
async run(msg, { subject, status, color }) {
|
|
try {
|
|
const { body } = await request.get(`https://img.shields.io/badge/${subject}-${status}-${color}.png`);
|
|
return msg.say({ files: [{ attachment: body, name: 'badge.png' }] });
|
|
} catch (err) {
|
|
if (err.status === 404) return msg.reply('Could not create the badge...');
|
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
|
}
|
|
}
|
|
};
|