Added youtube mode toggle with full url -> share url conversion
This commit is contained in:
parent
5a5c9dd9eb
commit
0766a8351b
|
@ -2,5 +2,6 @@
|
|||
"feedUrl": "https://www.youtube.com/feeds/videos.xml?user=EthosLab",
|
||||
"channelID": "241238530376990722",
|
||||
"pollingInterval": 5000,
|
||||
"numLinksToCache": 10
|
||||
"numLinksToCache": 10,
|
||||
"youtubeMode": true
|
||||
}
|
17
feed-bot.js
17
feed-bot.js
|
@ -17,6 +17,9 @@ var latestFeedLink = "";
|
|||
var linkRegExp = new RegExp(["http", "https", "www"].join("|"));
|
||||
var cachedLinks = [];
|
||||
|
||||
var youtubeShareUrl = "http://youtu.be/";
|
||||
var youtubeFullUrl = "http://www.youtube.com/watch?v=";
|
||||
|
||||
//caches a link so we can check again later
|
||||
function cacheLink(link) {
|
||||
//cheaty way to get around http and https not matching
|
||||
|
@ -31,6 +34,18 @@ function cacheLink(link) {
|
|||
cachedLinks.shift();
|
||||
}
|
||||
|
||||
function checkCache(link) {
|
||||
if (Config.youtubeMode && link.includes(youtubeFullUrl)) {
|
||||
return cachedLinks.includes(convertToYoutubeShareUrl(link));
|
||||
}
|
||||
return cachedLinks.includes(link);
|
||||
}
|
||||
|
||||
function convertToYoutubeShareUrl(fullUrl){
|
||||
var shareUrl = fullUrl.replace(youtubeFullUrl, youtubeShareUrl);
|
||||
shareUrl.splice(0, shareUrl.indexOf("&"));
|
||||
}
|
||||
|
||||
//check if we can connect to discordapp.com to authenticate the bot
|
||||
Dns.resolve("discordapp.com", function (err) {
|
||||
if (err) Log.error("CONNECTION ERROR: Unable to locate discordapp.com to authenticate the bot (you are probably not connected to the internet).", err);
|
||||
|
@ -96,7 +111,7 @@ function checkLinkAndPost(err, articles) {
|
|||
var latestLink = articles[0].link.replace("https", "http");
|
||||
|
||||
//check whether the latest link out the feed exists in our cache
|
||||
if (!cachedLinks.includes(latestLink)) {
|
||||
if (!checkCache(latestLink)) {
|
||||
Log.info("Attempting to post new link: " + latestLink);
|
||||
|
||||
//send a messsage containing the new feed link to our discord channel
|
||||
|
|
Loading…
Reference in New Issue