This commit is contained in:
MSFTserver 2017-11-15 14:16:30 -08:00
parent 6a7b68afc3
commit cb87a9495b

View file

@ -1,27 +1,43 @@
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 = function(bot, msg, suffix) {
bot.on('message', msg => { bot.on('message', msg => {
var link = msg.content.indexOf("lbry://") var link = msg.content.indexOf("lbry://")
if (link != -1) { if (link != -1) {
var text = msg.content.replace("lbry://", "https://open.lbry.io/"); var text = msg.content.replace("lbry://", "https://open.lbry.io/");
var message = GetWordByPos(text, link) var message = GetWordByPos(text, link)
var name = message.replace("https://open.lbry.io/", ""); if (text.search("<") != -1) {
const embed = { var name = "@" + msg.mentions.members.first().user.username
"description": msg.author+", 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"+"[lbry://"+name+"]("+message+")", var trim = message.split("/").pop()
"color": 7976557, var trim2 = trim.substr(2)
"author": { var id = trim2.substr(0, trim2.length - 1)
"name": "LBRY Linker", if (msg.mentions.members.first().id != id) {
"icon_url": "https://i.imgur.com/yWf5USu.png" var message = "https://open.lbry.io/@" + msg.mentions.members.first().user.username + "/" + message.split("/").pop()
} var newname = name + "/" + message.split("/").pop()
}; } else {
msg.channel.send({embed}) var message = "https://open.lbry.io/@" + msg.mentions.members.first().user.username
} var newname = name
}) }
function GetWordByPos(str, pos) { } else {
var newname = message.replace("https://open.lbry.io/", "");
}
const embed = {
"description": msg.author + ", 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" + "[lbry://" + newname + "](" + message + ")",
"color": 7976557,
"author": {
"name": "LBRY Linker",
"icon_url": "https://i.imgur.com/yWf5USu.png"
}
};
msg.channel.send({
embed
})
}
})
function GetWordByPos(str, pos) {
var left = str.substr(0, pos); var left = str.substr(0, pos);
var right = str.substr(pos); var right = str.substr(pos);
@ -29,5 +45,5 @@ function GetWordByPos(str, pos) {
right = right.replace(/ .+$/g, ""); right = right.replace(/ .+$/g, "");
return left + right; return left + right;
} }
} }