Update feed addition to be simpler

This commit is contained in:
benji7425 2017-08-22 23:02:16 +01:00
parent fbab7730b8
commit 1539926671
3 changed files with 17 additions and 20 deletions

View File

@ -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 <url> <channelName> <roleName>
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

View File

@ -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 }) {

View File

@ -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"
}
}
}