Format numbers, style changes, fixes

This commit is contained in:
Daniel Odendahl Jr
2018-10-13 02:28:07 +00:00
parent 5c2c9d25a5
commit b0780575be
45 changed files with 146 additions and 159 deletions
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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) {
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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 {
+13 -11
View File
@@ -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]);
}
};
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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(', ')}
`);
}
+2 -1
View File
@@ -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));
}
};
+2 -1
View File
@@ -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!`);
+3 -2
View File
@@ -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.`);
}
};
+2 -1
View File
@@ -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) {
+2 -1
View File
@@ -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));
}
};
+2 -1
View File
@@ -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.');
}
+2 -2
View File
@@ -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)}`);
}
};
+1 -1
View File
@@ -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) {
@@ -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
});
+2 -1
View File
@@ -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)}`);
}
};
+2 -1
View File
@@ -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)}.`);
}
};
+12 -8
View File
@@ -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];
}
};
+10 -9
View File
@@ -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})
+4 -4
View File
@@ -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);
+2 -2
View File
@@ -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) {
+4 -4
View File
@@ -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);
+2 -2
View File
@@ -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);
+7 -2
View File
@@ -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);
+2 -1
View File
@@ -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!`);
+8 -7
View File
@@ -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!`);
+2 -1
View File
@@ -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);
+2 -2
View File
@@ -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!`);
+3 -2
View File
@@ -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);
+3 -2
View File
@@ -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);
+3 -4
View File
@@ -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!`);
+3 -3
View File
@@ -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(', ') : '???');
+2 -1
View File
@@ -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) {
+4 -4
View File
@@ -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)
+5 -13
View File
@@ -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) {
+5 -5
View File
@@ -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!`);
+1 -7
View File
@@ -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!`);
+3 -3
View File
@@ -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) {
+3 -18
View File
@@ -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('');
}
};
+1 -16
View File
@@ -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.',
+4 -3
View File
@@ -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)
+3 -2
View File
@@ -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\`
`);
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "94.1.2",
"version": "95.0.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
+4
View File
@@ -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;