From 1bb1010a8e0053194aafeaf5fba2a34fa5e4f1ff Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Thu, 20 Apr 2017 13:27:41 +0000 Subject: [PATCH] SoundCloud Search Command --- README.md | 4 +-- commands/search/soundcloud.js | 59 +++++++++++++++++++++++++++++++++++ commands/util/info.js | 4 +-- html/carbondesc.html | 1 + html/discordbots.html | 1 + package.json | 2 +- 6 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 commands/search/soundcloud.js diff --git a/README.md b/README.md index d9ec7e21..34c3de61 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,14 @@ You can join the home server with [this link](https://discord.gg/fqQF8mc). [discord.js](https://discord.js.org/#/), [commando](https://github.com/Gawdl3y/discord.js-commando), [zalgoize](https://github.com/clux/zalgolize), [superagent](https://github.com/visionmedia/superagent), [mathjs](http://mathjs.org/), [moment](http://momentjs.com), [moment-duration-format](https://github.com/jsmreese/moment-duration-format), [jimp](https://github.com/oliver-moran/jimp), [cheerio](https://cheerio.js.org/) ## APIs -[Wattpad](https://developer.wattpad.com/docs/api), [Wordnik](http://developer.wordnik.com/docs.html), [osu!](https://osu.ppy.sh/p/api), [memegen.link](https://memegen.link/), [Yugioh Prices](http://docs.yugiohprices.apiary.io/#), [YouTube Data](https://developers.google.com/youtube/v3/), [Discord Bots](https://bots.discord.pw/api), [Today in History](http://history.muffinlabs.com/#api), [jService](http://jservice.io/), [Urban Dictionary](https://github.com/zdict/zdict/wiki/Urban-dictionary-API-documentation), [OMDB](http://www.omdbapi.com/), [Yahoo Weather](https://developer.yahoo.com/weather/), [Google Static Maps](https://developers.google.com/maps/documentation/static-maps/), [Strawpoll](https://github.com/strawpoll/strawpoll/wiki/API), [rrrather](http://www.rrrather.com/botapi) +[Wattpad](https://developer.wattpad.com/docs/api), [Wordnik](http://developer.wordnik.com/docs.html), [osu!](https://osu.ppy.sh/p/api), [memegen.link](https://memegen.link/), [Yugioh Prices](http://docs.yugiohprices.apiary.io/#), [YouTube Data](https://developers.google.com/youtube/v3/), [Discord Bots](https://bots.discord.pw/api), [Today in History](http://history.muffinlabs.com/#api), [jService](http://jservice.io/), [Urban Dictionary](https://github.com/zdict/zdict/wiki/Urban-dictionary-API-documentation), [OMDB](http://www.omdbapi.com/), [Yahoo Weather](https://developer.yahoo.com/weather/), [Google Static Maps](https://developers.google.com/maps/documentation/static-maps/), [Strawpoll](https://github.com/strawpoll/strawpoll/wiki/API), [rrrather](http://www.rrrather.com/botapi), [SoundCloud](https://developers.soundcloud.com/) ## Self-Hosting You can Self-Host the bot easily, provided you have API keys and a Discord Bot Token. [Node.js](https://nodejs.org/en/) is also required, with at least version 7.8.0 recommended. APIs that require API Keys: -[Wattpad](https://developer.wattpad.com/docs/api) | [Wordnik](http://developer.wordnik.com/docs.html) | [osu!](https://osu.ppy.sh/p/api) | [YouTube Data](https://developers.google.com/youtube/v3/) +[Wattpad](https://developer.wattpad.com/docs/api) | [Wordnik](http://developer.wordnik.com/docs.html) | [osu!](https://osu.ppy.sh/p/api) | [YouTube Data](https://developers.google.com/youtube/v3/) | [SoundCloud](https://developers.soundcloud.com/) > Note: If you do self-host, you will need to go into the file `index.js` and remove the entries for requests to Discord Bots and Carbon. diff --git a/commands/search/soundcloud.js b/commands/search/soundcloud.js new file mode 100644 index 00000000..f26ab11a --- /dev/null +++ b/commands/search/soundcloud.js @@ -0,0 +1,59 @@ +const { Command } = require('discord.js-commando'); +const { RichEmbed } = require('discord.js'); +const request = require('superagent'); + +module.exports = class SoundCloudCommand extends Command { + constructor(client) { + super(client, { + name: 'soundcloud', + aliases: [ + 'cloudsound', + 'scloud', + 'csound' + ], + group: 'search', + memberName: 'soundcloud', + description: 'Searches SoundCloud for a song. (;soundcloud Turtle Dreams)', + examples: [';soundcloud Turtle Dreams'], + args: [{ + key: 'query', + prompt: 'What do you want to search SoundCloud for?', + type: 'string', + parse: text => { + return encodeURIComponent(text); + } + }] + }); + } + + async run(message, args) { + if (message.channel.type !== 'dm') { + if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; + if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!'); + } + const { query } = args; + try { + const { body } = await request + .get(`https://api.soundcloud.com/tracks?q=${query}&client_id=${process.env.SOUNDCLOUD_KEY}`); + const data = body[0]; + const embed = new RichEmbed() + .setColor(0xF15A22) + .setAuthor('SoundCloud', 'http://icons.iconarchive.com/icons/danleech/simple/1024/soundcloud-icon.png') + .setURL(data.permalink_url) + .setThumbnail(data.artwork_url) + .addField('**Artist:**', + data.user.username) + .addField('**Download Count:**', + data.download_count, true) + .addField('**Comment Count**', + data.comment_count, true) + .addField('**Playback Count:**', + data.playback_count, true) + .addField('**Favorited Count:**', + data.favoritings_count, true); + return message.embed(embed); + } catch (err) { + return message.say(':x: Error! No Results Found!'); + } + } +}; diff --git a/commands/util/info.js b/commands/util/info.js index 9d001032..3d05b217 100644 --- a/commands/util/info.js +++ b/commands/util/info.js @@ -33,7 +33,7 @@ module.exports = class InfoCommand extends Command { .addField('Shards', `${this.client.options.shardCount} (${this.client.shard.id})`, true) .addField('Commands', - '108', true) + '109', true) .addField('Owner', 'dragonfire535#8081', true) .addField('Source Code', @@ -49,7 +49,7 @@ module.exports = class InfoCommand extends Command { .addField('Modules', '[commando](https://github.com/Gawdl3y/discord.js-commando), [zalgoize](https://github.com/clux/zalgolize), [superagent](https://github.com/visionmedia/superagent), [mathjs](http://mathjs.org/), [moment](http://momentjs.com), [moment-duration-format](https://github.com/jsmreese/moment-duration-format), [jimp](https://github.com/oliver-moran/jimp), [cheerio](https://cheerio.js.org/)') .addField('APIs', - '[Wattpad](https://developer.wattpad.com/docs/api), [Wordnik](http://developer.wordnik.com/docs.html), [osu!](https://osu.ppy.sh/p/api), [memegen.link](https://memegen.link/), [Yugioh Prices](http://docs.yugiohprices.apiary.io/#), [YouTube Data](https://developers.google.com/youtube/v3/), [Discord Bots](https://bots.discord.pw/api), [Today in History](http://history.muffinlabs.com/#api), [jService](http://jservice.io/), [Urban Dictionary](https://github.com/zdict/zdict/wiki/Urban-dictionary-API-documentation), [OMDB](http://www.omdbapi.com/), [Yahoo Weather](https://developer.yahoo.com/weather/), [Wikipedia](https://en.wikipedia.org/w/api.php), [Google Static Maps](https://developers.google.com/maps/documentation/static-maps/), [Strawpoll](https://github.com/strawpoll/strawpoll/wiki/API), [rrrather](http://www.rrrather.com/botapi)'); + '[Wattpad](https://developer.wattpad.com/docs/api), [Wordnik](http://developer.wordnik.com/docs.html), [osu!](https://osu.ppy.sh/p/api), [memegen.link](https://memegen.link/), [Yugioh Prices](http://docs.yugiohprices.apiary.io/#), [YouTube Data](https://developers.google.com/youtube/v3/), [Discord Bots](https://bots.discord.pw/api), [Today in History](http://history.muffinlabs.com/#api), [jService](http://jservice.io/), [Urban Dictionary](https://github.com/zdict/zdict/wiki/Urban-dictionary-API-documentation), [OMDB](http://www.omdbapi.com/), [Yahoo Weather](https://developer.yahoo.com/weather/), [Wikipedia](https://en.wikipedia.org/w/api.php), [Google Static Maps](https://developers.google.com/maps/documentation/static-maps/), [Strawpoll](https://github.com/strawpoll/strawpoll/wiki/API), [rrrather](http://www.rrrather.com/botapi), [SoundCloud](https://developers.soundcloud.com/)'); return message.embed(embed); } }; diff --git a/html/carbondesc.html b/html/carbondesc.html index 7c33dc1f..1a137e64 100644 --- a/html/carbondesc.html +++ b/html/carbondesc.html @@ -46,6 +46,7 @@
  • Google Static Maps
  • Strawpoll
  • rrrather
  • +
  • SoundCloud
  • Information

    Information

    diff --git a/package.json b/package.json index ae4a7b5b..397ad223 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "30.1.0", + "version": "30.2.0", "description": "A Discord Bot", "main": "shardingmanager.js", "scripts": {