Files
xiao/commands/other/screenshot.js
T
2021-02-28 15:21:31 -05:00

47 lines
1.3 KiB
JavaScript

const Command = require('../../structures/Command');
const request = require('node-superfetch');
const url = require('url');
const validURL = require('valid-url');
module.exports = class ScreenshotCommand extends Command {
constructor(client) {
super(client, {
name: 'screenshot',
aliases: ['capture', 'ss'],
group: 'other',
memberName: 'screenshot',
description: 'Takes a screenshot of any webpage.',
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'Thum.io',
url: 'https://www.thum.io/',
reason: 'API'
}
],
args: [
{
key: 'site',
prompt: 'What webpage do you want to take a screenshot of?',
type: 'string',
validate: site => Boolean(validURL.isWebUri(site))
}
]
});
}
async run(msg, { site }) {
try {
const parsed = url.parse(site);
if (!msg.channel.nsfw && this.client.adultSiteList.includes(parsed.host)) {
return msg.reply('This site is NSFW.');
}
const { body } = await request.get(`https://image.thum.io/get/width/1920/crop/675/noanimate/${site}`);
return msg.say({ files: [{ attachment: body, name: 'screenshot.png' }] });
} catch (err) {
if (err.status === 404) return msg.say('Could not find any results. Invalid URL?');
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};