From 1e201c46f6b6c4380b9adcef7e2128f834303382 Mon Sep 17 00:00:00 2001 From: Yamboy1 Date: Fri, 27 Dec 2019 08:41:41 +1300 Subject: [PATCH 1/2] Remove mention parsing from link --- bot/modules/lbrylink.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bot/modules/lbrylink.js b/bot/modules/lbrylink.js index 7e8a2d6..4ac1bda 100644 --- a/bot/modules/lbrylink.js +++ b/bot/modules/lbrylink.js @@ -12,11 +12,18 @@ exports.lbrylink = async function(bot, msg, suffix) { const urlOccurrences = (msg.content.match(/lbry:\/\//g) || []).length; if (urlOccurrences > 0) { - //convert all mentions to a plain string (because lbry://@Nikooo777 gets parsed as lbry://@<123123123> instead) - let mentions = msg.mentions.users; - mentions.forEach(m => { - msg.content = msg.content.replace(new RegExp(m.toString(), 'g'), `@${m.username}`); - }); + //convert all mentions to a plain string (because lbry://@Nikooo777 gets parsed as lbry://@<123123123> instead) + const mentionRegex = /(.+)<@!?(\d{18})>(.+)/; + let match; + do { + if (match) { + msg.content = + match[1] + + `@${msg.guild.members.get(match[2]).user.username}` + + match[3]; + } + match = msg.content.match(mentionRegex); + } while (match); //compile a list of URLs let urls = msg.content.match(/lbry:\/\/\S+/g); From c81c82506e32b41fff1f2f84940ec7da11469b8d Mon Sep 17 00:00:00 2001 From: Yamboy1 Date: Fri, 27 Dec 2019 10:33:26 +1300 Subject: [PATCH 2/2] Prettier --- bot/modules/lbrylink.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/bot/modules/lbrylink.js b/bot/modules/lbrylink.js index 4ac1bda..5ac1b31 100644 --- a/bot/modules/lbrylink.js +++ b/bot/modules/lbrylink.js @@ -13,14 +13,11 @@ exports.lbrylink = async function(bot, msg, suffix) { const urlOccurrences = (msg.content.match(/lbry:\/\//g) || []).length; if (urlOccurrences > 0) { //convert all mentions to a plain string (because lbry://@Nikooo777 gets parsed as lbry://@<123123123> instead) - const mentionRegex = /(.+)<@!?(\d{18})>(.+)/; + const mentionRegex = /(.+)<@!?(\d{18})>(.+)/s; let match; do { if (match) { - msg.content = - match[1] + - `@${msg.guild.members.get(match[2]).user.username}` + - match[3]; + msg.content = match[1] + `@${msg.guild.members.get(match[2]).user.username}` + match[3]; } match = msg.content.match(mentionRegex); } while (match);