From a2b8a475412581834ee0226c0444be613152760e Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Wed, 28 Oct 2020 14:06:06 -0400 Subject: [PATCH] DiceBear Command, Fix Adorable --- README.md | 9 ++++- commands/edit-image/adorable.js | 10 ++++- commands/edit-image/dicebear.js | 70 +++++++++++++++++++++++++++++++++ package.json | 2 +- 4 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 commands/edit-image/dicebear.js diff --git a/README.md b/README.md index fc2cb694..c6f4c09b 100644 --- a/README.md +++ b/README.md @@ -257,7 +257,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 550 +Total: 551 ### Utility: @@ -619,6 +619,7 @@ Total: 550 * **danger:** Creates a danger sign with the text of your choice. * **desaturate:** Draws an image or a user's avatar but desaturated. * **dexter:** Draws an image or a user's avatar over the screen of Dexter from Pokémon. +* **dicebear:** Creates a DiceBear avatar based on the text you provide. * **distort:** Draws an image or a user's avatar but distorted. * **emboss:** Draws an image or a user's avatar but embossed. * **fire-frame:** Draws a fiery border over an image or a user's avatar. @@ -916,7 +917,7 @@ here. - [@liltusk](https://twitter.com/liltusk) * food-broke ([Image](https://twitter.com/liltusk/status/835719948597137408)) - [Adorable Avatars](http://avatars.adorable.io/) - * adorable (API) + * adorable (Original API) - [Advice Slip](https://adviceslip.com/) * advice ([API](https://api.adviceslip.com/)) - [Akinator](https://en.akinator.com/) @@ -1035,6 +1036,8 @@ here. * deviantart ([API](https://www.deviantart.com/developers/)) - [devsnek](https://github.com/devsnek) * owo (Code) +- [DiceBear](https://avatars.dicebear.com/) + * dicebear (API) - [Digital Equipment Corporation](http://gordonbell.azurewebsites.net/digital/timeline/tmlnhome.htm) * dec-talk (Original DECTalk Software) - [Discord](https://discord.com/) @@ -1107,6 +1110,8 @@ here. * gender (API) - [Gerhard Jordan](http://www.gerhardjordan.com/) * never-have-i-ever ([Statement Data](http://www.neverhaveiever.org/)) +- [gfauchart](https://github.com/gfauchart) + * adorable ([API](https://github.com/adorableio/avatars-api-middleware/issues/108)) - [GIPHY](https://giphy.com/) * giphy ([API](https://developers.giphy.com/)) - [GitHub](https://github.com/) diff --git a/commands/edit-image/adorable.js b/commands/edit-image/adorable.js index 7b6b1c4f..4896098d 100644 --- a/commands/edit-image/adorable.js +++ b/commands/edit-image/adorable.js @@ -14,7 +14,13 @@ module.exports = class AdorableCommand extends Command { { name: 'Adorable Avatars', url: 'http://avatars.adorable.io/', - reason: 'API' + reason: 'Original API' + }, + { + name: 'gfauchart', + url: 'https://github.com/gfauchart', + reason: 'API', + reasonURL: 'https://github.com/adorableio/avatars-api-middleware/issues/108' } ], args: [ @@ -30,7 +36,7 @@ module.exports = class AdorableCommand extends Command { async run(msg, { text }) { try { - const { body } = await request.get(`https://api.adorable.io/avatars/285/${text}.png`); + const { body } = await request.get(`https://api.hello-avatar.com/adorables/285/${text}.png`); return msg.say({ files: [{ attachment: body, name: 'adorable.png' }] }); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/edit-image/dicebear.js b/commands/edit-image/dicebear.js new file mode 100644 index 00000000..5fd2082c --- /dev/null +++ b/commands/edit-image/dicebear.js @@ -0,0 +1,70 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); +const { createCanvas, loadImage } = require('canvas'); +const { list } = require('../../util/Util'); +const emotions = ['happy', 'sad', 'surprised']; + +module.exports = class DicebearCommand extends Command { + constructor(client) { + super(client, { + name: 'dicebear', + aliases: ['dicebear-avatar'], + group: 'edit-image', + memberName: 'dicebear', + description: 'Creates a DiceBear avatar based on the text you provide.', + clientPermissions: ['ATTACH_FILES'], + throttling: { + usages: 1, + duration: 10 + }, + credit: [ + { + name: 'DiceBear Avatars', + url: 'https://avatars.dicebear.com/', + reason: 'API' + } + ], + args: [ + { + key: 'gender', + prompt: 'What gender do you want to use? Either male or female.', + type: 'string', + oneOf: ['male', 'female'], + parse: gender => gender.toLowerCase() + }, + { + key: 'emotion', + prompt: `What emotion should the avatar display? Either ${list(emotions, 'or')}.`, + type: 'string', + oneOf: emotions, + parse: emotion => emotion.toLowerCase() + }, + { + key: 'text', + prompt: 'What text should be used for generation?', + type: 'string', + parse: text => encodeURIComponent(text) + } + ] + }); + } + + async run(msg, { gender, emotion, text }) { + try { + const { body } = await request + .get(`https://avatars.dicebear.com/api/${gender}/${text}.svg`) + .query({ + width: 285, + height: 285, + 'mood[]': emotion + }); + const canvas = createCanvas(285, 285); + const ctx = canvas.getContext('2d'); + const img = await loadImage(body); + ctx.drawImage(img, 0, 0, 285, 285); + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'dicebear.png' }] }); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 9a23dac1..3f070c56 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "119.32.0", + "version": "119.33.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {