Advertisement
Nickster258

Untitled

Dec 6th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function triggerLinkEvent(user, message) {
  2.     var messageUrl = message.match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/);
  3.     if (messageUrl !== null) {
  4.         var domain = "";
  5.         var title = "";
  6.         var details = fetch(messageUrl[0])
  7.             .then(res => {
  8.                 if (!res.ok) {
  9.                     throw InvalidResponseCode(res.statusText);
  10.                 }
  11.                 domain = url.parse(res.url).hostname;
  12.                 return res;
  13.             })
  14.             .then(res => res.text())
  15.             .then(body => {
  16.                 const $ = cheerio.load(body);
  17.                 title = $('title').html();
  18.                 sendTo("irc", ircChannel, domain + " | " + entities.decode($('title').html()));
  19.             })
  20.             .catch();
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement