From 321ebf2066b44647e8d83069b463e3d3498f9f50 Mon Sep 17 00:00:00 2001 From: dragonfire535 Date: Fri, 15 Sep 2017 16:52:45 -0400 Subject: [PATCH] iTunes Command, Remove SoundCloud --- commands/search/itunes.js | 70 +++++++++++++++++++++++++++++++++++ commands/search/soundcloud.js | 55 --------------------------- package.json | 2 +- 3 files changed, 71 insertions(+), 56 deletions(-) create mode 100644 commands/search/itunes.js delete mode 100644 commands/search/soundcloud.js diff --git a/commands/search/itunes.js b/commands/search/itunes.js new file mode 100644 index 00000000..b7a3f884 --- /dev/null +++ b/commands/search/itunes.js @@ -0,0 +1,70 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const snekfetch = require('snekfetch'); +const { list } = require('../../structures/Util'); +const countries = ['us', 'jp']; + +module.exports = class iTunesCommand extends Command { + constructor(client) { + super(client, { + name: 'itunes', + aliases: ['song', 'music', 'apple-music', 'itunes-music'], + group: 'search', + memberName: 'itunes', + description: 'Searches iTunes for your query.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'country', + prompt: `What country should results be obtained for? Either ${list(countries, 'or')}.`, + type: 'string', + validate: country => { + if (countries.includes(country)) return true; + return `Invalid country, please enter either ${list(countries, 'or')}.`; + }, + parse: country => country.toLowerCase() + }, + { + key: 'query', + prompt: 'What song would you like to search for?', + type: 'string' + } + ] + }); + } + + async run(msg, args) { + const { country, query } = args; + try { + const { text } = await snekfetch + .get('https://itunes.apple.com/search') + .query({ + term: query, + media: 'music', + entity: 'song', + limit: 1, + explicit: msg.channel.nsfw ? 'yes' : 'no', + country + }); + const body = JSON.parse(text); + if (!body.resultCount) return msg.say('Could not find any results.'); + const embed = new MessageEmbed() + .setColor(0xFEFEFE) + .setAuthor('iTunes', 'https://i.imgur.com/TbqzJFs.jpg') + .setURL(body.results[0].trackViewUrl) + .setThumbnail(body.results[0].artworkUrl100) + .setTitle(body.results[0].trackName) + .addField('❯ Artist', + body.results[0].artistName, true) + .addField('❯ Album', + body.results[0].collectionName, true) + .addField('❯ Release Date', + new Date(body.results[0].releaseDate).toDateString(), true) + .addField('❯ Genre', + body.results[0].primaryGenreName, 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/soundcloud.js b/commands/search/soundcloud.js deleted file mode 100644 index 7702c16a..00000000 --- a/commands/search/soundcloud.js +++ /dev/null @@ -1,55 +0,0 @@ -const Command = require('../../structures/Command'); -const { MessageEmbed } = require('discord.js'); -const snekfetch = require('snekfetch'); -const { SOUNDCLOUD_KEY } = process.env; - -module.exports = class SoundCloudCommand extends Command { - constructor(client) { - super(client, { - name: 'soundcloud', - group: 'search', - memberName: 'soundcloud', - description: 'Searches SoundCloud for your query.', - clientPermissions: ['EMBED_LINKS'], - args: [ - { - key: 'query', - prompt: 'What song would you like to search for?', - type: 'string' - } - ] - }); - } - - async run(msg, args) { - const { query } = args; - try { - const { body } = await snekfetch - .get('https://api.soundcloud.com/tracks') - .query({ - q: query, - client_id: SOUNDCLOUD_KEY - }); - if (!body.length) return msg.say('Could not find any results.'); - const embed = new MessageEmbed() - .setColor(0xF15A22) - .setAuthor('SoundCloud', 'https://i.imgur.com/lFIz7RU.png') - .setTitle(body[0].title) - .setURL(body[0].permalink_url) - .setThumbnail(body[0].artwork_url) - .addField('❯ Artist', - body[0].user.username) - .addField('❯ Download Count', - body[0].download_count, true) - .addField('❯ Comment Count', - body[0].comment_count, true) - .addField('❯ Playback Count', - body[0].playback_count, true) - .addField('❯ Favorited Count', - body[0].favoritings_count, true); - return msg.embed(embed); - } catch (err) { - return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } - } -}; diff --git a/package.json b/package.json index d749c88a..a9b5278a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "38.8.0", + "version": "39.0.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {