Update feed addition to be simpler
This commit is contained in:
parent
fbab7730b8
commit
1539926671
21
app/index.js
21
app/index.js
|
@ -2,8 +2,9 @@
|
||||||
const FileSystem = require("fs");
|
const FileSystem = require("fs");
|
||||||
|
|
||||||
//external lib imports
|
//external lib imports
|
||||||
const JsonFile = require("jsonfile");
|
const JsonFile = require("jsonfile"); //for saving to/from JSON
|
||||||
const Url = require("url");
|
const Url = require("url"); //for url parsing
|
||||||
|
const GetUrls = require("get-urls"); //for extracting urls from messages
|
||||||
|
|
||||||
//my imports
|
//my imports
|
||||||
const DiscordUtil = require("discordjs-util");
|
const DiscordUtil = require("discordjs-util");
|
||||||
|
@ -64,22 +65,18 @@ const HandleMessage = {
|
||||||
function addFeed(client, guildsData, message) {
|
function addFeed(client, guildsData, message) {
|
||||||
const parameters = message.content.split(" "); //expect !addfeed <url> <channelName> <roleName>
|
const parameters = message.content.split(" "); //expect !addfeed <url> <channelName> <roleName>
|
||||||
|
|
||||||
|
const feedUrl = [...GetUrls(message.content)][0];
|
||||||
const channel = message.mentions.channels.first();
|
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)
|
const role = message.mentions.roles.first();
|
||||||
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 feedData = new FeedData({
|
const feedData = new FeedData({
|
||||||
url: feedUrl,
|
url: feedUrl,
|
||||||
channelName: channelName,
|
channelName: channel.name,
|
||||||
roleName: roleName
|
roleName: role.name
|
||||||
});
|
});
|
||||||
|
|
||||||
//ask the user if they're happy with the details they set up, save if yes, don't if no
|
//ask the user if they're happy with the details they set up, save if yes, don't if no
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
const DiscordUtil = require("discordjs-util");
|
const DiscordUtil = require("discordjs-util");
|
||||||
|
|
||||||
//external lib imports
|
//external lib imports
|
||||||
const Dns = require("dns");
|
const Dns = require("dns"); //for host resolution checking
|
||||||
const Url = require("url");
|
const Url = require("url"); //for url parsing
|
||||||
const FeedRead = require("feed-read");
|
const FeedRead = require("feed-read"); //for extracing new links from RSS feeds
|
||||||
|
|
||||||
module.exports = class FeedData {
|
module.exports = class FeedData {
|
||||||
constructor({ url, channelName, roleName, cachedLinks }) {
|
constructor({ url, channelName, roleName, cachedLinks }) {
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
"discordjs-util": "git+https://github.com/benji7425/discordjs-util.git",
|
"discordjs-util": "git+https://github.com/benji7425/discordjs-util.git",
|
||||||
"dns": "0.2.2",
|
"dns": "0.2.2",
|
||||||
"feed-read": "0.0.1",
|
"feed-read": "0.0.1",
|
||||||
"jsonfile": "3.0.1",
|
"get-urls": "7.0.0",
|
||||||
"urijs": "1.18.10"
|
"jsonfile": "3.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue