diff --git a/.env.example b/.env.example index 46ff5de1..a38e2008 100644 --- a/.env.example +++ b/.env.example @@ -25,6 +25,8 @@ CLEVERBOT_KEY= CUSTOM_SEARCH_ID= DEVIANTART_ID= DEVIANTART_SECRET= +FACEPLUSPLUS_KEY= +FACEPLUSPLUS_SECRET= FLICKR_KEY= GIPHY_KEY= GITHUB_PASSWORD= diff --git a/README.md b/README.md index 1685e169..2ab82bc1 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/commands/analyze/face.js b/commands/analyze/face.js new file mode 100644 index 00000000..5909dccd --- /dev/null +++ b/commands/analyze/face.js @@ -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; + } +}; diff --git a/package.json b/package.json index df23d630..9734244d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "102.3.0", + "version": "102.4.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {