From 0e29e8c74b15949cd07534a39e37549b6afcf425 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 23 Apr 2020 18:18:15 -0400 Subject: [PATCH] Fix various bugs, more aliases --- commands/analyze/birthstone.js | 2 +- commands/analyze/gender.js | 2 +- commands/events/horoscope.js | 6 ++--- commands/info/id.js | 2 +- commands/info/server.js | 28 +++++++++---------- commands/info/user.js | 37 ++++++++++---------------- commands/random-res/draw-cards.js | 2 +- commands/random-res/number-fact.js | 1 + commands/random-res/shower-thought.js | 2 +- commands/random-res/suggest-command.js | 2 +- commands/search/derpibooru.js | 24 ++++++++--------- commands/search/league-of-legends.js | 3 +-- package.json | 2 +- 13 files changed, 49 insertions(+), 64 deletions(-) diff --git a/commands/analyze/birthstone.js b/commands/analyze/birthstone.js index b3755f13..bdda2e14 100644 --- a/commands/analyze/birthstone.js +++ b/commands/analyze/birthstone.js @@ -13,7 +13,7 @@ module.exports = class BirthstoneCommand extends Command { args: [ { key: 'month', - prompt: 'What month would you like to get the Zodiac Sign for?', + prompt: 'What month would you like to get the birthstone for?', type: 'month' } ] diff --git a/commands/analyze/gender.js b/commands/analyze/gender.js index 53c15117..6c84b179 100644 --- a/commands/analyze/gender.js +++ b/commands/analyze/gender.js @@ -32,7 +32,7 @@ module.exports = class GenderCommand extends Command { .get(`https://api.genderize.io/`) .query({ name }); if (!body.gender) return msg.say(`I have no idea what gender ${body.name} is.`); - return msg.say(`I'm ${body.probability * 100}% sure ${body.name} is a ${body.gender} name.`); + return msg.say(`I'm ${Math.round(body.probability * 100)}% sure ${body.name} is a ${body.gender} name.`); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/events/horoscope.js b/commands/events/horoscope.js index 80d2d7a7..308547a1 100644 --- a/commands/events/horoscope.js +++ b/commands/events/horoscope.js @@ -40,7 +40,7 @@ module.exports = class HoroscopeCommand extends Command { const embed = new MessageEmbed() .setColor(0x9797FF) .setTitle(`Horoscope for ${firstUpperCase(sign)}...`) - .setURL(`https://new.theastrologer.com/${sign}/`) + .setURL(`https://astrology.tv/horoscope/signs/${sign}/`) .setFooter('© Kelli Fox, The Astrologer') .setTimestamp() .setDescription(horoscope); @@ -51,8 +51,8 @@ module.exports = class HoroscopeCommand extends Command { } async fetchHoroscope(sign) { - const { text } = await request.get(`https://new.theastrologer.com/${sign}/`); + const { text } = await request.get(`https://astrology.tv/horoscope/signs/${sign}/`); const $ = cheerio.load(text); - return $('#today').find('p').first().text(); + return $('div[class="ct-text-block day-tabs-content_horoscope"]').eq(1).text(); } }; diff --git a/commands/info/id.js b/commands/info/id.js index 1185045f..581bc0f6 100644 --- a/commands/info/id.js +++ b/commands/info/id.js @@ -20,6 +20,6 @@ module.exports = class IDCommand extends Command { } run(msg, { user }) { - return msg.say(`${user.username}'s ID is ${user.id}.`); + return msg.reply(`${user.id === msg.author.id ? 'Your' : `${user.username}'s`} ID is ${user.id}.`); } }; diff --git a/commands/info/server.js b/commands/info/server.js index e129f31b..10932d0b 100644 --- a/commands/info/server.js +++ b/commands/info/server.js @@ -1,7 +1,6 @@ const Command = require('../../structures/Command'); const moment = require('moment'); const { MessageEmbed } = require('discord.js'); -const { stripIndents } = require('common-tags'); const filterLevels = { DISABLED: 'Off', MEMBERS_WITHOUT_ROLES: 'No Role', @@ -33,21 +32,18 @@ module.exports = class ServerCommand extends Command { const embed = new MessageEmbed() .setColor(0x00AE86) .setThumbnail(msg.guild.iconURL({ format: 'png' })) - .setAuthor(msg.guild.name) - .setDescription(stripIndents` - **General Info:** - • ID: ${msg.guild.id} - • Owner: ${msg.guild.owner.user.tag} - • Region: ${msg.guild.region.toUpperCase()} - • Creation Date: ${moment.utc(msg.guild.createdAt).format('MM/DD/YYYY h:mm A')} - • Explicit Filter: ${filterLevels[msg.guild.explicitContentFilter]} - • Verification Level: ${verificationLevels[msg.guild.verificationLevel]} - - **Server Stats:** - • Members: ${msg.guild.memberCount} - • Roles: ${msg.guild.roles.cache.size} - • Channels: ${msg.guild.channels.cache.filter(channel => channel.type !== 'category').size} - `); + .addField('❯ Name', msg.guild.name, true) + .addField('❯ ID', msg.guild.id, true) + .addField('❯ Creation Date', moment.utc(msg.guild.createdAt).format('MM/DD/YYYY h:mm A'), true) + .addField('❯ Owner', msg.guild.owner.user.tag, true) + .addField('❯ Boost Count', msg.guild.premiumSubscriptionCount || 0, true) + .addField('❯ Boost Tier', msg.guild.premiumTier ? `Tier ${msg.guild.premiumTier}` : 'None', true) + .addField('❯ Region', msg.guild.region.toUpperCase(), true) + .addField('❯ Explicit Filter', filterLevels[msg.guild.explicitContentFilter], true) + .addField('❯ Verification Level', verificationLevels[msg.guild.verificationLevel], true) + .addField('❯ Members', msg.guild.memberCount, true) + .addField('❯ Roles', msg.guild.roles.cache.size, true) + .addField('❯ Channels', msg.guild.channels.cache.filter(channel => channel.type !== 'category').size, true); return msg.embed(embed); } }; diff --git a/commands/info/user.js b/commands/info/user.js index 4ce1b802..7b732107 100644 --- a/commands/info/user.js +++ b/commands/info/user.js @@ -1,7 +1,6 @@ const Command = require('../../structures/Command'); const moment = require('moment'); const { MessageEmbed } = require('discord.js'); -const { stripIndents } = require('common-tags'); const { trimArray } = require('../../util/Util'); const flags = { DISCORD_EMPLOYEE: 'Discord Employee', @@ -40,17 +39,14 @@ module.exports = class UserCommand extends Command { } async run(msg, { user }) { - const embed = new MessageEmbed() - .setAuthor(user.tag) - .setThumbnail(user.displayAvatarURL({ format: 'png', dynamic: true })); const userFlags = user.flags.toArray(); - let description = stripIndents` - **General User Info:** - • ID: ${user.id} - • Discord Join Date: ${moment.utc(user.createdAt).format('MM/DD/YYYY h:mm A')} - • ${user.bot ? 'Bot' : 'Not a Bot'} - • Flags: ${userFlags.length ? userFlags.map(flag => flags[flag]).join(', ') : 'None'} - `; + const embed = new MessageEmbed() + .setThumbnail(user.displayAvatarURL({ format: 'png', dynamic: true })) + .setAuthor(user.tag) + .addField('❯ Discord Join Date', moment.utc(user.createdAt).format('MM/DD/YYYY h:mm A'), true) + .addField('❯ ID', user.id, true) + .addField('❯ Bot?', user.bot ? 'Yes' : 'No', true) + .addField('❯ Flags', userFlags.length ? userFlags.map(flag => flags[flag]).join(', ') : 'None'); if (msg.guild) { try { const member = await msg.guild.members.fetch(user.id); @@ -59,18 +55,13 @@ module.exports = class UserCommand extends Command { .filter(role => role.id !== defaultRole.id) .sort((a, b) => b.position - a.position) .map(role => role.name); - description += '\n\n'; - description += stripIndents` - **Server Member Info:** - • Nickname: ${member.nickname || 'None'} - • Server Join Date: ${moment.utc(member.joinedAt).format('MM/DD/YYYY h:mm A')} - • Highest Role: ${member.roles.highest.id === defaultRole.id ? 'None' : member.roles.highest.name} - • Hoist Role: ${member.roles.hoist ? member.roles.hoist.name : 'None'} - - **Roles (${roles.length})** - • ${roles.length ? trimArray(roles, 6).join(', ') : 'None'} - `; - embed.setColor(member.displayHexColor); + embed + .addField('❯ Server Join Date', moment.utc(member.joinedAt).format('MM/DD/YYYY h:mm A'), true) + .addField('❯ Highest Role', + member.roles.highest.id === defaultRole.id ? 'None' : member.roles.highest.name, true) + .addField('❯ Hoist Role', member.roles.hoist ? member.roles.hoist.name : 'None', true) + .addField(`❯ Roles (${roles.length})`, roles.length ? trimArray(roles, 6).join(', ') : 'None') + .setColor(member.displayHexColor); } catch { embed.setFooter('Failed to resolve member, showing basic user information instead.'); } diff --git a/commands/random-res/draw-cards.js b/commands/random-res/draw-cards.js index 20886f75..377ae653 100644 --- a/commands/random-res/draw-cards.js +++ b/commands/random-res/draw-cards.js @@ -36,7 +36,7 @@ module.exports = class DrawCardsCommand extends Command { if (!this.deck) this.deck = this.generateDeck(); let cards = this.deck; if (!jokers) cards = cards.filter(card => !card.includes('Joker')); - return msg.reply(shuffle(cards).slice(0, amount).join('\n')); + return msg.reply(`${amount === 1 ? '' : '\n'}${shuffle(cards).slice(0, amount).join('\n')}`); } generateDeck() { diff --git a/commands/random-res/number-fact.js b/commands/random-res/number-fact.js index 8e7d068c..b2bc04df 100644 --- a/commands/random-res/number-fact.js +++ b/commands/random-res/number-fact.js @@ -5,6 +5,7 @@ module.exports = class NumberFactCommand extends Command { constructor(client) { super(client, { name: 'number-fact', + aliases: ['num-fact'], group: 'random-res', memberName: 'number-fact', description: 'Responds with a random fact about a specific number.', diff --git a/commands/random-res/shower-thought.js b/commands/random-res/shower-thought.js index 9094bd9e..9909b4e7 100644 --- a/commands/random-res/shower-thought.js +++ b/commands/random-res/shower-thought.js @@ -4,7 +4,7 @@ module.exports = class ShowerThoughtCommand extends SubredditCommand { constructor(client) { super(client, { name: 'shower-thought', - aliases: ['shower-thoughts'], + aliases: ['shower-thoughts', 'shower', 's-thought', 'shower-t'], group: 'random-res', memberName: 'shower-thought', description: 'Responds with a random shower thought, directly from r/Showerthoughts.', diff --git a/commands/random-res/suggest-command.js b/commands/random-res/suggest-command.js index 9f05c652..a4a027d8 100644 --- a/commands/random-res/suggest-command.js +++ b/commands/random-res/suggest-command.js @@ -5,7 +5,7 @@ module.exports = class SuggestCommandCommand extends Command { constructor(client) { super(client, { name: 'suggest-command', - aliases: ['command-suggestion', 'command-suggest'], + aliases: ['command-suggestion', 'command-suggest', 'suggest-cmd', 'cmd-suggest'], group: 'random-res', memberName: 'suggest-command', description: 'Suggests a random command for you to try.' diff --git a/commands/search/derpibooru.js b/commands/search/derpibooru.js index 2de11d03..3809e8cb 100644 --- a/commands/search/derpibooru.js +++ b/commands/search/derpibooru.js @@ -27,9 +27,9 @@ module.exports = class DerpibooruCommand extends Command { async run(msg, { query }) { try { - const id = await this.search(query); - if (!id) return msg.say('Could not find any results.'); - const url = await this.fetchImage(id); + const url = await this.search(query, msg.channel.nsfw || false); + if (!url) return msg.say('Could not find any results.'); + if (url === 'nsfw') return msg.say('The image I found was NSFW, and this isn\'t the channel for that.'); return msg.say(url); } catch (err) { if (err.status === 404) return msg.say('Could not find any results.'); @@ -37,19 +37,17 @@ module.exports = class DerpibooruCommand extends Command { } } - async search(query) { + async search(query, nsfw) { const { body } = await request - .get('https://derpibooru.org/search.json') + .get('https://derpibooru.org/api/v1/json/search') .query({ q: query, - random_image: 1 + per_page: 1, + sf: 'random' }); - if (!body) return null; - return body.id; - } - - async fetchImage(id) { - const { body } = await request.get(`https://derpibooru.org/images/${id}.json`); - return `http:${body.representations.full}`; + if (!body || !body.images || !body.images.length) return null; + const image = body.images[0]; + if (!image.tags.includes('safe') && !nsfw) return 'nsfw'; + return image.representations.full; } }; diff --git a/commands/search/league-of-legends.js b/commands/search/league-of-legends.js index 092fd9c0..e4f1d7b1 100644 --- a/commands/search/league-of-legends.js +++ b/commands/search/league-of-legends.js @@ -59,8 +59,7 @@ module.exports = class LeagueOfLegendsCommand extends Command { .addField('❯ Armor', `${data.stats.armor} (${data.stats.armorperlevel}/level)`, true) .addField('❯ Attack Damage', `${data.stats.attackdamage} (${data.stats.attackdamageperlevel}/level)`, true) .addField('❯ Attack Range', data.stats.attackrange, true) - .addField('❯ Attack Speed Offset', - `${data.stats.attackspeedoffset} (${data.stats.attackspeedperlevel}/level)`, true) + .addField('❯ Attack Speed', `${data.stats.attackspeed} (${data.stats.attackspeedperlevel}/level)`, true) .addField('❯ Crit', `${data.stats.crit} (${data.stats.critperlevel}/level)`, true) .addField('❯ Move Speed', data.stats.movespeed, true) .addField('❯ Spell Block', `${data.stats.spellblock} (${data.stats.spellblockperlevel}/level)`, true) diff --git a/package.json b/package.json index 48df4617..29cd2493 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "113.15.2", + "version": "113.15.3", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {