2020-03-04 02:08:04 +01:00
|
|
|
const { Command } = require('discord-akairo');
|
2021-09-13 15:38:56 +02:00
|
|
|
const { Hapi } = require('../../config.json');
|
|
|
|
const checkHapi = require('../../utils/checkHapi');
|
|
|
|
const fetch = require('node-fetch');
|
2020-03-04 02:08:04 +01:00
|
|
|
|
|
|
|
class screenshotCommand extends Command {
|
|
|
|
constructor() {
|
|
|
|
super('screenshot', {
|
|
|
|
aliases: ['screenshot', 'webshot', 'ss'],
|
|
|
|
category: 'utility',
|
|
|
|
clientPermissions: ['SEND_MESSAGES', 'ATTACH_FILES'],
|
|
|
|
args: [
|
|
|
|
{
|
|
|
|
id: 'url',
|
2021-09-13 15:38:56 +02:00
|
|
|
type: 'url',
|
2020-07-19 11:43:29 +02:00
|
|
|
prompt: {
|
|
|
|
start: 'Please send a link of which website you want to take a screenshot of.',
|
|
|
|
retry: 'This does not look like an url, please try again.'
|
|
|
|
}
|
2020-03-04 02:08:04 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'fullpage',
|
|
|
|
type: 'flag',
|
|
|
|
flag: '--full'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
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) {
|
2021-09-13 15:38:56 +02:00
|
|
|
if (args.url.href.includes('config.json') || args.url.href.includes('file://')) return message.channel.send('I don\'t think so');
|
|
|
|
|
2020-03-04 02:08:04 +01:00
|
|
|
let Embed = this.client.util.embed()
|
2021-09-13 15:38:56 +02:00
|
|
|
.setColor(message.member ? message.member.displayHexColor : 'NAVY');
|
2020-03-04 02:08:04 +01:00
|
|
|
|
2020-03-19 16:07:46 +01:00
|
|
|
let loadingmsg = await message.channel.send('Taking a screenshot <a:loadingmin:527579785212329984>');
|
2021-09-13 15:38:56 +02:00
|
|
|
const isHapiOnline = await checkHapi();
|
|
|
|
|
|
|
|
if (isHapiOnline) {
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
params.append('url', args.url.href);
|
|
|
|
|
|
|
|
fetch(`${Hapi}/screenshot`, {method: 'POST', body: params})
|
|
|
|
.then(async res => {
|
|
|
|
console.log(res);
|
|
|
|
console.log(`Status is: ${res.status}`);
|
|
|
|
if (res.status === 200) {
|
|
|
|
let json = await res.json();
|
|
|
|
Embed.setImage(json.image);
|
|
|
|
Embed.setTitle(json.url);
|
|
|
|
await message.reply(Embed);
|
|
|
|
}
|
|
|
|
await loadingmsg.delete();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return message.reply('Hapi server is not online, try again later!');
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-07-19 11:43:29 +02:00
|
|
|
await captureWebsite.file(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());
|
|
|
|
loadingmsg.delete();
|
|
|
|
return message.channel.send(Embed);
|
2020-03-04 02:08:04 +01:00
|
|
|
})
|
2020-07-19 11:43:29 +02:00
|
|
|
.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);
|
2020-07-19 11:43:29 +02:00
|
|
|
}
|
|
|
|
});
|
2021-09-13 15:38:56 +02:00
|
|
|
*/
|
2020-03-04 02:08:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = screenshotCommand;
|