Haha-Yes/commands/fun/despacito.js

49 lines
2 KiB
JavaScript
Raw Normal View History

2018-09-08 01:50:13 +02:00
const { Command } = require('discord.js-commando');
2018-10-06 13:24:14 +02:00
const responseObject = require("../../json/despacito.json");
2018-10-13 11:22:55 +02:00
const { createCanvas, loadImage, getContext } = require('canvas')
const superagent = require('superagent')
const Discord = require('discord.js');
2018-09-08 01:50:13 +02:00
module.exports = class DespacitoCommand extends Command {
constructor(client) {
super(client, {
name: 'despacito',
group: 'fun',
memberName: 'despacito',
description: `despacito`,
2018-10-07 10:05:26 +02:00
args: [
{
key: 'user',
prompt: 'What do you want me to say',
2018-10-13 11:22:55 +02:00
type: 'user',
2018-10-07 10:05:26 +02:00
default: ''
}
]
2018-09-08 01:50:13 +02:00
});
}
2018-10-07 10:05:26 +02:00
async run(message, { user }) {
if (!user) {
2018-10-06 13:24:14 +02:00
const number = Object.keys(responseObject).length;
const despacitoNumber = Math.floor (Math.random() * (number - 1 + 1)) + 1;
2018-10-13 12:13:38 +02:00
return message.channel.send({files: [responseObject[despacitoNumber]]});
} else if (user.id === message.author.id) {
2018-10-08 23:27:41 +02:00
return message.say(`Did you just try to despacitoad yourself?`);
2018-10-08 17:57:08 +02:00
} else if (user.id === this.client.user.id) {
2018-10-08 23:27:41 +02:00
return message.say('Nice try but you wont get me :^)');
2018-10-13 11:22:55 +02:00
} else {
2018-10-13 12:13:38 +02:00
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');
message.delete();
2018-10-13 11:22:55 +02:00
message.say(`${user}, you have been despacitoad`, attachment);
}
}
2018-09-08 01:50:13 +02:00
};