Added prompt and use url type
Signed-off-by: loicbersier <loic.bersier1@gmail.com>
This commit is contained in:
parent
c857d36c65
commit
6da1ba9cfb
1 changed files with 27 additions and 32 deletions
|
@ -12,7 +12,11 @@ class screenshotCommand extends Command {
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
id: 'url',
|
id: 'url',
|
||||||
type: 'string'
|
type: 'url',
|
||||||
|
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.'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'fullpage',
|
id: 'fullpage',
|
||||||
|
@ -20,7 +24,6 @@ class screenshotCommand extends Command {
|
||||||
flag: '--full'
|
flag: '--full'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
channel: 'guild',
|
|
||||||
description: {
|
description: {
|
||||||
content: 'Take a screenshot of a website. Need to start with http(s)://. Use --full to take a full page capture',
|
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]',
|
usage: '[link to a website] [optional: --full]',
|
||||||
|
@ -30,43 +33,35 @@ class screenshotCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
async exec(message, args) {
|
async exec(message, args) {
|
||||||
if (args.url.includes('config.json')) return message.channel.send('I don\'t think so');
|
let url = args.url.href;
|
||||||
|
if (url.includes('config.json')) 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(args.url);
|
.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>');
|
||||||
|
|
||||||
// eslint-disable-next-line no-useless-escape
|
await captureWebsite.file(url, `${os.tmpdir()}/${message.id}.jpg`, {
|
||||||
let urlregex = new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/);
|
type: 'jpeg',
|
||||||
if (!args.url.includes('http')) args.url = 'http://' + args.url;
|
headers: {
|
||||||
console.log(args.url);
|
'Accept-Language': 'en-GB'
|
||||||
if (args.url.match(urlregex)) { // Only allow link with http/https
|
},
|
||||||
await captureWebsite.file(args.url, `${os.tmpdir()}/${message.id}.jpg`, {
|
fullPage: args.fullpage
|
||||||
type: 'jpeg',
|
})
|
||||||
headers: {
|
.catch((err) => {
|
||||||
'Accept-Language': 'en-GB'
|
console.error(err);
|
||||||
},
|
Embed.setDescription(err.toString());
|
||||||
fullPage: args.fullpage
|
loadingmsg.delete();
|
||||||
|
return message.channel.send(Embed);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.then(() => {
|
||||||
console.error(err);
|
if (fs.existsSync(`${os.tmpdir()}/${message.id}.jpg`)) {
|
||||||
Embed.setDescription(err.toString());
|
Embed.attachFiles([`${os.tmpdir()}/${message.id}.jpg`]);
|
||||||
|
Embed.setImage(`attachment://${message.id}.jpg`);
|
||||||
loadingmsg.delete();
|
loadingmsg.delete();
|
||||||
return message.channel.send(Embed);
|
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`);
|
|
||||||
loadingmsg.delete();
|
|
||||||
return message.channel.send(Embed);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
loadingmsg.delete();
|
|
||||||
return message.channel.send('The URL you used doesn\'t correspond to a website!');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = screenshotCommand;
|
module.exports = screenshotCommand;
|
Loading…
Reference in a new issue