From 8bcbb3902c4eb3ca875645bd79f99ee69058cdf0 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Tue, 12 Dec 2017 04:06:26 +0000 Subject: [PATCH] IGDB Command, Minor changes --- commands/events/horoscope.js | 2 +- commands/info/emoji.js | 2 +- commands/info/role.js | 4 +- commands/search/github.js | 4 +- commands/search/igdb.js | 60 +++++++++++++++++++ commands/search/kickstarter.js | 6 +- commands/search/league-of-legends-champion.js | 33 ++++++---- commands/search/npm.js | 4 +- commands/search/stack-overflow.js | 2 +- commands/search/steam.js | 2 +- commands/search/twitter.js | 2 +- commands/search/wattpad.js | 4 +- package.json | 2 +- 13 files changed, 101 insertions(+), 26 deletions(-) create mode 100644 commands/search/igdb.js diff --git a/commands/events/horoscope.js b/commands/events/horoscope.js index b7c8e84e..83635114 100644 --- a/commands/events/horoscope.js +++ b/commands/events/horoscope.js @@ -34,7 +34,7 @@ module.exports = class HoroscopeCommand extends Command { const embed = new MessageEmbed() .setColor(0x9797FF) .setTitle(`Horoscope for ${body.sunsign}...`) - .setURL('https://new.theastrologer.com/horoscopes/') + .setURL(`https://new.theastrologer.com/${body.sunsign}/`) .setTimestamp() .setDescription(body.horoscope) .addField('❯ Mood', diff --git a/commands/info/emoji.js b/commands/info/emoji.js index 3f17e5cc..b368df2f 100644 --- a/commands/info/emoji.js +++ b/commands/info/emoji.js @@ -31,7 +31,7 @@ module.exports = class EmojiInfoCommand extends Command { emoji.id, true) .addField('❯ Creation Date', emoji.createdAt.toDateString(), true) - .addField('❯ External', + .addField('❯ External?', emoji.managed ? 'Yes' : 'No', true); return msg.embed(embed); } diff --git a/commands/info/role.js b/commands/info/role.js index a164eff1..b0baf064 100644 --- a/commands/info/role.js +++ b/commands/info/role.js @@ -35,9 +35,9 @@ module.exports = class RoleInfoCommand extends Command { role.hexColor.toUpperCase(), true) .addField('❯ Creation Date', role.createdAt.toDateString(), true) - .addField('❯ Hoisted', + .addField('❯ Hoisted?', role.hoist ? 'Yes' : 'No', true) - .addField('❯ Mentionable', + .addField('❯ Mentionable?', role.mentionable ? 'Yes' : 'No', true) .addField('❯ Permissions', perms.map(perm => permissions[perm]).join(', ') || 'None'); diff --git a/commands/search/github.js b/commands/search/github.js index d6ff3386..ef956121 100644 --- a/commands/search/github.js +++ b/commands/search/github.js @@ -48,9 +48,9 @@ module.exports = class GitHubCommand extends Command { body.open_issues, true) .addField('❯ Language', body.language || '???', true) - .addField('❯ Created', + .addField('❯ Creation Date', new Date(body.created_at).toDateString(), true) - .addField('❯ Modified', + .addField('❯ Modification Date', new Date(body.updated_at).toDateString(), true); return msg.embed(embed); } catch (err) { diff --git a/commands/search/igdb.js b/commands/search/igdb.js new file mode 100644 index 00000000..c34adf95 --- /dev/null +++ b/commands/search/igdb.js @@ -0,0 +1,60 @@ +const { Command } = require('discord.js-commando'); +const { MessageEmbed } = require('discord.js'); +const snekfetch = require('snekfetch'); +const { shorten } = require('../../util/Util'); +const { IGDB_KEY } = process.env; +const esrb = ['RP', 'EC', 'E', 'E10+', 'T', 'M', 'AO']; +const statuses = ['Released', '???', 'Alpha', 'Beta', 'Early Access', 'Offline', 'Cancelled']; + +module.exports = class IGDBCommand extends Command { + constructor(client) { + super(client, { + name: 'igdb', + aliases: ['igdb-video-game', 'game', 'video-game', 'game'], + group: 'search', + memberName: 'igdb', + description: 'Searches IGDB for your query.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'query', + prompt: 'What video game would you like to search for?', + type: 'string' + } + ] + }); + } + + async run(msg, { query }) { + try { + const { body } = await snekfetch + .get('https://api-2445582011268.apicast.io/games/') + .query({ + search: query, + limit: 1, + fields: '*', + 'filter[version_parent][not_exists]': 1 + }) + .set({ 'user-key': IGDB_KEY }); + const data = body[0]; + const embed = new MessageEmbed() + .setColor(0x01DF6B) + .setTitle(data.name) + .setURL(data.url) + .setAuthor('IGDB', 'https://i.imgur.com/LHLQEns.png') + .setDescription(data.summary ? shorten(data.summary) : 'No description available.') + .setThumbnail(data.cover ? data.cover.url : null) + .addField('❯ ESRB Rating', + data.esrb ? esrb[data.esrb.rating] : '???', true) + .addField('❯ Release Date', + data.first_release_date ? new Date(data.first_release_date * 1000).toDateString() : '???', true) + .addField('❯ Status', + data.status ? statuses[data.status] : '???', true) + .addField('❯ Score', + data.total_rating || '???', 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/kickstarter.js b/commands/search/kickstarter.js index c0be3e14..cd813213 100644 --- a/commands/search/kickstarter.js +++ b/commands/search/kickstarter.js @@ -46,7 +46,11 @@ module.exports = class KickstarterCommand extends Command { .addField('❯ Backers', data.backers_count, true) .addField('❯ Creator', - data.creator.name, true); + data.creator.name, true) + .addField('❯ Creation Date', + new Date(data.created_at * 1000).toDateString(), true) + .addField('❯ Deadline', + new Date(data.deadline * 1000).toDateString(), 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/league-of-legends-champion.js b/commands/search/league-of-legends-champion.js index b621237a..d6453509 100644 --- a/commands/search/league-of-legends-champion.js +++ b/commands/search/league-of-legends-champion.js @@ -24,21 +24,14 @@ module.exports = class LeagueOfLegendsChampionCommand extends Command { }); this.version = null; - this.client.setInterval(() => { this.version = null; }, 3600000); } async run(msg, { champion }) { if (champion === 'satan') champion = 'teemo'; try { - if (!this.version) this.version = await this.fetchVersion(); - const search = await snekfetch - .get(`https://ddragon.leagueoflegends.com/cdn/${this.version}/data/en_US/champion.json`); - const name = Object.keys(search.body.data).find(key => key.toLowerCase() === champion); - if (!name) return msg.say('Could not find any results.'); - const { id } = search.body.data[name]; - const { body } = await snekfetch - .get(`https://ddragon.leagueoflegends.com/cdn/${this.version}/data/en_US/champion/${id}.json`); - const data = body.data[id]; + if (!this.version) await this.fetchVersion(); + const data = await this.fetchChampion(champion); + if (!data) return msg.say('Could not find any results.'); const tips = [].concat(data.allytips, data.enemytips); const embed = new MessageEmbed() .setColor(0x002366) @@ -92,6 +85,24 @@ module.exports = class LeagueOfLegendsChampionCommand extends Command { const { body } = await snekfetch .get('https://na1.api.riotgames.com/lol/static-data/v3/versions') .query({ api_key: RIOT_KEY }); - return body[0]; + [this.version] = body; + this.client.setInterval(() => { this.version = null; }, 3600000); + return body; + } + + async fetchChampions() { + const { body } = await snekfetch + .get(`https://ddragon.leagueoflegends.com/cdn/${this.version}/data/en_US/champion.json`); + return body; + } + + async fetchChampion(champion) { + const champions = await this.fetchChampions(); + const name = Object.keys(champions.data).find(key => key.toLowerCase() === champion); + if (!name) return null; + const { id } = champions.data[name]; + const { body } = await snekfetch + .get(`https://ddragon.leagueoflegends.com/cdn/${this.version}/data/en_US/champion/${id}.json`); + return body.data[id]; } }; diff --git a/commands/search/npm.js b/commands/search/npm.js index 297a04f1..823a5f25 100644 --- a/commands/search/npm.js +++ b/commands/search/npm.js @@ -42,9 +42,9 @@ module.exports = class NPMCommand extends Command { body.license || 'None', true) .addField('❯ Author', body.author ? body.author.name : 'Unknown', true) - .addField('❯ Created', + .addField('❯ Creation Date', new Date(body.time.created).toDateString(), true) - .addField('❯ Modified', + .addField('❯ Modification Date', new Date(body.time.modified).toDateString(), true) .addField('❯ Main File', version.main || '???', true) diff --git a/commands/search/stack-overflow.js b/commands/search/stack-overflow.js index 3b668fce..ab98f18c 100644 --- a/commands/search/stack-overflow.js +++ b/commands/search/stack-overflow.js @@ -51,7 +51,7 @@ module.exports = class StackOverflowCommand extends Command { data.view_count, true) .addField('❯ Score', data.score, true) - .addField('❯ Created', + .addField('❯ Creation Date', new Date(data.creation_date * 1000).toDateString(), true) .addField('❯ Last Activity', new Date(data.last_activity_date * 1000).toDateString(), true); diff --git a/commands/search/steam.js b/commands/search/steam.js index 7e4785ad..19ef1e3f 100644 --- a/commands/search/steam.js +++ b/commands/search/steam.js @@ -59,7 +59,7 @@ module.exports = class SteamCommand extends Command { data.recommendations ? data.recommendations.total : '???', true) .addField('❯ Platforms', platforms.join(', ') || 'None', true) - .addField('❯ Release Data', + .addField('❯ Release Date', data.release_date ? data.release_date.date : '???', true) .addField('❯ DLC Count', data.dlc ? data.dlc.length : 0, true) diff --git a/commands/search/twitter.js b/commands/search/twitter.js index fc2ba300..647da649 100644 --- a/commands/search/twitter.js +++ b/commands/search/twitter.js @@ -48,7 +48,7 @@ module.exports = class TwitterCommand extends Command { body.protected ? 'Yes' : 'No', true) .addField('❯ Verified?', body.verified ? 'Yes' : 'No', true) - .addField('❯ Created', + .addField('❯ Creation Date', new Date(body.created_at).toDateString(), true) .addField('❯ Latest Tweet', body.status ? body.status.text : 'None'); diff --git a/commands/search/wattpad.js b/commands/search/wattpad.js index 3d7b9ce2..e521d3df 100644 --- a/commands/search/wattpad.js +++ b/commands/search/wattpad.js @@ -41,11 +41,11 @@ module.exports = class WattpadCommand extends Command { .setTitle(data.title) .setDescription(shorten(data.description)) .setThumbnail(data.cover) - .addField('❯ Created On', + .addField('❯ Creation Date', new Date(data.createDate).toDateString(), true) .addField('❯ Author', data.user, true) - .addField('❯ Parts', + .addField('❯ Chapters', data.numParts, true) .addField('❯ Reads', data.readCount, true) diff --git a/package.json b/package.json index ba8bb7be..d14416e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "56.5.1", + "version": "56.6.0", "description": "Your personal server companion.", "main": "XiaoBot.js", "scripts": {