From 5618e2470f1a7dbd99c59396e2b44b9ee3833a8d Mon Sep 17 00:00:00 2001 From: loicbersier Date: Sat, 13 Oct 2018 11:22:55 +0200 Subject: [PATCH] show despacito album --- commands/fun/despacito.js | 23 +++++++++++++++++++---- package.json | 1 + 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/commands/fun/despacito.js b/commands/fun/despacito.js index 05ce15de..11d8d982 100644 --- a/commands/fun/despacito.js +++ b/commands/fun/despacito.js @@ -1,5 +1,8 @@ const { Command } = require('discord.js-commando'); const responseObject = require("../../json/despacito.json"); +const { createCanvas, loadImage, getContext } = require('canvas') +const superagent = require('superagent') +const Discord = require('discord.js'); module.exports = class DespacitoCommand extends Command { constructor(client) { super(client, { @@ -11,7 +14,7 @@ module.exports = class DespacitoCommand extends Command { { key: 'user', prompt: 'What do you want me to say', - type: 'member', + type: 'user', default: '' } ] @@ -19,6 +22,15 @@ module.exports = class DespacitoCommand extends Command { } async run(message, { user }) { + const canvas = createCanvas(660, 660); + const ctx = canvas.getContext('2d'); + const background = await loadImage(user.avatarURL); + ctx.drawImage(background, 5, 12, canvas.width, canvas.height); + const { body: buffer } = await superagent.get('https://image.noelshack.com/fichiers/2018/41/6/1539381851-untitled.png'); + const bg = await loadImage(buffer); + ctx.drawImage(bg, 0, 0, canvas.width, canvas.height); + const attachment = new Discord.Attachment(canvas.toBuffer(), 'despacito.png'); + if (!user) { const number = Object.keys(responseObject).length; const despacitoNumber = Math.floor (Math.random() * (number - 1 + 1)) + 1; @@ -28,8 +40,11 @@ module.exports = class DespacitoCommand extends Command { return message.say(`Did you just try to despacitoad yourself?`); } else if (user.id === this.client.user.id) { return message.say('Nice try but you wont get me :^)'); - } else + } else { message.delete(); - message.say(`${user}, you have been despacitoad`); - } + message.say(`${user}, you have been despacitoad`, attachment); + } + + +} }; \ No newline at end of file diff --git a/package.json b/package.json index 3f4c3945..b08549fc 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ }, "homepage": "https://gitlab.com/loicbersier/discordbot#readme", "dependencies": { + "canvas": "^2.0.0-alpha.18", "discord.js": "^11.4.2", "discord.js-commando": "^0.10.0", "faceapp": "^0.4.4",