From 374b2e1919da5ce7d87aba1e484754a28bd80e2a Mon Sep 17 00:00:00 2001 From: Emily J Date: Wed, 28 Oct 2020 12:18:11 +1100 Subject: [PATCH] colour gen command --- bot/commands/Fun/colour.js | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 bot/commands/Fun/colour.js diff --git a/bot/commands/Fun/colour.js b/bot/commands/Fun/colour.js new file mode 100644 index 0000000..8a9d1ec --- /dev/null +++ b/bot/commands/Fun/colour.js @@ -0,0 +1,47 @@ +const Embed = require('../../util/embed'); + +module.exports = class { + constructor (name, category) { + this.name = name, + this.category = category, + this.enabled = true, + this.devOnly = false, + this.aliases = ['color'], + this.userPerms = [], + this.botPerms = [], + this.cooldown = 2000, + this.help = { + description: 'Shows you colours that can be random, a hex code or generated from the words you type into the command.', + usage: 'colour ', + examples: '`colour` - generates a random colour\n`colour #ee79ff` - Displays the colour of this hexcode\n`colour alpaca` - Generates a colour from the word alpaca' + }; + } + + run (client, message, args, data) { //eslint-disable-line no-unused-vars + let colour; + + if (!args[0]) { + colour = client.functions.randomColour(); + } else if (args[0].match(/#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)) { + colour = args[0]; + } else { + let hash = 0; + const string = args.join(' '); + for (let i = 0; i < string.length; i++) { + hash = string.charCodeAt(i) + ((hash << 5) - hash); + } + colour = '#'; + for (let i = 0; i < 3; i++) { + const value = (hash >> (i * 8)) & 0xFF; + colour += ('00' + value.toString(16)).substr(-2); + } + } + + const embed = new Embed() + .setTitle(colour) + .setColor(colour) + .setImage(`https://fakeimg.pl/256x256/${colour.replace('#', '')}/?text=%20`); + + message.channel.createMessage({ embed: embed }); + } +}; \ No newline at end of file