From ca65c960dafc2f4cccbad6ac3deb6afa234555b2 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 12 Apr 2020 09:26:00 -0400 Subject: [PATCH] Birthstone Command --- README.md | 3 ++- assets/json/birthstone.json | 44 ++++++++++++++++++++++++++++++++++ commands/analyze/birthstone.js | 28 ++++++++++++++++++++++ package.json | 2 +- util/Util.js | 2 ++ 5 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 assets/json/birthstone.json create mode 100644 commands/analyze/birthstone.js diff --git a/README.md b/README.md index 27e7ae23..30621b2b 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 384 +Total: 385 ### Utility: @@ -349,6 +349,7 @@ Total: 384 ### Analyzers: * **age:** Responds with how old someone born in a certain year is. +* **birthstone:** Responds with the Birthstone for a month. * **character-count:** Responds with the character count of text. * **chinese-zodiac:** Responds with the Chinese Zodiac Sign for the given year. * **face:** Determines the race, gender, and age of a face. diff --git a/assets/json/birthstone.json b/assets/json/birthstone.json new file mode 100644 index 00000000..5d054dbd --- /dev/null +++ b/assets/json/birthstone.json @@ -0,0 +1,44 @@ +[ + { + "primary": "Garnet" + }, + { + "primary": "Amethyst" + }, + { + "primary": "Aquamarine", + "alternative": ["Bloodstone"] + }, + { + "primary": "Diamond" + }, + { + "primary": "Emerald" + }, + { + "primary": "Pearl", + "alternative": ["Moonstone", "Alexandrite"] + }, + { + "primary": "Ruby" + }, + { + "primary": "Peridot", + "alternative": ["Spinel"] + }, + { + "primary": "Sapphire" + }, + { + "primary": "Opal", + "alternative": ["Tourmaline"] + }, + { + "primary": "Topaz", + "alternative": ["Citrine"] + }, + { + "primary": "Turquoise", + "alternative": ["Zircon", "Tanzanite"] + } +] diff --git a/commands/analyze/birthstone.js b/commands/analyze/birthstone.js new file mode 100644 index 00000000..901ebaba --- /dev/null +++ b/commands/analyze/birthstone.js @@ -0,0 +1,28 @@ +const Command = require('../../structures/Command'); +const { list } = require('../../util/Util'); +const months = require('../../assets/json/month'); +const stones = require('../../assets/json/birthstone'); + +module.exports = class BirthstoneCommand extends Command { + constructor(client) { + super(client, { + name: 'birthstone', + group: 'analyze', + memberName: 'birthstone', + description: 'Responds with the Birthstone for a month.', + args: [ + { + key: 'month', + prompt: 'What month would you like to get the Zodiac Sign for?', + type: 'month' + } + ] + }); + } + + run(msg, { month }) { + const stone = stones[month - 1]; + const alternate = stone.alternate ? ` Alternatively, you can also use ${list(stone.alternate, 'or')}.` : ''; + return msg.say(`The Birthstone for ${months[month - 1]} is ${stone.primary}.${alternate}`); + } +}; diff --git a/package.json b/package.json index 481eb35b..662b0c7f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "112.21.0", + "version": "112.22.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/util/Util.js b/util/Util.js index e4791e43..dc75016b 100644 --- a/util/Util.js +++ b/util/Util.js @@ -20,6 +20,8 @@ module.exports = class Util { static list(arr, conj = 'and') { const len = arr.length; + if (len === 0) return ''; + if (len === 1) return arr[0]; return `${arr.slice(0, -1).join(', ')}${len > 1 ? `${len > 2 ? ',' : ''} ${conj} ` : ''}${arr.slice(-1)}`; }