mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-05 00:06:42 +02:00
iTunes Command, Remove SoundCloud
This commit is contained in:
@@ -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!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiaobot",
|
||||
"version": "38.8.0",
|
||||
"version": "39.0.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Shard.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user