From b0780575be4ab4df99c83ad5b06caa3cdd9a8250 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sat, 13 Oct 2018 02:28:07 +0000 Subject: [PATCH] Format numbers, style changes, fixes --- README.md | 2 +- commands/games/gunfight.js | 2 +- commands/games/mafia.js | 2 +- commands/games/math-quiz.js | 2 +- commands/games/tic-tac-toe.js | 24 ++++++++++--------- commands/games/wizard-convention.js | 2 +- commands/info/discriminator.js | 2 +- commands/number-edit/character-count.js | 3 ++- commands/number-edit/currency.js | 3 ++- commands/number-edit/gravity.js | 5 ++-- commands/number-edit/prime.js | 3 ++- commands/number-edit/scrabble-score.js | 3 ++- commands/number-edit/units.js | 3 ++- commands/random/meme.js | 4 ++-- commands/random/quantum-coin.js | 2 +- .../{user-roulette.js => random-user.js} | 8 +++---- commands/random/reddit.js | 3 ++- commands/random/roll.js | 3 ++- commands/random/superpower.js | 20 +++++++++------- commands/search/azur-lane-ship.js | 19 ++++++++------- commands/search/github.js | 8 +++---- commands/search/google-book.js | 4 ++-- commands/search/kickstarter.js | 8 +++---- commands/search/kitsu-anime.js | 4 ++-- commands/search/kitsu-manga.js | 9 +++++-- commands/search/neopets-item.js | 3 ++- commands/search/osu.js | 15 ++++++------ commands/search/reddit-user.js | 3 ++- commands/search/soundcloud.js | 4 ++-- commands/search/stack-overflow.js | 5 ++-- commands/search/steam.js | 5 ++-- commands/search/stocks.js | 7 +++--- commands/search/tmdb-tv-show.js | 6 ++--- commands/search/tumblr.js | 3 ++- commands/search/twitter.js | 8 +++---- commands/search/urban-dictionary.js | 18 ++++---------- commands/search/wattpad.js | 10 ++++---- commands/search/weather.js | 8 +------ commands/search/yu-gi-oh.js | 6 ++--- commands/text-edit/binary.js | 21 +++------------- commands/text-edit/organization-xiii-name.js | 17 +------------ commands/util/info.js | 7 +++--- commands/util/ping.js | 5 ++-- package.json | 2 +- util/Util.js | 4 ++++ 45 files changed, 146 insertions(+), 159 deletions(-) rename commands/random/{user-roulette.js => random-user.js} (61%) diff --git a/README.md b/README.md index 3c8dda3f..23a8dc3e 100644 --- a/README.md +++ b/README.md @@ -309,7 +309,7 @@ the [home server](https://discord.gg/sbMe32W). * **alphabet-reverse:** Reverses the alphabet of text. * **base64:** Converts text to/from Base64. -* **binary:** Converts text to/from binary. +* **binary:** Converts text to binary. * **braille:** Converts text to braille. * **brony-speak:** Converts text to brony speak. * **clap:** Sends 👏 text 👏 like 👏 this. diff --git a/commands/games/gunfight.js b/commands/games/gunfight.js index 9e64aaeb..70a534a0 100644 --- a/commands/games/gunfight.js +++ b/commands/games/gunfight.js @@ -1,6 +1,6 @@ const Command = require('../../structures/Command'); const { delay, randomRange, verify } = require('../../util/Util'); -const words = ['fire', 'draw', 'shoot', 'bang', 'pull']; +const words = ['fire', 'draw', 'shoot', 'bang', 'pull', 'boom']; module.exports = class GunfightCommand extends Command { constructor(client) { diff --git a/commands/games/mafia.js b/commands/games/mafia.js index 77576a18..d1554122 100644 --- a/commands/games/mafia.js +++ b/commands/games/mafia.js @@ -66,7 +66,6 @@ module.exports = class MafiaCommand extends Command { } const display = killed ? players.get(killed).user : null; const story = stories[Math.floor(Math.random() * stories.length)]; - if (killed && killed !== saved) players.delete(killed); if (killed && killed === saved) { await msg.say(stripIndents` Late last night, a Mafia member emerged from the dark and tried to kill ${display}${story} @@ -80,6 +79,7 @@ module.exports = class MafiaCommand extends Command { `); break; } else if (killed && killed !== saved) { + players.delete(killed); await msg.say(stripIndents` Late last night, a Mafia member emerged from the dark and killed poor ${display}${story} Who is this mysterious Mafia member? You have one minute to decide. diff --git a/commands/games/math-quiz.js b/commands/games/math-quiz.js index 9aada7f5..2bbda06d 100644 --- a/commands/games/math-quiz.js +++ b/commands/games/math-quiz.js @@ -8,7 +8,7 @@ const maxValues = { medium: 100, hard: 500, extreme: 1000, - impossible: 1000000 + impossible: Number.MAX_SAFE_INTEGER }; module.exports = class MathQuizCommand extends Command { diff --git a/commands/games/tic-tac-toe.js b/commands/games/tic-tac-toe.js index 513ee495..47454aad 100644 --- a/commands/games/tic-tac-toe.js +++ b/commands/games/tic-tac-toe.js @@ -22,7 +22,7 @@ module.exports = class TicTacToeCommand extends Command { this.playing = new Set(); } - async run(msg, { opponent }) { // eslint-disable-line complexity + async run(msg, { opponent }) { if (opponent.bot) return msg.reply('Bots may not be played against.'); if (opponent.id === msg.author.id) return msg.reply('You may not play against yourself.'); if (this.playing.has(msg.channel.id)) return msg.reply('Only one game may be occurring per channel.'); @@ -67,16 +67,7 @@ module.exports = class TicTacToeCommand extends Command { const choice = turn.first().content; sides[Number.parseInt(choice, 10)] = sign; taken.push(choice); - if ( - (sides[0] === sides[1] && sides[0] === sides[2]) - || (sides[0] === sides[3] && sides[0] === sides[6]) - || (sides[3] === sides[4] && sides[3] === sides[5]) - || (sides[1] === sides[4] && sides[1] === sides[7]) - || (sides[6] === sides[7] && sides[6] === sides[8]) - || (sides[2] === sides[5] && sides[2] === sides[8]) - || (sides[0] === sides[4] && sides[0] === sides[8]) - || (sides[2] === sides[4] && sides[2] === sides[6]) - ) winner = userTurn ? msg.author : opponent; + if (this.verifyWin(sides)) winner = userTurn ? msg.author : opponent; userTurn = !userTurn; } this.playing.delete(msg.channel.id); @@ -86,4 +77,15 @@ module.exports = class TicTacToeCommand extends Command { throw err; } } + + verifyWin(sides) { + return (sides[0] === sides[1] && sides[0] === sides[2]) + || (sides[0] === sides[3] && sides[0] === sides[6]) + || (sides[3] === sides[4] && sides[3] === sides[5]) + || (sides[1] === sides[4] && sides[1] === sides[7]) + || (sides[6] === sides[7] && sides[6] === sides[8]) + || (sides[2] === sides[5] && sides[2] === sides[8]) + || (sides[0] === sides[4] && sides[0] === sides[8]) + || (sides[2] === sides[4] && sides[2] === sides[6]); + } }; diff --git a/commands/games/wizard-convention.js b/commands/games/wizard-convention.js index e9a4ddcd..380657de 100644 --- a/commands/games/wizard-convention.js +++ b/commands/games/wizard-convention.js @@ -66,7 +66,6 @@ module.exports = class WizardConventionCommand extends Command { } const display = eaten ? players.get(eaten).user : null; const story = stories[Math.floor(Math.random() * stories.length)]; - if (eaten && eaten !== healed) players.delete(eaten); if (eaten && eaten === healed) { await msg.say(stripIndents` Late last night, a dragon emerged and tried to eat ${display}${story} @@ -80,6 +79,7 @@ module.exports = class WizardConventionCommand extends Command { `); break; } else if (eaten && eaten !== healed) { + players.delete(eaten); await msg.say(stripIndents` Late last night, a dragon emerged and devoured poor ${display}${story} Who is this mysterious dragon? You have one minute to decide. diff --git a/commands/info/discriminator.js b/commands/info/discriminator.js index ef869c69..05206a7d 100644 --- a/commands/info/discriminator.js +++ b/commands/info/discriminator.js @@ -29,7 +29,7 @@ module.exports = class DiscriminatorCommand extends Command { run(msg, { discrim }) { const users = this.client.users.filter(user => user.discriminator === discrim).map(user => user.username); return msg.say(stripIndents` - **Found ${users.length} users with the discriminator #${discrim}** + **Found ${users.length} users with the discriminator #${discrim}:** ${trimArray(users, 50).join(', ')} `); } diff --git a/commands/number-edit/character-count.js b/commands/number-edit/character-count.js index 45e94519..08931247 100644 --- a/commands/number-edit/character-count.js +++ b/commands/number-edit/character-count.js @@ -1,4 +1,5 @@ const Command = require('../../structures/Command'); +const { formatNumber } = require('../../util/Util'); module.exports = class CharacterCountCommand extends Command { constructor(client) { @@ -19,6 +20,6 @@ module.exports = class CharacterCountCommand extends Command { } run(msg, { text }) { - return msg.reply(text.length); + return msg.reply(formatNumber(text.length)); } }; diff --git a/commands/number-edit/currency.js b/commands/number-edit/currency.js index 5d3d3ebe..da503352 100644 --- a/commands/number-edit/currency.js +++ b/commands/number-edit/currency.js @@ -1,5 +1,6 @@ const Command = require('../../structures/Command'); const request = require('node-superfetch'); +const { formatNumber } = require('../../util/Util'); module.exports = class CurrencyCommand extends Command { constructor(client) { @@ -41,7 +42,7 @@ module.exports = class CurrencyCommand extends Command { if (base === target) return msg.say(`Converting ${base} to ${target} is the same value, dummy.`); try { const rate = await this.fetchRate(base, target); - return msg.say(`${amount} ${base} is ${(amount * rate).toFixed(2)} ${target}.`); + return msg.say(`${formatNumber(amount)} ${base} is ${formatNumber(amount * rate)} ${target}.`); } catch (err) { if (err.status === 400) return msg.say('Invalid base/target.'); return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/number-edit/gravity.js b/commands/number-edit/gravity.js index aef3f943..5e8058a6 100644 --- a/commands/number-edit/gravity.js +++ b/commands/number-edit/gravity.js @@ -1,5 +1,5 @@ const Command = require('../../structures/Command'); -const { list, firstUpperCase } = require('../../util/Util'); +const { list, firstUpperCase, formatNumber } = require('../../util/Util'); const planets = require('../../assets/json/gravity'); module.exports = class GravityCommand extends Command { @@ -28,6 +28,7 @@ module.exports = class GravityCommand extends Command { } run(msg, { weight, planet }) { - return msg.say(`${weight} kg on ${firstUpperCase(planet)} is ${weight * planets[planet]} kg.`); + const result = weight * planets[planet]; + return msg.say(`${formatNumber(weight)} kg on ${firstUpperCase(planet)} is ${formatNumber(result)} kg.`); } }; diff --git a/commands/number-edit/prime.js b/commands/number-edit/prime.js index 97f64cc7..59208acf 100644 --- a/commands/number-edit/prime.js +++ b/commands/number-edit/prime.js @@ -1,4 +1,5 @@ const Command = require('../../structures/Command'); +const { formatNumber } = require('../../util/Util'); module.exports = class PrimeCommand extends Command { constructor(client) { @@ -20,7 +21,7 @@ module.exports = class PrimeCommand extends Command { } run(msg, { number }) { - return msg.reply(`${number} is${this.isPrime(number) ? '' : ' not'} a prime number.`); + return msg.reply(`${formatNumber(number)} is${this.isPrime(number) ? '' : ' not'} a prime number.`); } isPrime(number) { diff --git a/commands/number-edit/scrabble-score.js b/commands/number-edit/scrabble-score.js index 78a4a4ae..334022a1 100644 --- a/commands/number-edit/scrabble-score.js +++ b/commands/number-edit/scrabble-score.js @@ -1,4 +1,5 @@ const Command = require('../../structures/Command'); +const { formatNumber } = require('../../util/Util'); const letters = require('../../assets/json/scrabble-score'); module.exports = class ScrabbleScoreCommand extends Command { @@ -26,6 +27,6 @@ module.exports = class ScrabbleScoreCommand extends Command { if (!letters[letter]) continue; score += letters[letter]; } - return msg.reply(score); + return msg.reply(formatNumber(score)); } }; diff --git a/commands/number-edit/units.js b/commands/number-edit/units.js index e266047a..37323d1a 100644 --- a/commands/number-edit/units.js +++ b/commands/number-edit/units.js @@ -1,5 +1,6 @@ const Command = require('../../structures/Command'); const math = require('mathjs'); +const { formatNumber } = require('../../util/Util'); module.exports = class UnitsCommand extends Command { constructor(client) { @@ -34,7 +35,7 @@ module.exports = class UnitsCommand extends Command { run(msg, { base, target, amount }) { try { const value = math.unit(amount, base).toNumber(target); - return msg.say(`${amount} ${base} is ${value} ${target}.`); + return msg.say(`${formatNumber(amount)} ${base} is ${formatNumber(value)} ${target}.`); } catch (err) { return msg.say('Either an invalid unit type was provided or the unit types do not match.'); } diff --git a/commands/random/meme.js b/commands/random/meme.js index 9548dc32..89aee31c 100644 --- a/commands/random/meme.js +++ b/commands/random/meme.js @@ -1,6 +1,6 @@ const SubredditCommand = require('../../structures/commands/Subreddit'); const { MessageEmbed } = require('discord.js'); -const { list } = require('../../util/Util'); +const { list, formatNumber } = require('../../util/Util'); const subreddits = require('../../assets/json/meme'); module.exports = class MemeCommand extends SubredditCommand { @@ -34,6 +34,6 @@ module.exports = class MemeCommand extends SubredditCommand { .setImage(post.post_hint === 'image' ? post.url : null) .setURL(`https://www.reddit.com${post.permalink}`) .setTimestamp(post.created_utc * 1000) - .setFooter(`⬆ ${post.ups}`); + .setFooter(`⬆ ${formatNumber(post.ups)}`); } }; diff --git a/commands/random/quantum-coin.js b/commands/random/quantum-coin.js index b08f40c4..37f74b84 100644 --- a/commands/random/quantum-coin.js +++ b/commands/random/quantum-coin.js @@ -1,5 +1,5 @@ const Command = require('../../structures/Command'); -const sides = ['NaN', '0', 'null', 'undefined', '\'\'']; +const sides = [NaN, 0, null, undefined, '']; module.exports = class QuantumCoinCommand extends Command { constructor(client) { diff --git a/commands/random/user-roulette.js b/commands/random/random-user.js similarity index 61% rename from commands/random/user-roulette.js rename to commands/random/random-user.js index 9c3a6d4a..f17ffcb0 100644 --- a/commands/random/user-roulette.js +++ b/commands/random/random-user.js @@ -1,12 +1,12 @@ const Command = require('../../structures/Command'); -module.exports = class UserRouletteCommand extends Command { +module.exports = class RandomUserCommand extends Command { constructor(client) { super(client, { - name: 'user-roulette', - aliases: ['member-roulette', 'random-user', 'random-member'], + name: 'random-user', + aliases: ['member-roulette', 'user-roulette', 'random-member'], group: 'random', - memberName: 'user-roulette', + memberName: 'random-user', description: 'Randomly chooses a member of the server.', guildOnly: true }); diff --git a/commands/random/reddit.js b/commands/random/reddit.js index f0fa4a0e..af213c25 100644 --- a/commands/random/reddit.js +++ b/commands/random/reddit.js @@ -1,5 +1,6 @@ const SubredditCommand = require('../../structures/commands/Subreddit'); const { MessageEmbed } = require('discord.js'); +const { formatNumber } = require('../../util/Util'); module.exports = class RedditCommand extends SubredditCommand { constructor(client) { @@ -29,6 +30,6 @@ module.exports = class RedditCommand extends SubredditCommand { .setImage(post.post_hint === 'image' ? post.url : null) .setURL(`https://www.reddit.com${post.permalink}`) .setTimestamp(post.created_utc * 1000) - .setFooter(`⬆ ${post.ups}`); + .setFooter(`⬆ ${formatNumber(post.ups)}`); } }; diff --git a/commands/random/roll.js b/commands/random/roll.js index 240a9297..2cca5a5b 100644 --- a/commands/random/roll.js +++ b/commands/random/roll.js @@ -1,4 +1,5 @@ const Command = require('../../structures/Command'); +const { formatNumber } = require('../../util/Util'); module.exports = class RollCommand extends Command { constructor(client) { @@ -21,6 +22,6 @@ module.exports = class RollCommand extends Command { } run(msg, { value }) { - return msg.say(`You rolled a ${Math.floor(Math.random() * value) + 1}.`); + return msg.say(`You rolled a ${formatNumber(Math.floor(Math.random() * value) + 1)}.`); } }; diff --git a/commands/random/superpower.js b/commands/random/superpower.js index 387780c0..fea4b610 100644 --- a/commands/random/superpower.js +++ b/commands/random/superpower.js @@ -15,21 +15,18 @@ module.exports = class SuperpowerCommand extends Command { async run(msg) { try { - const article = await this.randomSuperpower(); - const { body } = await request - .get('http://powerlisting.wikia.com/api/v1/Articles/AsSimpleJson/') - .query({ id: article }); - const data = body.sections[0]; + const id = await this.random(); + const article = this.fetchSuperpower(id); return msg.reply(stripIndents` - Your superpower is... **${data.title}**! - _${shorten(data.content.map(section => section.text).join('\n\n'), 1950)}_ + Your superpower is... **${article.title}**! + _${shorten(article.content.map(section => section.text).join('\n\n'), 1950)}_ `); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } } - async randomSuperpower() { + async random() { const { body } = await request .get('http://powerlisting.wikia.com/api.php') .query({ @@ -42,4 +39,11 @@ module.exports = class SuperpowerCommand extends Command { }); return body.query.random[0].id; } + + async fetchSuperpower(id) { + const { body } = await request + .get('http://powerlisting.wikia.com/api/v1/Articles/AsSimpleJson/') + .query({ id }); + return body.sections[0]; + } }; diff --git a/commands/search/azur-lane-ship.js b/commands/search/azur-lane-ship.js index ec196959..f90d6e98 100644 --- a/commands/search/azur-lane-ship.js +++ b/commands/search/azur-lane-ship.js @@ -2,6 +2,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); const { stripIndents } = require('common-tags'); +const { formatNumber } = require('../../util/Util'); module.exports = class AzurLaneShipCommand extends Command { constructor(client) { @@ -40,16 +41,16 @@ module.exports = class AzurLaneShipCommand extends Command { .addField('❯ Rarity', data.rarity, true) .addField('❯ Nationality', data.nationality, true) .addField('❯ Type', data.type, true) - .addField('❯ Health', `${data.base.health} (${data.max.health} Max)`, true) + .addField('❯ Health', `${formatNumber(data.base.health)} (${formatNumber(data.max.health)} Max)`, true) .addField('❯ Armor', data.base.armor, true) - .addField('❯ Reload', `${data.base.reload} (${data.max.reload} Max)`, true) - .addField('❯ Firepower', `${data.base.firepower} (${data.max.firepower} Max)`, true) - .addField('❯ Torpedo', `${data.base.torpedo} (${data.max.torpedo} Max)`, true) - .addField('❯ Evasion', `${data.base.speed} (${data.max.speed} Max)`, true) - .addField('❯ Anti-Air', `${data.base.anti_air} (${data.max.anti_air} Max)`, true) - .addField('❯ Anti-Sub', `${data.base.anti_sub} (${data.max.anti_sub} Max)`, true) - .addField('❯ Aviation', `${data.base.air_power} (${data.max.air_power} Max)`, true) - .addField('❯ Oil Cost', `${data.base.oil_usage} (${data.max.oil_usage} Max)`, true) + .addField('❯ Reload', `${formatNumber(data.base.reload)} (${formatNumber(data.max.reload)} Max)`, true) + .addField('❯ Firepower', `${formatNumber(data.base.firepower)} (${formatNumber(data.max.firepower)} Max)`, true) + .addField('❯ Torpedo', `${formatNumber(data.base.torpedo)} (${formatNumber(data.max.torpedo)} Max)`, true) + .addField('❯ Evasion', `${formatNumber(data.base.speed)} (${formatNumber(data.max.speed)} Max)`, true) + .addField('❯ Anti-Air', `${formatNumber(data.base.anti_air)} (${formatNumber(data.max.anti_air)} Max)`, true) + .addField('❯ Anti-Sub', `${formatNumber(data.base.anti_sub)} (${formatNumber(data.max.anti_sub)} Max)`, true) + .addField('❯ Aviation', `${formatNumber(data.base.air_power)} (${formatNumber(data.max.air_power)} Max)`, true) + .addField('❯ Oil Cost', `${formatNumber(data.base.oil_usage)} (${formatNumber(data.max.oil_usage)} Max)`, true) .addField('❯ Equipment', stripIndents` ${data.equipment[0].equippable} (${data.equipment[0].efficiency}) ${data.equipment[1].equippable} (${data.equipment[1].efficiency}) diff --git a/commands/search/github.js b/commands/search/github.js index 9a8d1045..c13a2382 100644 --- a/commands/search/github.js +++ b/commands/search/github.js @@ -2,7 +2,7 @@ const Command = require('../../structures/Command'); const moment = require('moment'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); -const { shorten, base64 } = require('../../util/Util'); +const { shorten, formatNumber, base64 } = require('../../util/Util'); const { GITHUB_USERNAME, GITHUB_PASSWORD } = process.env; module.exports = class GithubCommand extends Command { @@ -43,9 +43,9 @@ module.exports = class GithubCommand extends Command { .setURL(body.html_url) .setDescription(body.description ? shorten(body.description) : 'No description.') .setThumbnail(body.owner.avatar_url) - .addField('❯ Stars', body.stargazers_count, true) - .addField('❯ Forks', body.forks, true) - .addField('❯ Issues', body.open_issues, true) + .addField('❯ Stars', formatNumber(body.stargazers_count), true) + .addField('❯ Forks', formatNumber(body.forks), true) + .addField('❯ Issues', formatNumber(body.open_issues), true) .addField('❯ Language', body.language || '???', true) .addField('❯ Creation Date', moment.utc(body.created_at).format('MM/DD/YYYY h:mm A'), true) .addField('❯ Modification Date', moment.utc(body.updated_at).format('MM/DD/YYYY h:mm A'), true); diff --git a/commands/search/google-book.js b/commands/search/google-book.js index c6187e7b..a5d0ff3d 100644 --- a/commands/search/google-book.js +++ b/commands/search/google-book.js @@ -1,7 +1,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); -const { shorten } = require('../../util/Util'); +const { shorten, formatNumber } = require('../../util/Util'); const { GOOGLE_KEY } = process.env; module.exports = class GoogleBookCommand extends Command { @@ -44,7 +44,7 @@ module.exports = class GoogleBookCommand extends Command { .setThumbnail(data.imageLinks ? data.imageLinks.thumbnail : null) .addField('❯ Authors', data.authors.length ? data.authors.join(', ') : '???') .addField('❯ Publish Date', data.publishedDate || '???', true) - .addField('❯ Page Count', data.pageCount || '???', true) + .addField('❯ Page Count', data.pageCount ? formatNumber(data.pageCount) : '???', true) .addField('❯ Genres', data.categories.length ? data.categories.join(', ') : '???'); return msg.embed(embed); } catch (err) { diff --git a/commands/search/kickstarter.js b/commands/search/kickstarter.js index 6e7a3dfe..96e2dac9 100644 --- a/commands/search/kickstarter.js +++ b/commands/search/kickstarter.js @@ -2,7 +2,7 @@ const Command = require('../../structures/Command'); const moment = require('moment'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); -const { shorten } = require('../../util/Util'); +const { shorten, formatNumber } = require('../../util/Util'); module.exports = class KickstarterCommand extends Command { constructor(client) { @@ -40,9 +40,9 @@ module.exports = class KickstarterCommand extends Command { .setAuthor('Kickstarter', 'https://i.imgur.com/EHDlH5t.png', 'https://www.kickstarter.com/') .setDescription(shorten(data.blurb)) .setThumbnail(data.photo ? data.photo.full : null) - .addField('❯ Goal', `$${data.goal}`, true) - .addField('❯ Pledged', `$${data.pledged}`, true) - .addField('❯ Backers', data.backers_count, true) + .addField('❯ Goal', `$${formatNumber(data.goal)}`, true) + .addField('❯ Pledged', `$${formatNumber(data.pledged)}`, true) + .addField('❯ Backers', formatNumber(data.backers_count), true) .addField('❯ Creator', data.creator.name, true) .addField('❯ Creation Date', moment.utc(data.created_at * 1000).format('MM/DD/YYYY h:mm A'), true) .addField('❯ Deadline', moment.utc(data.deadline * 1000).format('MM/DD/YYYY h:mm A'), true); diff --git a/commands/search/kitsu-anime.js b/commands/search/kitsu-anime.js index 3d22759d..c651fb78 100644 --- a/commands/search/kitsu-anime.js +++ b/commands/search/kitsu-anime.js @@ -2,7 +2,7 @@ const Command = require('../../structures/Command'); const moment = require('moment'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); -const { shorten, firstUpperCase } = require('../../util/Util'); +const { shorten, formatNumber, firstUpperCase } = require('../../util/Util'); module.exports = class KitsuAnimeCommand extends Command { constructor(client) { @@ -39,7 +39,7 @@ module.exports = class KitsuAnimeCommand extends Command { .setTitle(data.canonicalTitle) .setDescription(shorten(data.synopsis)) .addField('❯ Type', `${firstUpperCase(data.showType)} - ${firstUpperCase(data.status)}`, true) - .addField('❯ Episodes', data.episodeCount || '???', true) + .addField('❯ Episodes', data.episodeCount ? formatNumber(data.episodeCount) : '???', true) .addField('❯ Start Date', data.startDate ? moment.utc(data.startDate).format('MM/DD/YYYY') : '???', true) .addField('❯ End Date', data.endDate ? moment.utc(data.endDate).format('MM/DD/YYYY') : '???', true); return msg.embed(embed); diff --git a/commands/search/kitsu-manga.js b/commands/search/kitsu-manga.js index 0e6a9048..a93ad07d 100644 --- a/commands/search/kitsu-manga.js +++ b/commands/search/kitsu-manga.js @@ -2,7 +2,8 @@ const Command = require('../../structures/Command'); const moment = require('moment'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); -const { shorten, firstUpperCase } = require('../../util/Util'); +const { oneLine } = require('common-tags'); +const { shorten, formatNumber, firstUpperCase } = require('../../util/Util'); module.exports = class KitsuMangaCommand extends Command { constructor(client) { @@ -39,7 +40,11 @@ module.exports = class KitsuMangaCommand extends Command { .setTitle(data.canonicalTitle) .setDescription(shorten(data.synopsis)) .addField('❯ Type', `${firstUpperCase(data.subtype)} - ${firstUpperCase(data.status)}`, true) - .addField('❯ Volumes / Chapters', `${data.volumeCount || '???'} / ${data.chapterCount || '???'}`, true) + .addField('❯ Volumes / Chapters', oneLine` + ${data.volumeCount ? formatNumber(data.volumeCount) : '???'} + / + ${data.chapterCount ? formatNumber(data.chapterCount) : '???'} + `, true) .addField('❯ Start Date', data.startDate ? moment.utc(data.startDate).format('MM/DD/YYYY') : '???', true) .addField('❯ End Date', data.endDate ? moment.utc(data.endDate).format('MM/DD/YYYY') : '???', true); return msg.embed(embed); diff --git a/commands/search/neopets-item.js b/commands/search/neopets-item.js index cd5ac8c5..ccbcbcb1 100644 --- a/commands/search/neopets-item.js +++ b/commands/search/neopets-item.js @@ -1,6 +1,7 @@ const Command = require('../../structures/Command'); const request = require('node-superfetch'); const { MessageEmbed } = require('discord.js'); +const { formatNumber } = require('../../util/Util'); module.exports = class NeopetsItemCommand extends Command { constructor(client) { @@ -32,7 +33,7 @@ module.exports = class NeopetsItemCommand extends Command { .setDescription(data.details) .setURL(data.url) .setThumbnail(data.image) - .addField('❯ Price', data.price ? `${data.price} ${data.currency}` : 'Not for Sale'); + .addField('❯ Price', data.price ? `${formatNumber(data.price)} ${data.currency}` : 'Not for Sale'); return msg.embed(embed); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/osu.js b/commands/search/osu.js index 963f0c17..9518846f 100644 --- a/commands/search/osu.js +++ b/commands/search/osu.js @@ -1,6 +1,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); +const { formatNumber } = require('../../util/Util'); const { OSU_KEY } = process.env; module.exports = class OsuCommand extends Command { @@ -40,14 +41,14 @@ module.exports = class OsuCommand extends Command { .addField('❯ ID', data.user_id, true) .addField('❯ Level', data.level || '???', true) .addField('❯ Accuracy', data.accuracy ? `${Math.round(data.accuracy)}%` : '???', true) - .addField('❯ Rank', data.pp_rank || '???', true) - .addField('❯ Play Count', data.playcount || '???', true) + .addField('❯ Rank', data.pp_rank ? formatNumber(data.pp_rank) : '???', true) + .addField('❯ Play Count', data.playcount ? formatNumber(data.playcount) : '???', true) .addField('❯ Country', data.country || '???', true) - .addField('❯ Ranked Score', data.ranked_score || '???', true) - .addField('❯ Total Score', data.total_score || '???', true) - .addField('❯ SS', data.count_rank_ss || '???', true) - .addField('❯ S', data.count_rank_s || '???', true) - .addField('❯ A', data.count_rank_a || '???', true); + .addField('❯ Ranked Score', data.ranked_score ? formatNumber(data.ranked_score) : '???', true) + .addField('❯ Total Score', data.total_score ? formatNumber(data.total_score) : '???', true) + .addField('❯ SS', data.count_rank_ss ? formatNumber(data.count_rank_ss) : '???', true) + .addField('❯ S', data.count_rank_s ? formatNumber(data.count_rank_s) : '???', true) + .addField('❯ A', data.count_rank_a ? formatNumber(data.count_rank_a) : '???', true); return msg.embed(embed); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/reddit-user.js b/commands/search/reddit-user.js index dd063a11..031bc362 100644 --- a/commands/search/reddit-user.js +++ b/commands/search/reddit-user.js @@ -2,6 +2,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); const moment = require('moment'); +const { formatNumber } = require('../../util/Util'); module.exports = class RedditUserCommand extends Command { constructor(client) { @@ -36,7 +37,7 @@ module.exports = class RedditUserCommand extends Command { .setTitle(`/u/${data.name}`) .addField('❯ Username', data.name, true) .addField('❯ ID', data.id, true) - .addField('❯ Karma', data.link_karma + data.comment_karma, true) + .addField('❯ Karma', formatNumber(data.link_karma + data.comment_karma), true) .addField('❯ Creation Date', moment.utc(data.created_utc * 1000).format('MM/DD/YYYY h:mm A'), true) .addField('❯ Gold?', data.is_gold ? 'Yes' : 'No', true) .addField('❯ Verified?', data.verified ? 'Yes' : 'No', true); diff --git a/commands/search/soundcloud.js b/commands/search/soundcloud.js index 17cf3d4d..3317448d 100644 --- a/commands/search/soundcloud.js +++ b/commands/search/soundcloud.js @@ -2,7 +2,7 @@ const Command = require('../../structures/Command'); const moment = require('moment'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); -const { shorten } = require('../../util/Util'); +const { shorten, formatNumber } = require('../../util/Util'); const { SOUNDCLOUD_KEY } = process.env; module.exports = class SoundcloudCommand extends Command { @@ -44,7 +44,7 @@ module.exports = class SoundcloudCommand extends Command { .addField('❯ Artist', `[${data.user.username}](${data.user.permalink_url})`, true) .addField('❯ Release Date', moment.utc(data.created_at).format('MM/DD/YYYY'), true) .addField('❯ Genre', data.genre, true) - .addField('❯ Likes', data.likes_count, true); + .addField('❯ Likes', formatNumber(data.likes_count), true); return msg.embed(embed); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/stack-overflow.js b/commands/search/stack-overflow.js index 042e07bf..bc25cbc0 100644 --- a/commands/search/stack-overflow.js +++ b/commands/search/stack-overflow.js @@ -2,6 +2,7 @@ const Command = require('../../structures/Command'); const moment = require('moment'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); +const { formatNumber } = require('../../util/Util'); const { STACKOVERFLOW_KEY } = process.env; module.exports = class StackOverflowCommand extends Command { @@ -46,8 +47,8 @@ module.exports = class StackOverflowCommand extends Command { .setTitle(data.title) .addField('❯ ID', data.question_id, true) .addField('❯ Asker', `[${data.owner.display_name}](${data.owner.link})`, true) - .addField('❯ Views', data.view_count, true) - .addField('❯ Score', data.score, true) + .addField('❯ Views', formatNumber(data.view_count), true) + .addField('❯ Score', formatNumber(data.score), true) .addField('❯ Creation Date', moment.utc(data.creation_date * 1000).format('MM/DD/YYYY h:mm A'), true) .addField('❯ Last Activity', moment.utc(data.last_activity_date * 1000).format('MM/DD/YYYY h:mm A'), true); diff --git a/commands/search/steam.js b/commands/search/steam.js index 6faf3186..4272f066 100644 --- a/commands/search/steam.js +++ b/commands/search/steam.js @@ -1,6 +1,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); +const { formatNumber } = require('../../util/Util'); module.exports = class SteamCommand extends Command { constructor(client) { @@ -43,10 +44,10 @@ module.exports = class SteamCommand extends Command { .setThumbnail(data.header_image) .addField('❯ Price', price, true) .addField('❯ Metascore', data.metacritic ? data.metacritic.score : '???', true) - .addField('❯ Recommendations', data.recommendations ? data.recommendations.total : '???', true) + .addField('❯ Recommendations', data.recommendations ? formatNumber(data.recommendations.total) : '???', true) .addField('❯ Platforms', platforms.join(', ') || 'None', true) .addField('❯ Release Date', data.release_date ? data.release_date.date : '???', true) - .addField('❯ DLC Count', data.dlc ? data.dlc.length : 0, true) + .addField('❯ DLC Count', data.dlc ? formatNumber(data.dlc.length) : 0, true) .addField('❯ Developers', data.developers ? data.developers.join(', ') || '???' : '???') .addField('❯ Publishers', data.publishers ? data.publishers.join(', ') || '???' : '???'); return msg.embed(embed); diff --git a/commands/search/stocks.js b/commands/search/stocks.js index 54f52a9c..7b29f238 100644 --- a/commands/search/stocks.js +++ b/commands/search/stocks.js @@ -1,5 +1,4 @@ const Command = require('../../structures/Command'); -const moment = require('moment'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); const { ALPHA_VANTAGE_KEY } = process.env; @@ -38,13 +37,13 @@ module.exports = class StocksCommand extends Command { const embed = new MessageEmbed() .setTitle(`Stocks for ${symbol.toUpperCase()}`) .setColor(0x9797FF) + .setFooter('Last Updated') + .setTimestamp(new Date(body['Meta Data']['3. Last Refreshed'])) .addField('❯ Open', `$${data['1. open']}`, true) .addField('❯ Close', `$${data['4. close']}`, true) .addField('❯ Volume', data['5. volume'], true) .addField('❯ High', `$${data['2. high']}`, true) - .addField('❯ Low', `$${data['3. low']}`, true) - .addField('❯ Last Updated', - moment.utc(body['Meta Data']['3. Last Refreshed']).format('MM/DD/YYYY h:mm A'), true); + .addField('❯ Low', `$${data['3. low']}`, true); return msg.embed(embed); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/tmdb-tv-show.js b/commands/search/tmdb-tv-show.js index c1d4a072..91dcf630 100644 --- a/commands/search/tmdb-tv-show.js +++ b/commands/search/tmdb-tv-show.js @@ -1,7 +1,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); -const { shorten } = require('../../util/Util'); +const { shorten, formatNumber } = require('../../util/Util'); const { TMDB_KEY } = process.env; module.exports = class TMDBTVShowCommand extends Command { @@ -45,8 +45,8 @@ module.exports = class TMDBTVShowCommand extends Command { .setThumbnail(body.poster_path ? `https://image.tmdb.org/t/p/w500${body.poster_path}` : null) .addField('❯ First Air Date', body.first_air_date || '???', true) .addField('❯ Last Air Date', body.last_air_date || '???', true) - .addField('❯ Seasons', body.number_of_seasons || '???', true) - .addField('❯ Episodes', body.number_of_episodes || '???', true) + .addField('❯ Seasons', body.number_of_seasons ? formatNumber(body.number_of_seasons) : '???', true) + .addField('❯ Episodes', body.number_of_episodes ? formatNumber(body.number_of_episodes) : '???', true) .addField('❯ Genres', body.genres.length ? body.genres.map(genre => genre.name).join(', ') : '???') .addField('❯ Production Companies', body.production_companies.length ? body.production_companies.map(c => c.name).join(', ') : '???'); diff --git a/commands/search/tumblr.js b/commands/search/tumblr.js index 921c119f..d312edca 100644 --- a/commands/search/tumblr.js +++ b/commands/search/tumblr.js @@ -1,6 +1,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); +const { formatNumber } = require('../../util/Util'); const { TUMBLR_KEY } = process.env; module.exports = class TumblrCommand extends Command { @@ -35,7 +36,7 @@ module.exports = class TumblrCommand extends Command { .setThumbnail(`https://api.tumblr.com/v2/blog/${blog}/avatar/512`) .setURL(data.url) .setTitle(data.title) - .addField('❯ Posts', data.total_posts, true) + .addField('❯ Posts', formatNumber(data.total_posts), true) .addField('❯ A.M.A.?', data.ask ? 'Yes' : 'No', true); return msg.embed(embed); } catch (err) { diff --git a/commands/search/twitter.js b/commands/search/twitter.js index d3b5f21c..60ba85f2 100644 --- a/commands/search/twitter.js +++ b/commands/search/twitter.js @@ -2,7 +2,7 @@ const Command = require('../../structures/Command'); const moment = require('moment'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); -const { base64 } = require('../../util/Util'); +const { formatNumber, base64 } = require('../../util/Util'); const { TWITTER_KEY, TWITTER_SECRET } = process.env; const retweetRegex = /^RT @([a-zA-Z0-9_]{1,15}):/; @@ -49,9 +49,9 @@ module.exports = class TwitterCommand extends Command { .setURL(`https://twitter.com/${body.screen_name}`) .setTitle(`${body.name} (@${body.screen_name})`) .setDescription(body.description) - .addField('❯ Tweets', body.statuses_count, true) - .addField('❯ Followers', body.followers_count, true) - .addField('❯ Following', body.friends_count, true) + .addField('❯ Tweets', formatNumber(body.statuses_count), true) + .addField('❯ Followers', formatNumber(body.followers_count), true) + .addField('❯ Following', formatNumber(body.friends_count), true) .addField('❯ Protected?', body.protected ? 'Yes' : 'No', true) .addField('❯ Verified?', body.verified ? 'Yes' : 'No', true) .addField('❯ Creation Date', moment.utc(body.created_at).format('MM/DD/YYYY h:mm A'), true) diff --git a/commands/search/urban-dictionary.js b/commands/search/urban-dictionary.js index ad828b65..5332f826 100644 --- a/commands/search/urban-dictionary.js +++ b/commands/search/urban-dictionary.js @@ -1,8 +1,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); -const { shorten } = require('../../util/Util'); -const types = ['random', 'top']; +const { shorten, formatNumber } = require('../../util/Util'); module.exports = class UrbanDictionaryCommand extends Command { constructor(client) { @@ -12,39 +11,32 @@ module.exports = class UrbanDictionaryCommand extends Command { group: 'search', memberName: 'urban-dictionary', description: 'Defines a word, but with Urban Dictionary.', - details: `**Types:** ${types.join(', ')}`, clientPermissions: ['EMBED_LINKS'], args: [ { key: 'word', prompt: 'What word would you like to look up?', type: 'string' - }, - { - key: 'type', - prompt: 'Do you want to get the top answer or a random one?', - type: 'string', - default: 'top', - oneOf: types, - parse: type => type.toLowerCase() } ] }); } - async run(msg, { word, type }) { + async run(msg, { word }) { try { const { body } = await request .get('http://api.urbandictionary.com/v0/define') .query({ term: word }); if (!body.list.length) return msg.say('Could not find any results.'); - const data = body.list[type === 'top' ? 0 : Math.floor(Math.random() * body.list.length)]; + const data = body.list[0]; const embed = new MessageEmbed() .setColor(0x32A8F0) .setAuthor('Urban Dictionary', 'https://i.imgur.com/Fo0nRTe.png', 'https://www.urbandictionary.com/') .setURL(data.permalink) .setTitle(data.word) .setDescription(shorten(data.definition)) + .setFooter(`👍 ${formatNumber(data.thumbs_up)} 👎 ${formatNumber(data.thumbs_down)}`) + .setTimestamp(new Date(data.written_on)) .addField('❯ Example', data.example ? shorten(data.example, 1000) : 'None'); return msg.embed(embed); } catch (err) { diff --git a/commands/search/wattpad.js b/commands/search/wattpad.js index 44467ae1..683e5b74 100644 --- a/commands/search/wattpad.js +++ b/commands/search/wattpad.js @@ -2,7 +2,7 @@ const Command = require('../../structures/Command'); const moment = require('moment'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); -const { shorten } = require('../../util/Util'); +const { shorten, formatNumber } = require('../../util/Util'); const { WATTPAD_KEY } = process.env; module.exports = class WattpadCommand extends Command { @@ -44,10 +44,10 @@ module.exports = class WattpadCommand extends Command { .setThumbnail(data.cover) .addField('❯ Creation Date', moment.utc(data.createDate).format('MM/DD/YYYY h:mm A'), true) .addField('❯ Author', data.user.name, true) - .addField('❯ Chapters', data.numParts, true) - .addField('❯ Reads', data.readCount, true) - .addField('❯ Votes', data.voteCount, true) - .addField('❯ Comments', data.commentCount, true); + .addField('❯ Chapters', formatNumber(data.numParts), true) + .addField('❯ Reads', formatNumber(data.readCount), true) + .addField('❯ Votes', formatNumber(data.voteCount), true) + .addField('❯ Comments', formatNumber(data.commentCount), true); return msg.embed(embed); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/weather.js b/commands/search/weather.js index de66f3dd..e4a93e4c 100644 --- a/commands/search/weather.js +++ b/commands/search/weather.js @@ -42,13 +42,7 @@ module.exports = class WeatherCommand extends Command { .addField('❯ Region', data.location.region, true) .addField('❯ Condition', data.item.condition.text, true) .addField('❯ Temperature', `${data.item.condition.temp}°F`, true) - .addField('❯ Humidity', data.atmosphere.humidity, true) - .addField('❯ Pressure', data.atmosphere.pressure, true) - .addField('❯ Rising', data.atmosphere.rising, true) - .addField('❯ Visibility', data.atmosphere.visibility, true) - .addField('❯ Wind Chill', data.wind.chill, true) - .addField('❯ Wind Direction', data.wind.direction, true) - .addField('❯ Wind Speed', data.wind.speed, true); + .addField('❯ Humidity', `${data.atmosphere.humidity}%`, true); return msg.embed(embed); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/yu-gi-oh.js b/commands/search/yu-gi-oh.js index a594570c..ba7574b3 100644 --- a/commands/search/yu-gi-oh.js +++ b/commands/search/yu-gi-oh.js @@ -1,7 +1,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const request = require('node-superfetch'); -const { shorten, firstUpperCase } = require('../../util/Util'); +const { shorten, formatNumber, firstUpperCase } = require('../../util/Util'); module.exports = class YuGiOhCommand extends Command { constructor(client) { @@ -42,8 +42,8 @@ module.exports = class YuGiOhCommand extends Command { .addField('❯ Species', data.type, true) .addField('❯ Attribute', firstUpperCase(data.family), true) .addField('❯ Level', data.level, true) - .addField('❯ ATK', data.atk, true) - .addField('❯ DEF', data.def, true); + .addField('❯ ATK', formatNumber(data.atk), true) + .addField('❯ DEF', formatNumber(data.def), true); } return msg.embed(embed); } catch (err) { diff --git a/commands/text-edit/binary.js b/commands/text-edit/binary.js index d1bd5d5d..4f57f975 100644 --- a/commands/text-edit/binary.js +++ b/commands/text-edit/binary.js @@ -1,6 +1,4 @@ const Command = require('../../structures/Command'); -const { list } = require('../../util/Util'); -const modes = ['encode', 'decode']; module.exports = class BinaryCommand extends Command { constructor(client) { @@ -8,16 +6,8 @@ module.exports = class BinaryCommand extends Command { name: 'binary', group: 'text-edit', memberName: 'binary', - description: 'Converts text to/from binary.', - details: `**Modes:** ${modes.join(', ')}`, + description: 'Converts text to binary.', args: [ - { - key: 'mode', - prompt: `Would you like to ${list(modes, 'or')}?`, - type: 'string', - oneOf: modes, - parse: mode => mode.toLowerCase() - }, { key: 'text', prompt: 'What text would you like to convert to binary?', @@ -31,9 +21,8 @@ module.exports = class BinaryCommand extends Command { }); } - run(msg, { mode, text }) { // eslint-disable-line consistent-return - if (mode === 'encode') return msg.say(this.binary(text)); - else if (mode === 'decode') return msg.say(this.unbinary(text)); + run(msg, { text }) { + return msg.say(this.binary(text)); } binary(text) { @@ -42,8 +31,4 @@ module.exports = class BinaryCommand extends Command { return converted.padStart(8, '0'); }).join(' '); } - - unbinary(text) { - return text.split(' ').map(str => String.fromCharCode(Number.parseInt(str, 2))).join(''); - } }; diff --git a/commands/text-edit/organization-xiii-name.js b/commands/text-edit/organization-xiii-name.js index 789e9707..fc5e0af3 100644 --- a/commands/text-edit/organization-xiii-name.js +++ b/commands/text-edit/organization-xiii-name.js @@ -5,22 +5,7 @@ module.exports = class OrganizationXIIINameCommand extends Command { constructor(client) { super(client, { name: 'organization-xiii-name', - aliases: [ - 'organization-xiii', - 'xiii-name', - 'xiii', - '13-name', - 'org-xiii-name', - 'org-xiii', - 'organization-13-name', - 'organization-13', - 'org-13-name', - 'org-13', - 'organization-name', - 'org-name', - 'org', - 'nobody-name' - ], + aliases: ['organization-xiii', 'org-xiii-name', 'org-xiii', 'organization-name', 'org-name', 'nobody-name'], group: 'text-edit', memberName: 'organization-xiii-name', description: 'Converts a name into the Organization XIII style.', diff --git a/commands/util/info.js b/commands/util/info.js index 07987fd7..5b548095 100644 --- a/commands/util/info.js +++ b/commands/util/info.js @@ -2,6 +2,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const moment = require('moment'); require('moment-duration-format'); +const { formatNumber } = require('../../util/Util'); const { version, dependencies } = require('../../package'); const { XIAO_GITHUB_REPO_USERNAME, XIAO_GITHUB_REPO_NAME } = process.env; const source = XIAO_GITHUB_REPO_NAME && XIAO_GITHUB_REPO_USERNAME; @@ -23,9 +24,9 @@ module.exports = class InfoCommand extends Command { const embed = new MessageEmbed() .setColor(0x00AE86) .setFooter('©2017-2018 dragonfire535#8081') - .addField('❯ Servers', this.client.guilds.size, true) - .addField('❯ Shards', this.client.options.shardCount, true) - .addField('❯ Commands', this.client.registry.commands.size, true) + .addField('❯ Servers', formatNumber(this.client.guilds.size), true) + .addField('❯ Shards', formatNumber(this.client.options.shardCount), true) + .addField('❯ Commands', formatNumber(this.client.registry.commands.size), true) .addField('❯ Home Server', this.client.options.invite ? `[Here](${this.client.options.invite})` : 'None', true) .addField('❯ Source Code', source ? `[Here](https://github.com/${XIAO_GITHUB_REPO_USERNAME}/${XIAO_GITHUB_REPO_NAME})` : 'N/A', true) diff --git a/commands/util/ping.js b/commands/util/ping.js index 6dcd9ed7..dd0e2273 100644 --- a/commands/util/ping.js +++ b/commands/util/ping.js @@ -1,5 +1,6 @@ const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); +const { formatNumber } = require('../../util/Util'); module.exports = class PingCommand extends Command { constructor(client) { @@ -17,8 +18,8 @@ module.exports = class PingCommand extends Command { const message = await msg.say('Pinging...'); const ping = Math.round(message.createdTimestamp - msg.createdTimestamp); return message.edit(stripIndents` - 🏓 P${'o'.repeat(Math.ceil(ping / 100))}ng! \`${ping}ms\` - Heartbeat: \`${Math.round(this.client.ping)}ms\` + 🏓 P${'o'.repeat(Math.min(Math.round(ping / 100), 1500))}ng! \`${formatNumber(ping)}ms\` + Heartbeat: \`${formatNumber(Math.round(this.client.ping))}ms\` `); } }; diff --git a/package.json b/package.json index 8632692a..22eecf86 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "94.1.2", + "version": "95.0.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/util/Util.js b/util/Util.js index 0c3d4ea5..c0a90751 100644 --- a/util/Util.js +++ b/util/Util.js @@ -45,6 +45,10 @@ module.exports = class Util { return text.split(split).map(word => `${word.charAt(0).toUpperCase()}${word.slice(1)}`).join(' '); } + static formatNumber(number) { + return Number.parseFloat(number).toLocaleString(undefined, { maximumFractionDigits: 2 }); + } + static base64(text, mode = 'encode') { if (mode === 'encode') return Buffer.from(text).toString('base64'); if (mode === 'decode') return Buffer.from(text, 'base64').toString('utf8') || null;