Haha-Yes/commands/fun/despacito.js

58 lines
2.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-11-28 01:35:26 +01:00
const SelfReloadJSON = require('self-reload-json');
2018-12-05 00:52:21 +01:00
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 }) {
2018-12-05 00:57:44 +01:00
let blacklistJson = new SelfReloadJSON('DiscordBot/json/blacklist.json');
2018-11-28 01:35:26 +01:00
if(blacklistJson[message.author.id])
return blacklist(blacklistJson[message.author.id] , message)
2018-10-07 10:05:26 +02:00
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-14 17:47:25 +02:00
return message.channel.send({files: [responseObject[despacitoNumber]]}).catch(error => {
message.say('an error as occured')
})
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-11-13 15:20:23 +01:00
message.say(`${user.username}, you have been despacito'd`, attachment).catch(error => {
2018-10-14 17:47:25 +02:00
message.say('an error as occured')
})
2018-10-13 11:22:55 +02:00
}
}
2018-09-08 01:50:13 +02:00
};