mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-27 14:18:36 +02:00
Detect face image size
This commit is contained in:
@@ -38,6 +38,7 @@ module.exports = class FaceCommand extends Command {
|
|||||||
try {
|
try {
|
||||||
const face = await this.detect(image);
|
const face = await this.detect(image);
|
||||||
if (!face) return msg.reply('There are no faces in this 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 pronoun = face.gender.value === 'Male' ? 'He' : 'She';
|
||||||
const emotion = emotionResponse[emotions.indexOf(
|
const emotion = emotionResponse[emotions.indexOf(
|
||||||
emotions.slice(0).sort((a, b) => face.emotion[b] - face.emotion[a])[0]
|
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) {
|
async detect(image) {
|
||||||
|
const imgData = await request.get(image);
|
||||||
|
if (Buffer.byteLength(imgData.body) >= 2e+6) return 'size';
|
||||||
const { body } = await request
|
const { body } = await request
|
||||||
.post('https://api-us.faceplusplus.com/facepp/v3/detect')
|
.post('https://api-us.faceplusplus.com/facepp/v3/detect')
|
||||||
|
.attach('image_file', imgData.body)
|
||||||
.query({
|
.query({
|
||||||
api_key: FACEPLUSPLUS_KEY,
|
api_key: FACEPLUSPLUS_KEY,
|
||||||
api_secret: FACEPLUSPLUS_SECRET,
|
api_secret: FACEPLUSPLUS_SECRET,
|
||||||
image_url: image,
|
|
||||||
return_attributes: 'gender,age,smiling,emotion,ethnicity,beauty'
|
return_attributes: 'gender,age,smiling,emotion,ethnicity,beauty'
|
||||||
});
|
});
|
||||||
if (!body.faces || !body.faces.length) return null;
|
if (!body.faces || !body.faces.length) return null;
|
||||||
|
|||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "119.19.5",
|
"version": "119.19.6",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -62,9 +62,9 @@
|
|||||||
"utf-8-validate": "^5.0.2"
|
"utf-8-validate": "^5.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^7.4.0",
|
"eslint": "^7.7.0",
|
||||||
"eslint-config-amber": "^2.0.3",
|
"eslint-config-amber": "^2.0.3",
|
||||||
"eslint-plugin-json": "^2.1.1"
|
"eslint-plugin-json": "^2.1.2"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"extends": "amber",
|
"extends": "amber",
|
||||||
|
|||||||
Reference in New Issue
Block a user