From 8ff7a610605a67fb6360e0f757b574e4d6f159f3 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Mon, 17 Sep 2018 22:48:38 +0000 Subject: [PATCH] Circle Avatar Command --- README.md | 3 ++- commands/avatar-edit/circle.js | 46 ++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 commands/avatar-edit/circle.js diff --git a/README.md b/README.md index 8666b531..fbe052ed 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Xiao is a Discord bot coded in JavaScript with The bot is no longer available for invite. You can self-host the bot, or use her on the [home server](https://discord.gg/sbMe32W). -## Commands (310) +## Commands (311) ### Utility: * **eval:** Executes JavaScript code. @@ -269,6 +269,7 @@ on the [home server](https://discord.gg/sbMe32W). * **avatar-fusion:** Draws a a user's avatar over a user's avatar. * **bob-ross:** Draws a user's avatar over Bob Ross' canvas. * **challenger:** Draws a user's avatar over Super Smash Bros.'s "Challenger Approaching" screen. +* **circle:** Draws a user's avatar as a circle. * **dexter:** Draws a user's avatar over the screen of Dexter from Pokémon. * **distracted-boyfriend:** Draws three user's avatars over the "Distracted Boyfriend" meme. * **drakeposting:** Draws two user's avatars over the "Drakeposting" meme. diff --git a/commands/avatar-edit/circle.js b/commands/avatar-edit/circle.js new file mode 100644 index 00000000..286574bc --- /dev/null +++ b/commands/avatar-edit/circle.js @@ -0,0 +1,46 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage } = require('canvas'); +const request = require('node-superfetch'); + +module.exports = class CircleCommand extends Command { + constructor(client) { + super(client, { + name: 'circle', + aliases: ['circle-avatar', 'circle-ava'], + group: 'avatar-edit', + memberName: 'circle', + description: 'Draws a user\'s avatar as a circle.', + throttling: { + usages: 1, + duration: 10 + }, + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'user', + prompt: 'Which user would you like to edit the avatar of?', + type: 'user', + default: msg => msg.author + } + ] + }); + } + + async run(msg, { user }) { + const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 }); + try { + const { body } = await request.get(avatarURL); + const avatar = await loadImage(body); + const canvas = createCanvas(avatar.width, avatar.height); + const ctx = canvas.getContext('2d'); + ctx.beginPath(); + ctx.arc(avatar.width / 2, avatar.height / 2, avatar.height / 2, 0, Math.PI * 2); + ctx.closePath(); + ctx.clip(); + ctx.drawImage(avatar, 0, 0); + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'circle.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 afef31d2..9db4f2ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "91.4.0", + "version": "91.5.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {