Skip to content

Commit

Permalink
Use message parser findLinks in link prefetcher
Browse files Browse the repository at this point in the history
This will fully match link parsing that the client does
  • Loading branch information
xPaw committed Jun 27, 2017
1 parent 8a9e72c commit b62a855
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/plugins/irc-events/link.js
Expand Up @@ -3,6 +3,7 @@
const cheerio = require("cheerio");
const request = require("request");
const Helper = require("../../helper");
const findLinks = require("../../../client/js/libs/handlebars/ircmessageparser/findLinks");
const es = require("event-stream");

process.setMaxListeners(0);
Expand All @@ -12,16 +13,14 @@ module.exports = function(client, chan, msg) {
return;
}

const links = msg.text
.replace(/\x02|\x1D|\x1F|\x16|\x0F|\x03(?:[0-9]{1,2}(?:,[0-9]{1,2})?)?/g, "")
.split(" ")
.filter((w) => /^https?:\/\//.test(w));
const cleanText = msg.text.replace(/\x02|\x1D|\x1F|\x16|\x0F|\x03(?:[0-9]{1,2}(?:,[0-9]{1,2})?)?/g, "");
const links = findLinks(cleanText).filter((w) => /^https?:\/\//.test(w.link));

if (links.length === 0) {
return;
}

const link = escapeHeader(links[0]);
const link = escapeHeader(links[0].link);
fetch(link, function(res) {
if (res === null) {
return;
Expand Down

0 comments on commit b62a855

Please sign in to comment.