diff --git a/.gitignore b/.gitignore index 961e6b0..699ef30 100644 --- a/.gitignore +++ b/.gitignore @@ -54,4 +54,5 @@ jspm_packages # Output of 'npm pack' *.tgz -/botConfig.json \ No newline at end of file +/botConfig.json +/bot-config.json \ No newline at end of file diff --git a/feed-bot.js b/feed-bot.js index ddfe1cd..4b97c88 100644 --- a/feed-bot.js +++ b/feed-bot.js @@ -41,9 +41,13 @@ function checkCache(link) { return cachedLinks.includes(link); } -function convertToYoutubeShareUrl(fullUrl){ +function convertToYoutubeShareUrl(fullUrl) { var shareUrl = fullUrl.replace(youtubeFullUrl, youtubeShareUrl); - shareUrl.splice(0, shareUrl.indexOf("&")); + var ampersandIdx = shareUrl.indexOf("&"); + if (ampersandIdx > -1) + return shareUrl.slice(0, ampersandIdx); + else + return shareUrl; } //check if we can connect to discordapp.com to authenticate the bot @@ -112,6 +116,8 @@ function checkLinkAndPost(err, articles) { //check whether the latest link out the feed exists in our cache if (!checkCache(latestLink)) { + if (Config.youtubeMode && latestLink.includes(youtubeFullUrl)) + latestLink = convertToYoutubeShareUrl(latestLink); Log.info("Attempting to post new link: " + latestLink); //send a messsage containing the new feed link to our discord channel diff --git a/log.js b/log.js index 2e7e103..8a8b115 100644 --- a/log.js +++ b/log.js @@ -1,26 +1,26 @@ var console = require("console"); function log(message) { - if (message) - //attach a formatted date string to the beginning of everything we log - console.log(new Date().toLocaleString() + " " + message); + if (message) + //attach a formatted date string to the beginning of everything we log + console.log(new Date().toLocaleString() + " " + message); } module.exports = { - info: function (message) { - if (message) - this.log("INFO: " + message); - }, - event: function (message, sender) { - //if we received a message, log it - include sender information if it was passed - if (message) { - log("EVENT: " + (sender ? sender + " has sent an event: " : "") + messsage); - } - }, - error: function (message, innerEx) { - if (message) { - //log the message, attach innerEx information if it was passed - log("ERROR: " + message + (innerEx ? ". Inner exception details: " + (innerEx.message || innerEx) : "")); - } - } -} \ No newline at end of file + info: function (message) { + if (message) + log("INFO: " + message); + }, + event: function (message, sender) { + //if we received a message, log it - include sender information if it was passed + if (message) { + log("EVENT: " + (sender ? sender + " has sent an event: " : "") + message); + } + }, + error: function (message, innerEx) { + if (message) { + //log the message, attach innerEx information if it was passed + log("ERROR: " + message + (innerEx ? ". Inner exception details: " + (innerEx.message || innerEx) : "")); + } + } +}; \ No newline at end of file