use Hapi for screenshot
This commit is contained in:
parent
d2aa20ffb5
commit
0c6af04fd3
1 changed files with 31 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
||||||
const { Command } = require('discord-akairo');
|
const { Command } = require('discord-akairo');
|
||||||
const captureWebsite = require('capture-website');
|
const { Hapi } = require('../../config.json');
|
||||||
const os = require('os');
|
const checkHapi = require('../../utils/checkHapi');
|
||||||
const fs = require('fs');
|
const fetch = require('node-fetch');
|
||||||
|
|
||||||
class screenshotCommand extends Command {
|
class screenshotCommand extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -12,7 +12,7 @@ class screenshotCommand extends Command {
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
id: 'url',
|
id: 'url',
|
||||||
type: 'string',
|
type: 'url',
|
||||||
prompt: {
|
prompt: {
|
||||||
start: 'Please send a link of which website you want to take a screenshot of.',
|
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.'
|
retry: 'This does not look like an url, please try again.'
|
||||||
|
@ -33,15 +33,35 @@ class screenshotCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
async exec(message, args) {
|
async exec(message, args) {
|
||||||
let url = args.url;
|
if (args.url.href.includes('config.json') || args.url.href.includes('file://')) return message.channel.send('I don\'t think so');
|
||||||
if (!url.includes('http')) url = `http://${url}`;
|
|
||||||
if (url.includes('config.json') || url.includes('file://')) return message.channel.send('I don\'t think so');
|
|
||||||
let Embed = this.client.util.embed()
|
let Embed = this.client.util.embed()
|
||||||
.setColor(message.member ? message.member.displayHexColor : 'NAVY')
|
.setColor(message.member ? message.member.displayHexColor : 'NAVY');
|
||||||
.setTitle(url);
|
|
||||||
|
|
||||||
let loadingmsg = await message.channel.send('Taking a screenshot <a:loadingmin:527579785212329984>');
|
let loadingmsg = await message.channel.send('Taking a screenshot <a:loadingmin:527579785212329984>');
|
||||||
|
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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
await captureWebsite.file(url, `${os.tmpdir()}/${message.id}.jpg`, {
|
await captureWebsite.file(url, `${os.tmpdir()}/${message.id}.jpg`, {
|
||||||
type: 'jpeg',
|
type: 'jpeg',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -63,6 +83,7 @@ class screenshotCommand extends Command {
|
||||||
return message.channel.send(Embed);
|
return message.channel.send(Embed);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = screenshotCommand;
|
module.exports = screenshotCommand;
|
Loading…
Reference in a new issue