Haha-Yes/commands/fun/face.js

53 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-10-10 15:37:03 +02:00
const { Command } = require('discord.js-commando');
const faceapp = require('faceapp')
const superagent = require('superagent')
module.exports = class faceappCommand extends Command {
constructor(client) {
super(client, {
name: 'face',
group: 'fun',
memberName: 'face',
description: `use faceapp to change the face of someone, Here the available filter https://goo.gl/5LLbJJ`,
args: [
2018-10-10 15:46:00 +02:00
{
key: 'type',
2018-10-11 13:08:30 +02:00
prompt: 'How the face should change ? (default to female)',
2018-10-10 15:46:00 +02:00
type: 'string',
2018-10-11 15:37:03 +02:00
default: 'female',
2018-10-11 13:08:30 +02:00
oneOf: ["no-filter", "smile", "smile_2", "hot", "old", "young", "hollywood", "fun_glasses", "hitman", "mustache_free", "pan", "heisenberg", "female", "female_2", "male", "impression", "goatee", "mustache", "hipster", "lion", "bangs", "glasses", "wave", "makeup"]
2018-10-12 16:16:14 +02:00
},
{
key: 'url',
prompt: 'Wich image would you want to process (default to empty so you can also send an image without the adress)',
type: 'string',
default: ''
2018-10-10 15:37:03 +02:00
}
]
});
}
2018-10-12 16:09:29 +02:00
async run(message, { url, type }) {
2018-10-12 15:41:25 +02:00
2018-10-12 15:42:27 +02:00
let Attachment = (message.attachments).array();
2018-10-12 16:09:29 +02:00
if(!Attachment[0] && !url) {
2018-10-12 15:45:28 +02:00
return message.say("You need to send an image")
2018-10-12 16:09:29 +02:00
} else if(url.includes("http") || url.includes("www")) {
let face = type.toLowerCase();
let { body } = await superagent.get(url)
let image = await faceapp.process(body, face)
.catch(error => {
message.say('Cant recognize the face')
console.error(error)
})
2018-10-13 01:12:20 +02:00
return message.channel.send({files: [image]});
} else {
2018-10-10 16:00:17 +02:00
let face = type.toLowerCase();
2018-10-12 15:41:25 +02:00
let { body } = await superagent.get(Attachment[0].url)
2018-10-10 16:00:17 +02:00
let image = await faceapp.process(body, face)
2018-10-11 15:43:43 +02:00
.catch(error => {
message.say('Cant recognize the face')
console.error(error)
})
2018-10-13 01:12:20 +02:00
return message.channel.send({files: [image]});
2018-10-12 15:45:28 +02:00
}
2018-10-12 15:41:25 +02:00
}};