mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Face Command is back!
This commit is contained in:
@@ -25,6 +25,8 @@ CLEVERBOT_KEY=
|
||||
CUSTOM_SEARCH_ID=
|
||||
DEVIANTART_ID=
|
||||
DEVIANTART_SECRET=
|
||||
FACEPLUSPLUS_KEY=
|
||||
FACEPLUSPLUS_SECRET=
|
||||
FLICKR_KEY=
|
||||
GIPHY_KEY=
|
||||
GITHUB_PASSWORD=
|
||||
|
||||
@@ -45,7 +45,7 @@ Xiao is a Discord bot coded in JavaScript with
|
||||
6. Run `npm i -g pm2` to install PM2.
|
||||
7. Run `pm2 start Xiao.js --name xiao` to run the bot.
|
||||
|
||||
## Commands (341)
|
||||
## Commands (342)
|
||||
### Utility:
|
||||
|
||||
* **eval:** Executes JavaScript code.
|
||||
@@ -229,6 +229,7 @@ Xiao is a Discord bot coded in JavaScript with
|
||||
* **chinese-zodiac:** Responds with the Chinese Zodiac Sign for the given year.
|
||||
* **coolness:** Determines a user's coolness.
|
||||
* **dick:** Determines your dick size.
|
||||
* **face:** Determines the race, gender, and age of a face.
|
||||
* **gender:** Determines the gender of a name.
|
||||
* **guess-looks:** Guesses what a user looks like.
|
||||
* **iq:** Determines a user's IQ.
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const request = require('node-superfetch');
|
||||
const { oneLine } = require('common-tags');
|
||||
const { FACEPLUSPLUS_KEY, FACEPLUSPLUS_SECRET } = process.env;
|
||||
const emotions = ['anger', 'disgust', 'fear', 'happiness', 'neutral', 'sadness', 'surprise'];
|
||||
const emotionResponse = ['angry', 'disgusted', 'afraid', 'happy', 'uncaring', 'sad', 'surprised'];
|
||||
|
||||
module.exports = class FaceCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'face',
|
||||
group: 'analyze',
|
||||
memberName: 'face',
|
||||
description: 'Determines the race, gender, and age of a face.',
|
||||
args: [
|
||||
{
|
||||
key: 'image',
|
||||
prompt: 'What face would you like to scan?',
|
||||
type: 'image'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { image }) {
|
||||
try {
|
||||
const face = await this.detect(image);
|
||||
if (!face) return msg.reply('There are no faces in this image.');
|
||||
const pronoun = face.gender.value === 'Male' ? 'He' : 'She';
|
||||
const emotion = emotionResponse[emotions.indexOf(emotions.sort((a, b) => face.emotion[b] - face.emotion[a])[0])];
|
||||
const smile = face.smile.value > face.smile.threshold;
|
||||
const beautyScore = face.gender.value === 'Male' ? face.beauty.female_score : face.beauty.male_score;
|
||||
return msg.reply(oneLine`
|
||||
I think this is a photo of a ${face.age.value} year old ${face.ethnicity.value.toLowerCase()}
|
||||
${face.gender.value.toLowerCase()}. ${pronoun} appears to be ${emotion}, and is
|
||||
${smile ? 'smiling' : 'not smiling'}. I give this face a ${Math.round(beautyScore)} on the 1-100 beauty scale.
|
||||
${beautyScore > 50 ? beautyScore > 70 ? beautyScore > 90 ? 'Hot!' : 'Not bad.' : 'Not _too_ ugly.' : 'Uggggly!'}
|
||||
`);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
async detect(image) {
|
||||
const { body } = await request
|
||||
.post('https://api-us.faceplusplus.com/facepp/v3/detect')
|
||||
.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;
|
||||
return body.faces[0].attributes;
|
||||
}
|
||||
};
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "102.3.0",
|
||||
"version": "102.4.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user