Merge pull request #286 from Yamboy1/master

Fix accidental mention parsing
This commit is contained in:
Ralph 2019-12-26 23:10:22 -05:00 committed by GitHub
commit 960edb56c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,11 +12,15 @@ 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})>(.+)/s;
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);