2020-03-04 02:08:04 +01:00
|
|
|
const { Command } = require('discord-akairo');
|
|
|
|
const captureWebsite = require('capture-website');
|
|
|
|
const os = require('os');
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
class screenshotCommand extends Command {
|
|
|
|
constructor() {
|
|
|
|
super('screenshot', {
|
|
|
|
aliases: ['screenshot', 'webshot', 'ss'],
|
|
|
|
category: 'utility',
|
|
|
|
clientPermissions: ['SEND_MESSAGES', 'ATTACH_FILES'],
|
|
|
|
args: [
|
|
|
|
{
|
|
|
|
id: 'url',
|
|
|
|
type: 'string'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'fullpage',
|
|
|
|
type: 'flag',
|
|
|
|
flag: '--full'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
channelRestriction: 'guild',
|
|
|
|
description: {
|
2020-03-19 16:19:07 +01:00
|
|
|
content: 'Take a screenshot of a website. Need to start with http(s)://. Use --full to take a full page capture',
|
|
|
|
usage: '[link to a website] [optional: --full]',
|
|
|
|
examples: ['https://google.com', 'https://namejeff.xyz --full']
|
2020-03-04 02:08:04 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async exec(message, args) {
|
2020-03-19 16:17:08 +01:00
|
|
|
if (args.url.includes('config.json')) return message.channel.send('I don\'t think so');
|
2020-03-04 02:08:04 +01:00
|
|
|
let Embed = this.client.util.embed()
|
|
|
|
.setColor(message.member.displayHexColor)
|
|
|
|
.setTitle(args.url);
|
|
|
|
|
2020-03-19 16:07:46 +01:00
|
|
|
let loadingmsg = await message.channel.send('Taking a screenshot <a:loadingmin:527579785212329984>');
|
|
|
|
|
2020-03-04 02:08:04 +01:00
|
|
|
// eslint-disable-next-line no-useless-escape
|
|
|
|
let urlregex = new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/);
|
|
|
|
if (args.url.match(urlregex)) { // Only allow link with http/https
|
|
|
|
await captureWebsite.file(args.url, `${os.tmpdir()}/${message.id}.jpg`, {
|
|
|
|
type: 'jpeg',
|
|
|
|
headers: {
|
|
|
|
'Accept-Language': 'en-GB'
|
|
|
|
},
|
|
|
|
fullPage: args.fullpage
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(err);
|
|
|
|
Embed.setDescription(err.toString());
|
2020-03-19 16:07:46 +01:00
|
|
|
loadingmsg.delete();
|
2020-03-04 02:08:04 +01:00
|
|
|
return message.channel.send(Embed);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
if (fs.existsSync(`${os.tmpdir()}/${message.id}.jpg`)) {
|
|
|
|
Embed.attachFiles([`${os.tmpdir()}/${message.id}.jpg`]);
|
|
|
|
Embed.setImage(`attachment://${message.id}.jpg`);
|
2020-03-19 16:07:46 +01:00
|
|
|
loadingmsg.delete();
|
2020-03-04 02:08:04 +01:00
|
|
|
return message.channel.send(Embed);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2020-03-19 16:07:46 +01:00
|
|
|
loadingmsg.delete();
|
2020-03-04 02:08:04 +01:00
|
|
|
return message.channel.send('The URL you used doesn\'t correspond to a website!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = screenshotCommand;
|