Detect face image size

This commit is contained in:
Dragon Fire
2020-08-20 00:11:18 -04:00
parent 8b874a2fd3
commit b23f694427
2 changed files with 7 additions and 4 deletions
+4 -1
View File
@@ -38,6 +38,7 @@ module.exports = class FaceCommand extends Command {
try {
const face = await this.detect(image);
if (!face) return msg.reply('There are no faces in this image.');
if (face === 'size') return msg.reply('This image is too large.');
const pronoun = face.gender.value === 'Male' ? 'He' : 'She';
const emotion = emotionResponse[emotions.indexOf(
emotions.slice(0).sort((a, b) => face.emotion[b] - face.emotion[a])[0]
@@ -57,12 +58,14 @@ module.exports = class FaceCommand extends Command {
}
async detect(image) {
const imgData = await request.get(image);
if (Buffer.byteLength(imgData.body) >= 2e+6) return 'size';
const { body } = await request
.post('https://api-us.faceplusplus.com/facepp/v3/detect')
.attach('image_file', imgData.body)
.query({
api_key: FACEPLUSPLUS_KEY,
api_secret: FACEPLUSPLUS_SECRET,
image_url: image,
return_attributes: 'gender,age,smiling,emotion,ethnicity,beauty'
});
if (!body.faces || !body.faces.length) return null;
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "119.19.5",
"version": "119.19.6",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
@@ -62,9 +62,9 @@
"utf-8-validate": "^5.0.2"
},
"devDependencies": {
"eslint": "^7.4.0",
"eslint": "^7.7.0",
"eslint-config-amber": "^2.0.3",
"eslint-plugin-json": "^2.1.1"
"eslint-plugin-json": "^2.1.2"
},
"eslintConfig": {
"extends": "amber",