Files
xiao/commands/other/spoopy-link.js
T
2017-10-12 13:54:43 +00:00

36 lines
1.0 KiB
JavaScript

const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const { stripIndents } = require('common-tags');
module.exports = class SpoopyLinkCommand extends Command {
constructor(client) {
super(client, {
name: 'spoopy-link',
group: 'other',
memberName: 'spoopy-link',
description: 'Checks if a link is spoopy or not.',
args: [
{
key: 'site',
prompt: 'What site do you think is spoopy?',
type: 'string',
parse: site => encodeURIComponent(site)
}
]
});
}
async run(msg, { site }) {
if (/discord(\.gg|app\.com%2Finvite|\.me)%2F/gi.test(site)) return msg.say('Discord invites are safe!');
try {
const { body } = await snekfetch.get(`https://spoopy.link/api/${site}`);
return msg.say(stripIndents`
${body.safe ? '✅ Safe!' : '❌ Not safe...'}
${body.chain.map(url => `<${url.url}> ${url.safe ? '✅' : `❌ (${url.reasons.join(', ')})`}`).join('\n')}
`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};