From be8c4f35d7ba803ae25429ad34c0813a1f27ff4a Mon Sep 17 00:00:00 2001 From: mudkipscience Date: Sun, 18 Dec 2022 17:44:03 +1100 Subject: [PATCH 1/2] DONE: colour 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..94d6d45 --- /dev/null +++ b/bot/commands/Fun/colour.js @@ -0,0 +1,47 @@ +const Command = require('../../base/Command.js'); + +module.exports = class Colour extends Command { + constructor (name, category) { + super (name, category); + this.name = name, + this.description = 'Shows you a random colour or a colour generated from a hex code or text.', + this.category = category; + this.options = [ + { + type: 3, + name: 'input', + description: 'hex code/text', + } + ]; + } + + async run (client, interaction, data) { //eslint-disable-line no-unused-vars + const input = await interaction.options.get('input'); + let color = null; + + if (!input) { + color = client.functions.randomColor(); + } else if (input.value.match(/#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)) { + color = input.value; + } else { + let hash = 0; + const string = input.value; + for (let i = 0; i < string.length; i++) { + hash = string.charCodeAt(i) + ((hash << 5) - hash); + } + color = '#'; + for (let i = 0; i < 3; i++) { + const value = (hash >> (i * 8)) & 0xFF; + color += ('00' + value.toString(16)).substr(-2); + } + } + + const embed = new client.EmbedBuilder() + .setTitle(color) + .setColor(color) + .setImage(`https://fakeimg.pl/256x256/${color.replace('#', '')}/?text=%20`) + .setFooter({ text: 'Wow, thats a pretty one!'}); + + interaction.reply({embeds: [embed]}); + } +}; \ No newline at end of file From 6f4545de4ce66c7585019b5c99d9b95fd514c8cb Mon Sep 17 00:00:00 2001 From: mudkipscience Date: Sun, 18 Dec 2022 17:45:22 +1100 Subject: [PATCH 2/2] grammar --- bot/commands/Fun/colour.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/commands/Fun/colour.js b/bot/commands/Fun/colour.js index 94d6d45..7198a3f 100644 --- a/bot/commands/Fun/colour.js +++ b/bot/commands/Fun/colour.js @@ -4,7 +4,7 @@ module.exports = class Colour extends Command { constructor (name, category) { super (name, category); this.name = name, - this.description = 'Shows you a random colour or a colour generated from a hex code or text.', + this.description = 'Shows you a random colour, or a colour generated from a hex code or text.', this.category = category; this.options = [ {