mirror of
https://github.com/LBRYFoundation/lbry-wunderbot.git
synced 2025-08-23 09:37:27 +00:00
Reformat bot for latest discord.js Bump Node to v16 Fix embeds across the board Implement intents for new discord API Remove SupportBot module Remove WelcomeBot module Fixed !helpcommands and !price helptext logic Fix LBRYLinker for new embed system Remove ClaimBot completely (Unused) Remove RoleSetter (No longer used) Remove Speech Module (Spee.ch is deprecated)
44 lines
1.6 KiB
JavaScript
44 lines
1.6 KiB
JavaScript
let inPrivate = require('../helpers.js').inPrivate;
|
||
let { MessageEmbed } = require('discord.js');
|
||
exports.custom = [
|
||
'lbrylink' //change this to your function name
|
||
];
|
||
|
||
exports.lbrylink = async function(bot, msg, suffix) {
|
||
bot.on('messageCreate', msg => {
|
||
if (inPrivate(msg)) {
|
||
return;
|
||
}
|
||
|
||
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})>(.*)/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);
|
||
|
||
//clean URLS from any prepended or appended extra chars
|
||
for (let i = 0; i < urls.length; i++) {
|
||
urls[i] = urls[i]
|
||
.replace(/^lbry:\/\//g, 'https://open.lbry.com/')
|
||
.replace(/\W+$/g, '')
|
||
.replace(/#/g, ':');
|
||
}
|
||
const linkEmbed = new MessageEmbed();
|
||
linkEmbed
|
||
.setAuthor('LBRY Linker')
|
||
.setDescription("I see you tried to post a LBRY URL, here's a friendly link to share and for others to access your content with a single click:")
|
||
.setColor(7976557);
|
||
urls.forEach(url => linkEmbed.addField('Open with LBRY or LBRY TV:', url, true));
|
||
return msg.channel.send({ embeds: [linkEmbed] });
|
||
}
|
||
});
|
||
};
|