Fixed a problem with the lbrylinker not working on - chars.

This commit is contained in:
filipnyquist 2018-07-17 11:40:10 +02:00
parent a3de66c2ac
commit ece3da11f8
5 changed files with 285 additions and 277 deletions

View file

@ -13,9 +13,9 @@ const supportbot = require('./modules/supportbot.js');
let aliases; let aliases;
try { try {
aliases = require("./alias.json"); aliases = require('./alias.json');
} catch (e) { } catch (e) {
console.log("No aliases defined") console.log('No aliases defined');
//No aliases defined //No aliases defined
aliases = { aliases = {
test: { test: {
@ -44,9 +44,7 @@ bot.on('ready', function() {
console.log('Logged in! Serving in ' + bot.guilds.array().length + ' servers'); console.log('Logged in! Serving in ' + bot.guilds.array().length + ' servers');
require('./plugins.js').init(); require('./plugins.js').init();
console.log('type ' + config.prefix + 'help in Discord for a commands list.'); console.log('type ' + config.prefix + 'help in Discord for a commands list.');
bot.user bot.user.setActivity(config.prefix + 'help', { type: 'LISTENING' }).catch(console.error);
.setActivity(config.prefix + 'help', { type: 'LISTENING' })
.catch(console.error);
//initialize the claimbot (content bot) //initialize the claimbot (content bot)
claimbot.init(bot); claimbot.init(bot);
@ -76,16 +74,15 @@ function checkMessageForCommand(msg, isEdit) {
if (msg.author.id != bot.user.id && msg.content.startsWith(config.prefix)) { if (msg.author.id != bot.user.id && msg.content.startsWith(config.prefix)) {
//check if user is Online //check if user is Online
if (!msg.author.presence.status || msg.author.presence.status == 'offline' || msg.author.presence.status == 'invisible') { if (!msg.author.presence.status || msg.author.presence.status == 'offline' || msg.author.presence.status == 'invisible') {
msg.author.send('Please set your Discord Presence to Online to talk to the bot!') msg.author.send('Please set your Discord Presence to Online to talk to the bot!').catch(function(error) {
.catch(function(error) { msg.channel
msg.channel.send(msg.author + .send(
msg.author +
', Please enable Direct Messages from server members to communicate fully with our bot, ' + ', Please enable Direct Messages from server members to communicate fully with our bot, ' +
'it is located in the user setting area under Privacy & Safety tab, ' + 'it is located in the user setting area under Privacy & Safety tab, ' +
'select the option allow direct messages from server members' 'select the option allow direct messages from server members'
).then(msg.channel.send(
'Please set your Discord Presence to Online to talk to the Bot!'
) )
); .then(msg.channel.send('Please set your Discord Presence to Online to talk to the Bot!'));
return; return;
}); });
} }

View file

@ -1,88 +1,44 @@
let inPrivate = require('../helpers.js').inPrivate; let inPrivate = require('../helpers.js').inPrivate;
let responseDebug = false; let { RichEmbed } = require('discord.js');
exports.custom = [ exports.custom = [
'lbrylink' //change this to your function name 'lbrylink' //change this to your function name
]; ];
exports.lbrylink = function(bot, msg, suffix) { exports.lbrylink = async function(bot, msg, suffix) {
bot.on('message', msg => { bot.on('message', msg => {
if (inPrivate(msg)) { if (inPrivate(msg)) {
return; return;
} }
if (msg.content.includes('lbry://')) { if (msg.content.includes('lbry://')) {
//Extract URL from Message try {
let newURL = msg.content // Extract the URL(s).
.replace('lbry://', 'https://open.lbry.io/') const urls = msg.content
.replace(new RegExp("(lbry:\\/\\/)", "g"), "https://open.lbry.io/")
.match(/\bhttps?:\/\/\S+/gi) .match(/\bhttps?:\/\/\S+/gi)
.toString(); .filter(url => url !== "https://open.lbry.io/");
if (responseDebug) { const cleanURLs = [];
console.log('___________________________'); for (const i in urls) {
console.log('newURL = ' + newURL);
}
//Check if just lbry:// was supplied
if (newURL == 'https://open.lbry.io/') {
return;
}
// Check if Username Was Supplied // Check if Username Was Supplied
if (newURL.includes('>')) { const user = urls[i].match("<@.*>");
//Get rid of ID from message if (user) {
let parseID = newURL.split('>').pop(); const { username } = msg.mentions.users.get(user[0].slice(2, -1));
let newURL = 'https://open.lbry.io' + parseID; urls[i] = urls[i].replace(user[0], `@${username}`);
if (responseDebug) {
console.log('Username Provided!');
console.log('parseID = ' + parseID);
console.log('newURL = ' + newURL);
} }
// Push clean URLs to the array.
//check if just Username Was Supplied cleanURLs.push(urls[i]);
if (!newURL.substr(20).includes('/')) {
return;
} }
if (cleanURLs.length < 1) return;
//check if more than username was supplied const linkEmbed = new RichEmbed();
//Also check obscurity in username like ``@MSFTserver` vs `@MSFTserverPics` linkEmbed
if (parseID.includes('/')) { .setAuthor("LBRY Linker")
//parse out extra params before `/` like `<@123456789>Pics` .setDescription("I see you tried to post a LBRY URL, here's a friendly hyperlink to share and for others to access your content with a single click:")
let parseID = parseID.split('/').pop(); .setColor(7976557);
let newURL = 'https://open.lbry.io/' + parseID; cleanURLs.forEach(url => linkEmbed.addField("Open with LBRY:", url, true));
if (responseDebug) { return msg.embed(linkEmbed);
console.log('Username no / check'); } catch (e) {
console.log('parseID = ' + parseID); console.log(e);
console.log('newURL = ' + newURL); msg.channel.send("Something went wrong when trying to run the lbrylinker, contact a moderator.");
} }
//checks if username had if after it or just blank to be safe
if (newURL == 'https://open.lbry.io/' || parseID.startsWith('#')) {
return;
}
}
//one last saftey check
if (newURL == 'https://open.lbry.io') {
return;
}
//If no UserName Found proceed
} else {
if (newURL == 'https://open.lbry.io/') {
return;
}
if (responseDebug) {
console.log('___________________________');
console.log('newURL = ' + newURL);
}
}
const embed = {
description: "I see you tried to post a LBRY URL, here's a friendly hyperlink to share and for others to access your content with a single click: \n" + newURL.replace(/[^0-9a-z#./:]/gi,''),
color: 7976557,
author: {
name: 'LBRY Linker',
icon_url: 'https://i.imgur.com/yWf5USu.png'
}
};
msg.channel.send({ embed });
} }
}); });
}; };

View file

@ -4,7 +4,8 @@ let inPrivate = require('../helpers.js').inPrivate;
exports.custom = ['onUserJoin']; exports.custom = ['onUserJoin'];
exports.onUserJoin = function(bot) { exports.onUserJoin = function(bot) {
bot.on('guildMemberAdd', member => { bot.on('guildMemberAdd', member => {
member.send({ member
.send({
embed: { embed: {
title: '*Click here for more info about LBRY!*', title: '*Click here for more info about LBRY!*',
description: description:
@ -19,12 +20,17 @@ exports.onUserJoin = function(bot) {
icon_url: 'https://i.imgur.com/yWf5USu.png' icon_url: 'https://i.imgur.com/yWf5USu.png'
} }
} }
}).catch(function(error) { })
bot.channels.get('369896313082478594').send(member + .catch(function(error) {
bot.channels
.get('369896313082478594')
.send(
member +
', Please enable Direct Messages from server members to communicate fully with our bot, it is located in the user setting area under Privacy & Safety tab, select the option allow direct messages from server members\nSince the bot could not send you our Welcome message please check the posts in <#431211007050776577> and see the Wunderbot and tipbot commands by typing `!help` in <#369896313082478594>' ', Please enable Direct Messages from server members to communicate fully with our bot, it is located in the user setting area under Privacy & Safety tab, select the option allow direct messages from server members\nSince the bot could not send you our Welcome message please check the posts in <#431211007050776577> and see the Wunderbot and tipbot commands by typing `!help` in <#369896313082478594>'
) );
}); });
member.send({ member
.send({
embed: { embed: {
description: description:
'1. Be respectful to other community members. Harrasment and vulgarity will not be tolerated \n' + '1. Be respectful to other community members. Harrasment and vulgarity will not be tolerated \n' +
@ -40,8 +46,12 @@ exports.onUserJoin = function(bot) {
icon_url: 'https://i.imgur.com/yWf5USu.png' icon_url: 'https://i.imgur.com/yWf5USu.png'
} }
} }
}).catch(function(error) {console.log('could not send dm')}); })
member.send({ .catch(function(error) {
console.log('could not send dm');
});
member
.send({
embed: { embed: {
description: description:
'1. Type !tip help in the #bot-sandbox channel to interact with our Tipbot which can be used to send and receive LBRY Credits (LBC). **Enable 2FA in your Discord account settings!** \n' + '1. Type !tip help in the #bot-sandbox channel to interact with our Tipbot which can be used to send and receive LBRY Credits (LBC). **Enable 2FA in your Discord account settings!** \n' +
@ -57,8 +67,12 @@ exports.onUserJoin = function(bot) {
icon_url: 'https://i.imgur.com/yWf5USu.png' icon_url: 'https://i.imgur.com/yWf5USu.png'
} }
} }
}).catch(function(error) {console.log('could not send dm')}); })
member.send({ .catch(function(error) {
console.log('could not send dm');
});
member
.send({
embed: { embed: {
title: '*Click here for more info about LBRY!*', title: '*Click here for more info about LBRY!*',
description: description:
@ -71,8 +85,12 @@ exports.onUserJoin = function(bot) {
icon_url: 'https://i.imgur.com/yWf5USu.png' icon_url: 'https://i.imgur.com/yWf5USu.png'
} }
} }
}).catch(function(error) {console.log('could not send dm')}); })
member.send({ .catch(function(error) {
console.log('could not send dm');
});
member
.send({
embed: { embed: {
title: '*Click here to see all LBRY Frequently Asked Questions (FAQ)!*', title: '*Click here to see all LBRY Frequently Asked Questions (FAQ)!*',
description: description:
@ -85,8 +103,12 @@ exports.onUserJoin = function(bot) {
icon_url: 'https://spee.ch/8/Id5Qoc3w.png' icon_url: 'https://spee.ch/8/Id5Qoc3w.png'
} }
} }
}).catch(function(error) {console.log('could not send dm')}); })
member.send({ .catch(function(error) {
console.log('could not send dm');
});
member
.send({
embed: { embed: {
title: '*Have you checked out spee.ch yet?!*', title: '*Have you checked out spee.ch yet?!*',
description: description:
@ -99,7 +121,10 @@ exports.onUserJoin = function(bot) {
icon_url: 'http://www.pd4pic.com/images/flag-green-blue-purple-indigo-bars-background.png' icon_url: 'http://www.pd4pic.com/images/flag-green-blue-purple-indigo-bars-background.png'
} }
} }
}).catch(function(error) {console.log('could not send dm')}); })
.catch(function(error) {
console.log('could not send dm');
});
}); });
}; };
@ -123,7 +148,9 @@ exports.welcome = {
msg.channel.send('You Dont Have Permission To Use This Command!'); msg.channel.send('You Dont Have Permission To Use This Command!');
return; return;
} }
msg.mentions.members.first().send({ msg.mentions.members
.first()
.send({
embed: { embed: {
title: '*Click here for more info about LBRY!*', title: '*Click here for more info about LBRY!*',
description: description:
@ -138,12 +165,16 @@ exports.welcome = {
icon_url: 'https://i.imgur.com/yWf5USu.png' icon_url: 'https://i.imgur.com/yWf5USu.png'
} }
} }
}).catch(function(error) { })
msg.channel.send(msg.mentions.members.first() + .catch(function(error) {
msg.channel.send(
msg.mentions.members.first() +
', Please enable Direct Messages from server members to communicate fully with our bot, it is located in the user setting area under Privacy & Safety tab, select the option allow direct messages from server members' ', Please enable Direct Messages from server members to communicate fully with our bot, it is located in the user setting area under Privacy & Safety tab, select the option allow direct messages from server members'
) );
}); });
msg.mentions.members.first().send({ msg.mentions.members
.first()
.send({
embed: { embed: {
description: description:
'1. Be respectful to other community members. Harrasment and vulgarity will not be tolerated \n' + '1. Be respectful to other community members. Harrasment and vulgarity will not be tolerated \n' +
@ -159,8 +190,13 @@ exports.welcome = {
icon_url: 'https://i.imgur.com/yWf5USu.png' icon_url: 'https://i.imgur.com/yWf5USu.png'
} }
} }
}).catch(function(error) {console.log('could not send dm')}); })
msg.mentions.members.first().send({ .catch(function(error) {
console.log('could not send dm');
});
msg.mentions.members
.first()
.send({
embed: { embed: {
description: description:
'1. Type !tip help in the #bot-sandbox channel to interact with our Tipbot which can be used to send and receive LBRY Credits (LBC). **Enable 2FA in your Discord account settings!** \n' + '1. Type !tip help in the #bot-sandbox channel to interact with our Tipbot which can be used to send and receive LBRY Credits (LBC). **Enable 2FA in your Discord account settings!** \n' +
@ -176,8 +212,13 @@ exports.welcome = {
icon_url: 'https://i.imgur.com/yWf5USu.png' icon_url: 'https://i.imgur.com/yWf5USu.png'
} }
} }
}).catch(function(error) {console.log('could not send dm')}); })
msg.mentions.members.first().send({ .catch(function(error) {
console.log('could not send dm');
});
msg.mentions.members
.first()
.send({
embed: { embed: {
title: '*Click here for more info about LBRY!*', title: '*Click here for more info about LBRY!*',
description: description:
@ -190,8 +231,13 @@ exports.welcome = {
icon_url: 'https://i.imgur.com/yWf5USu.png' icon_url: 'https://i.imgur.com/yWf5USu.png'
} }
} }
}).catch(function(error) {console.log('could not send dm')}); })
msg.mentions.members.first().send({ .catch(function(error) {
console.log('could not send dm');
});
msg.mentions.members
.first()
.send({
embed: { embed: {
title: '*Click here to see all LBRY Frequently Asked Questions (FAQ)!*', title: '*Click here to see all LBRY Frequently Asked Questions (FAQ)!*',
description: description:
@ -204,8 +250,12 @@ exports.welcome = {
icon_url: 'https://spee.ch/8/Id5Qoc3w.png' icon_url: 'https://spee.ch/8/Id5Qoc3w.png'
} }
} }
}).catch(console.error).then(console.log('could not send dm')); })
msg.mentions.members.first().send({ .catch(console.error)
.then(console.log('could not send dm'));
msg.mentions.members
.first()
.send({
embed: { embed: {
title: '*Have you checked out spee.ch yet?!*', title: '*Have you checked out spee.ch yet?!*',
description: description:
@ -218,6 +268,9 @@ exports.welcome = {
icon_url: 'http://www.pd4pic.com/images/flag-green-blue-purple-indigo-bars-background.png' icon_url: 'http://www.pd4pic.com/images/flag-green-blue-purple-indigo-bars-background.png'
} }
} }
}).catch(function(error) {console.log('could not send dm')}); })
.catch(function(error) {
console.log('could not send dm');
});
} }
}; };

View file

@ -183,7 +183,8 @@
"bundle": { "bundle": {
"url": "", "url": "",
"title": "", "title": "",
"description": ":warning: Hey, glad to see you love **LBRY** so much, but for the safety of our users we ask that you avoid using **Discord names** that include the word **LBRY**, names of **LBRY staff**, names of other **LBRY members** on the this server or any name that could be considered **deceptive**. This is to prevent impersonation and scams.", "description":
":warning: Hey, glad to see you love **LBRY** so much, but for the safety of our users we ask that you avoid using **Discord names** that include the word **LBRY**, names of **LBRY staff**, names of other **LBRY members** on the this server or any name that could be considered **deceptive**. This is to prevent impersonation and scams.",
"color": 7976557, "color": 7976557,
"author": { "author": {
"name": "Discord Username", "name": "Discord Username",
@ -800,7 +801,8 @@
"bundle": { "bundle": {
"url": "", "url": "",
"title": "", "title": "",
"description": "Type `!tip help` or `!tips` to interact with our Tipbot which can be used to send and receive LBRY Credits (LBC). <#369896313082478594> should be used to talk to bots in order to avoid spamming other channels. \nRead our [Tipbot FAQ](https://lbry.io/faq/tipbot-discord) on how use the LBRY Discord Tipbot", "description":
"Type `!tip help` or `!tips` to interact with our Tipbot which can be used to send and receive LBRY Credits (LBC). <#369896313082478594> should be used to talk to bots in order to avoid spamming other channels. \nRead our [Tipbot FAQ](https://lbry.io/faq/tipbot-discord) on how use the LBRY Discord Tipbot",
"color": 7976557, "color": 7976557,
"author": { "author": {
"name": "Tipbot Help Message", "name": "Tipbot Help Message",