Add feed validity checking before adding
This commit is contained in:
parent
0d5e3dcd81
commit
3877aa5c59
|
@ -1,5 +1,6 @@
|
||||||
const Core = require("../../discord-bot-core");
|
const Core = require("../../discord-bot-core");
|
||||||
const GetUrls = require("get-urls");
|
const GetUrls = require("get-urls");
|
||||||
|
const FeedRead = require("feed-read");
|
||||||
const FeedData = require("../models/feed-data.js");
|
const FeedData = require("../models/feed-data.js");
|
||||||
const GuildData = require("../models/guild-data.js");
|
const GuildData = require("../models/guild-data.js");
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -29,16 +30,20 @@ function invoke({ message, params, guildData, client }) {
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
//ask the user if they're happy with the details they set up, save if yes, don't if no
|
FeedRead(feedUrl, (err, articles) => {
|
||||||
Core.util.ask(client, message.channel, message.member, "Are you happy with this (yes/no)?\n" + feedData.toString())
|
if (err)
|
||||||
.then(responseMessage => {
|
return reject(`Unable to add the feed due to the following error:\n${err.message}`);
|
||||||
if (responseMessage.content.toLowerCase() === "yes") {
|
|
||||||
guildData.feeds.push(feedData);
|
Core.util.ask(client, message.channel, message.member, "Are you happy with this (yes/no)?\n" + feedData.toString())
|
||||||
guildData.cachePastPostedLinks(message.guild)
|
.then(responseMessage => {
|
||||||
.then(() => resolve("Your new feed has been saved!"));
|
if (responseMessage.content.toLowerCase() === "yes") {
|
||||||
}
|
guildData.feeds.push(feedData);
|
||||||
else
|
guildData.cachePastPostedLinks(message.guild)
|
||||||
reject("Your feed has not been saved, please add it again with the correct details");
|
.then(() => resolve("Your new feed has been saved!"));
|
||||||
});
|
}
|
||||||
|
else
|
||||||
|
reject("Your feed has not been saved, please add it again with the correct details");
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue