diff --git a/commands/category.js b/commands/category.js new file mode 100644 index 0000000..a0d7eec --- /dev/null +++ b/commands/category.js @@ -0,0 +1,11 @@ +var libFlayer = require("../libFlayer.js"); + +module.exports = { + name: 'categories', + description: 'Categories', + async execute(message) { + message.reply( + `Categories: [General, Entertainment, Sports, Tech]` + ); + } +}; \ No newline at end of file diff --git a/commands/help.js b/commands/help.js index 536ad05..de85026 100644 --- a/commands/help.js +++ b/commands/help.js @@ -7,12 +7,14 @@ module.exports = { message.reply( `!help - Lists the available commands **!key** - Testing remote Airtable: *!key url* + **!categories** - Displays Categories: *!categories* **!search** - Searches the RSS Sources: *!search google* **!get** - Retrieves Search By Index: *!get 25* **!add** - Add a new RSS Source Feed dynamically: *!add http://www.engadget.com/rss.xml* **!update** - Updates all current RSS Feeds: *!update* **!quote** - Selects a random quote: *!quote* **!random** - Selects a random article: *!random* + **!random category** - Selects a random article by category: *!random sports* ` ); } diff --git a/commands/random.js b/commands/random.js index d9e8256..fd99b20 100644 --- a/commands/random.js +++ b/commands/random.js @@ -4,11 +4,20 @@ var libFlayer = require("../libFlayer.js"); module.exports = { name: 'random', description: 'Random', - execute(message) { + execute(message, args) { + let category = ""; + let catName = "All"; + if (args.length == 1) { + category = args[0]; + catName = category; + } + message.reply( - `Selecting a random article...` + `Random article - loading... + Category: ${catName} + ` ); - var feedArray = libFlayer.getFeeds(); + var feedArray = libFlayer.getFeeds(category); var i = Math.floor(Math.random() * (feedArray.length - 0) + 0 ); message.reply(`Retrieving: [Link](${feedArray[i].link})`); diff --git a/feeds.json b/feeds.json index a86988d..721d503 100644 --- a/feeds.json +++ b/feeds.json @@ -1,11 +1,11 @@ [{ "title": "CNN Top Stories", "link": "http://rss.cnn.com/rss/cnn_topstories.rss", - "category": "news" + "category": "general" }, { "title": "Reddit Front Page", "link": "http://www.reddit.com/.rss", - "category": "news" + "category": "general" }, { "title": "Arstechnica", "link": "http://feeds.arstechnica.com/arstechnica/index", diff --git a/libFlayer.js b/libFlayer.js index 39bb33e..97c18e8 100644 --- a/libFlayer.js +++ b/libFlayer.js @@ -36,7 +36,8 @@ exports.loadFeeds = function() { var linkData = { title: `${unescape(item.title)}`, - link: `${unescape(item.link)}` + link: `${unescape(item.link)}`, + category: `${unescape(item.category)}` } linkFlayerMap.push(linkData); }); @@ -58,8 +59,18 @@ exports.writeFeed = function (feeds) { console.log("saving feeds.json"); }; -exports.getFeeds = function () { - return linkFlayerMap; +exports.getFeeds = function (feedType) { + if (feedType == null || feedType == undefined || feedType == "") { + return linkFlayerMap; + } else { + var linkFlayerFilteredMap = []; + linkFlayerMap.forEach(linkFlay => { + if (linkFlay.category.toLowerCase().indexOf(feedType.toLowerCase()) > -1) { + linkFlayerFilteredMap.push(linkFlay); + } + }); + return linkFlayerFilteredMap; + } } exports.getSources = function () {