From 1539926671b143300a69f871e7c29fd4f31cd33a Mon Sep 17 00:00:00 2001 From: benji7425 Date: Tue, 22 Aug 2017 23:02:16 +0100 Subject: [PATCH] Update feed addition to be simpler --- app/index.js | 21 +++++++++------------ app/models/feed-data.js | 6 +++--- package.json | 10 +++++----- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/app/index.js b/app/index.js index e8f9d7e..e20e4ea 100644 --- a/app/index.js +++ b/app/index.js @@ -2,8 +2,9 @@ const FileSystem = require("fs"); //external lib imports -const JsonFile = require("jsonfile"); -const Url = require("url"); +const JsonFile = require("jsonfile"); //for saving to/from JSON +const Url = require("url"); //for url parsing +const GetUrls = require("get-urls"); //for extracting urls from messages //my imports const DiscordUtil = require("discordjs-util"); @@ -64,22 +65,18 @@ const HandleMessage = { function addFeed(client, guildsData, message) { const parameters = message.content.split(" "); //expect !addfeed + const feedUrl = [...GetUrls(message.content)][0]; const channel = message.mentions.channels.first(); - if(!channel) - return message.reply("Please tag a channel with #channel-name"); - const feedUrl = parameters[2], channelName = channel.name, roleName = parameters[4]; + if (!feedUrl || !channel) + return message.reply("Please provide both a channel and an RSS feed URL. You can optionally @mention a role also."); - if (!Url.parse(feedUrl).host) - return message.reply("Please supply a valid url"); - - if (!feedUrl || !channelName) - return message.reply("Please supply all the needed fields in this format:\n add-feed url channel-name role-name"); + const role = message.mentions.roles.first(); const feedData = new FeedData({ url: feedUrl, - channelName: channelName, - roleName: roleName + channelName: channel.name, + roleName: role.name }); //ask the user if they're happy with the details they set up, save if yes, don't if no diff --git a/app/models/feed-data.js b/app/models/feed-data.js index 3e3e954..7ff2e80 100644 --- a/app/models/feed-data.js +++ b/app/models/feed-data.js @@ -2,9 +2,9 @@ const DiscordUtil = require("discordjs-util"); //external lib imports -const Dns = require("dns"); -const Url = require("url"); -const FeedRead = require("feed-read"); +const Dns = require("dns"); //for host resolution checking +const Url = require("url"); //for url parsing +const FeedRead = require("feed-read"); //for extracing new links from RSS feeds module.exports = class FeedData { constructor({ url, channelName, roleName, cachedLinks }) { diff --git a/package.json b/package.json index b918016..0f2b9b7 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "description": "", "main": "app/index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "node wrapper.js" + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node wrapper.js" }, "repository": { "type": "git", @@ -22,7 +22,7 @@ "discordjs-util": "git+https://github.com/benji7425/discordjs-util.git", "dns": "0.2.2", "feed-read": "0.0.1", - "jsonfile": "3.0.1", - "urijs": "1.18.10" + "get-urls": "7.0.0", + "jsonfile": "3.0.1" } -} \ No newline at end of file +}