diff --git a/lib/services/dgg-rolling-chat-cache.js b/lib/services/dgg-rolling-chat-cache.js index 86ceaff..139d8af 100644 --- a/lib/services/dgg-rolling-chat-cache.js +++ b/lib/services/dgg-rolling-chat-cache.js @@ -86,7 +86,10 @@ class ChatCache { return; } this.messageMatching.getLinks(message).forEach((link) => { - this.logger.info({ user, url: link.hostname + link.pathname, message }, 'Cached viewer url'); + this.logger.info( + { user, url: link.hostname + link.pathname, msg: message }, + 'Cached viewer url', + ); if (!_.has(this.viewerUrlMap, user)) this.viewerUrlMap[user] = []; this.viewerUrlMap[user].push({ url: link.hostname + link.pathname, diff --git a/lib/services/message-matching.js b/lib/services/message-matching.js index eb0eaf7..3c011ec 100644 --- a/lib/services/message-matching.js +++ b/lib/services/message-matching.js @@ -5,7 +5,18 @@ module.exports = { return linkRegex.test(message); }, getLinks(message) { - return Array.from(message.matchAll(new RegExp(linkRegex, 'g')), (k) => new URL(k[0])); + return Array.from( + message.matchAll(new RegExp(linkRegex, 'g')), + (k) => (k[0].startsWith('http') ? k[0] : `http://${k[0]}`), // add protocol to link + ) + .map((link) => { + try { + return new URL(link); // crash protection + } catch (e) { + return null; + } + }) + .filter((link) => link); // remove null }, mentionsUser(message, user) { if (!user) return false;