mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-23 18:05:01 +02:00
Shields.io badge, hi
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const snekfetch = require('snekfetch');
|
||||
|
||||
module.exports = class ShieldsIoBadgeCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'shields-io-badge',
|
||||
aliases: ['shields-io', 'img-shields-io'],
|
||||
group: 'image-edit',
|
||||
memberName: 'shields-io-badge',
|
||||
description: 'Creates a badge from shields.io.',
|
||||
clientPermissions: ['ATTACH_FILES'],
|
||||
args: [
|
||||
{
|
||||
key: 'subject',
|
||||
prompt: 'What is the subject of the badge?',
|
||||
type: 'string',
|
||||
parse: subject => encodeURIComponent(subject.replace(/-/g, '--').replace(/_/g, '__'))
|
||||
},
|
||||
{
|
||||
key: 'status',
|
||||
prompt: 'What is the status of the badge?',
|
||||
type: 'string',
|
||||
parse: status => encodeURIComponent(status.replace(/-/g, '--').replace(/_/g, '__'))
|
||||
},
|
||||
{
|
||||
key: 'color',
|
||||
prompt: 'What is the color of the badge?',
|
||||
type: 'string',
|
||||
default: 'brightgreen'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { subject, status, color }) {
|
||||
try {
|
||||
const { body, headers } = await snekfetch.get(`https://img.shields.io/badge/${subject}-${status}-${color}.png`);
|
||||
if (headers['Content-Type'] !== 'image/png') return msg.reply('Could not create the badge...');
|
||||
return msg.say({ files: [{ attachment: body, name: 'badge.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user