Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

Add Itunes command #1345

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
5a026a2
Add a Itunes command
puddingpy Oct 16, 2021
d5f1c0a
Merge branch 'dev' into dev
Doges Oct 16, 2021
4eeba9e
Update code with requested changes
puddingpy Oct 17, 2021
2f032a8
Make requested changes
puddingpy Oct 17, 2021
f087b79
Update .env and shard.js
puddingpy Oct 17, 2021
297553e
Make requested changes
puddingpy Oct 17, 2021
f115f10
Make requested changes
puddingpy Oct 17, 2021
4a87730
Merge branch 'dev' into dev
almeidx Oct 17, 2021
8ae2504
Use params while sending requests with axios
puddingpy Oct 17, 2021
5af5876
Set limit to the response data
puddingpy Oct 17, 2021
898059b
Formatting + Minor bugs
puddingpy Oct 17, 2021
a95e11f
Merge branch 'SwitchbladeBot:dev' into dev
puddingpy Oct 17, 2021
cbb1026
Bug fixes
puddingpy Oct 18, 2021
522bf0f
Update
puddingpy Oct 18, 2021
dfe0435
Make requested changes
puddingpy Oct 18, 2021
a00ed92
Bug fixes
puddingpy Oct 18, 2021
5fb79b0
Remove unused lines
puddingpy Oct 18, 2021
bc52e6e
Merge branch 'SwitchbladeBot:dev' into dev
puddingpy Oct 18, 2021
fb05f15
Add Birthday Command
puddingpy Oct 19, 2021
d83c670
Configure time
puddingpy Oct 19, 2021
b672ee0
Revert last commit
puddingpy Oct 19, 2021
1ca7856
Make requested changes
puddingpy Oct 22, 2021
98dd31e
Remove unnecessary lines
puddingpy Oct 22, 2021
e2045ac
Formatting
puddingpy Oct 22, 2021
3290cfc
Make requested changes
puddingpy Oct 23, 2021
845a3d7
Make requested changes
puddingpy Oct 23, 2021
31c7a18
Make requested changes
puddingpy Oct 25, 2021
3831d8f
Remove unnecesary line
puddingpy Oct 25, 2021
9c706bc
Make requested changes
puddingpy Oct 27, 2021
aff08d9
Fix
puddingpy Oct 27, 2021
ec90e04
Revert unwanted changes
almeidx Oct 31, 2021
b28f7bf
Update itunes.js
almeidx Oct 31, 2021
a7ab072
Merge branch 'SwitchbladeBot:dev' into dev
puddingpy Oct 31, 2021
bc3fdc3
Make requested changes
easedeath Oct 31, 2021
1af7138
Make requested changes
puddingpy Oct 31, 2021
cd51591
Make requested changes
puddingpy Oct 31, 2021
5c982d3
Fix errors
puddingpy Oct 31, 2021
b79eb1d
Update
puddingpy Oct 31, 2021
5ce4c2e
Update
puddingpy Oct 31, 2021
b33adc6
standard
almeidx Oct 31, 2021
1a3593b
Make requested changes
puddingpy Nov 1, 2021
7f5074c
Make requested changes
puddingpy Nov 3, 2021
0c045b2
Update
puddingpy Nov 3, 2021
291d7c6
Linting
puddingpy Nov 3, 2021
2b8ff18
Merge branch 'SwitchbladeBot:dev' into dev
puddingpy Nov 7, 2021
0772eec
Merge branch 'dev' into dev
puddingpy Nov 13, 2021
a6d6578
Make requested changes
puddingpy Nov 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/apis/Itunes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { APIWrapper } = require('..')
const axios = require('axios')

module.exports = class ITunes extends APIWrapper {
constructor () {
super({ name: 'itunes' })
}

async search (media, term, country) {
try {
const { data } = await axios.get('https://itunes.apple.com/search', {
params: {
media,
term,
country,
limit: 10
}
})

return [data.results, true]
} catch {
return [[], false]
}
}
}
69 changes: 69 additions & 0 deletions src/commands/misc/itunes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const { SwitchbladeEmbed, Command, Constants, CommandError } = require('../../')

const MEDIA_WHITE_LIST = ['movie', 'podcast', 'music', 'musicVideo', 'audiobook', 'shortFilm', 'tvShow', 'software', 'ebook', 'all']

module.exports = class Itunes extends Command {
constructor (client) {
super({
name: 'itunes',
requirements: { apis: ['itunes'] },
embedLogoURL: 'https://i.imgur.com/U4jjk5F.png',
parameters: [{
type: 'string',
full: false,
name: 'media',
whitelist: MEDIA_WHITE_LIST,
missingError: 'commands:itunes.notFound',
required: true
}, {
type: 'string',
name: 'country',
required: true,
missingError: 'commands:itunes.notFound'
}, {
type: 'string',
full: true,
name: 'term',
required: true,
missingError: 'commands:itunes.notFound'
}]
},
client)
}

async run ({ t, author, message, channel }, media, country, term) {
term = term.replaceAll(' ', '+')

const [data, response] = await this.client.apis.itunes.search(media, term, country)

if (!response) {
throw new CommandError(t('commands:itunes.invalidTerm'))
}

if (data.length === 0) {
throw new CommandError(t('commands:itunes.noResults'))
}

channel.send(this.parseResponse(author, t, data, message.content))
}

searchResultFormatter (i) {
return `[${i.trackName}](${i.trackViewUrl}) - [${i.artistName}](${i.artistViewUrl})`
}

getRatingEmojis (rating) {
return (this.getEmoji('ratingstar', '⭐').repeat(Math.floor(rating))) +
(this.getEmoji('ratinghalfstar')
.repeat(Math.ceil(rating - Math.floor(rating))))
}

parseResponse (author, t, data, title) {
const description = data.map((item, index) => `\`${String(index).padStart(2, '0')}\`: ${this.searchResultFormatter(item)}`)

return new SwitchbladeEmbed(author)
.setThumbnail(this.embedUrl)
.setDescription(description)
.setColor(Constants.ITUNES_COLOR)
.setTitle(t('commands:itunes.title', { title }))
}
}
8 changes: 8 additions & 0 deletions src/locales/en-US/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,14 @@
"commandUsage": "<text>",
"noText": "You have to give me some text to asciify!"
},
"itunes": {
"commandDescription": "Provides the content within the iTunes Store and Apple Books Store.",
"title": "Showing results for `{{title}}`",
"commandUsage": "<media> <country code> <term>",
"notFound": "I wasn't able to find the term with the given media.",
"noResults": "No results found.",
"invalidTerm": "Invalid term! Make sure that you are giving correct term."
},
"lorem": {
"commandDescription": "Generates a random lorem ipsum text with the specified amount of paragraphs.",
"commandUsage": "<number of paragraphs>",
Expand Down
1 change: 1 addition & 0 deletions src/utils/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
ERROR_COLOR: '#FF3333',
EIGHTBALL_COLOR: '#000000',
NPM_COLOR: '#CB3837',
ITUNES_COLOR: '#FF6283',
This conversation was marked as resolved.
Show resolved Hide resolved
GENERIC_RED_COLOR: '#CB3837',
E621_COLOR: '#258CF5',
XKCD_COLOR: '#96A8C8',
Expand Down