mirror of
https://github.com/LBRYFoundation/lbry-tipbot.git
synced 2025-08-23 16:57:24 +00:00
Merge branch 'master' into multirole
ported over the changes made in master changed vars to let simplified code added missing dependency to package.json
This commit is contained in:
commit
f2c784dc23
4 changed files with 1096 additions and 252 deletions
66
bot/bot.js
66
bot/bot.js
|
@ -4,30 +4,16 @@
|
||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
// Load config!
|
// Load config!
|
||||||
let config = require('config');
|
let config = require('config');
|
||||||
config = config.get('bot');
|
let botConfig = config.get('bot');
|
||||||
|
let commands = {};
|
||||||
|
|
||||||
var aliases;
|
const bot = new Discord.Client();
|
||||||
try {
|
|
||||||
aliases = require('./alias.json');
|
|
||||||
} catch (e) {
|
|
||||||
//No aliases defined
|
|
||||||
aliases = {
|
|
||||||
test: {
|
|
||||||
process: function(bot, msg) {
|
|
||||||
msg.channel.send('test');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
var commands = {};
|
|
||||||
|
|
||||||
var bot = new Discord.Client();
|
|
||||||
|
|
||||||
bot.on('ready', function() {
|
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 ${botConfig.prefix}help in Discord for a commands list.`);
|
||||||
bot.user.setGame(config.prefix + 'tip');
|
bot.user.setActivity(botConfig.prefix + 'tip');
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.on('disconnected', function() {
|
bot.on('disconnected', function() {
|
||||||
|
@ -35,35 +21,29 @@ bot.on('disconnected', function() {
|
||||||
process.exit(1); //exit node.js with an error
|
process.exit(1); //exit node.js with an error
|
||||||
});
|
});
|
||||||
|
|
||||||
function checkMessageForCommand(msg, isEdit) {
|
function checkMessageForCommand(msg) {
|
||||||
//check if message is a command
|
//check if message is a command
|
||||||
if (msg.author.id != bot.user.id && msg.content.startsWith(config.prefix)) {
|
if (msg.author.id !== bot.user.id && msg.content.startsWith(botConfig.prefix)) {
|
||||||
console.log('treating ' + msg.content + ' from ' + msg.author + ' as command');
|
console.log(`treating ${msg.content} from ${msg.author} as command`);
|
||||||
var cmdTxt = msg.content.split(' ')[0].substring(config.prefix.length);
|
let cmdTxt = msg.content.split(' ')[0].substring(botConfig.prefix.length);
|
||||||
var suffix = msg.content.substring(cmdTxt.length + config.prefix.length + 1); //add one for the ! and one for the space
|
let suffix = msg.content.substring(cmdTxt.length + botConfig.prefix.length + 1); //add one for the ! and one for the space
|
||||||
if (msg.isMentioned(bot.user)) {
|
if (msg.isMentioned(bot.user)) {
|
||||||
try {
|
try {
|
||||||
cmdTxt = msg.content.split(' ')[1];
|
cmdTxt = msg.content.split(' ')[1];
|
||||||
suffix = msg.content.substring(bot.user.mention().length + cmdTxt.length + config.prefix.length + 1);
|
suffix = msg.content.substring(bot.user.mention().length + cmdTxt.length + botConfig.prefix.length + 1);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//no command
|
//no command
|
||||||
msg.channel.send('Yes?');
|
return msg.channel.send('Yes?');
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let alias = aliases[cmdTxt];
|
let cmd = commands[cmdTxt];
|
||||||
if (alias) {
|
|
||||||
var cmd = alias;
|
|
||||||
} else {
|
|
||||||
var cmd = commands[cmdTxt];
|
|
||||||
}
|
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
// Add permission check here later on ;)
|
// Add permission check here later on ;)
|
||||||
try {
|
try {
|
||||||
cmd.process(bot, msg, suffix, isEdit);
|
cmd.process(bot, msg, suffix);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
var msgTxt = 'command ' + cmdTxt + ' failed :(';
|
let msgTxt = `command ${cmdTxt} failed :(`;
|
||||||
if (config.debug) {
|
if (botConfig.debug) {
|
||||||
msgTxt += '\n' + e.stack;
|
msgTxt += '\n' + e.stack;
|
||||||
}
|
}
|
||||||
msg.channel.send(msgTxt);
|
msg.channel.send(msgTxt);
|
||||||
|
@ -72,21 +52,17 @@ function checkMessageForCommand(msg, isEdit) {
|
||||||
} else {
|
} else {
|
||||||
//message isn't a command or is from us
|
//message isn't a command or is from us
|
||||||
//drop our own messages to prevent feedback loops
|
//drop our own messages to prevent feedback loops
|
||||||
if (msg.author == bot.user) {
|
if (msg.author === bot.user) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.author != bot.user && msg.isMentioned(bot.user)) {
|
if (msg.author !== bot.user && msg.isMentioned(bot.user)) {
|
||||||
msg.channel.send('yes?'); //using a mention here can lead to looping
|
msg.channel.send('yes?'); //using a mention here can lead to looping
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bot.on('message', msg => checkMessageForCommand(msg, false));
|
bot.on('message', msg => checkMessageForCommand(msg));
|
||||||
/*bot.on("messageUpdate", (oldMessage, newMessage) => {
|
|
||||||
checkMessageForCommand(newMessage, true);
|
|
||||||
});*/
|
|
||||||
|
|
||||||
exports.addCommand = function(commandName, commandObject) {
|
exports.addCommand = function(commandName, commandObject) {
|
||||||
try {
|
try {
|
||||||
|
@ -106,4 +82,4 @@ exports.commandCount = function() {
|
||||||
return Object.keys(commands).length;
|
return Object.keys(commands).length;
|
||||||
};
|
};
|
||||||
|
|
||||||
bot.login(config.token);
|
bot.login(botConfig.token);
|
||||||
|
|
|
@ -1,109 +1,152 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const bitcoin = require('bitcoin');
|
const bitcoin = require('bitcoin');
|
||||||
let config = require('config'),
|
let config = require('config');
|
||||||
spamchannel = config.get('moderation').botspamchannel,
|
let spamchannel = config.get('sandboxchannel');
|
||||||
regex = require('regex');
|
let regex = require('regex');
|
||||||
config = config.get('lbrycrd');
|
let lbrycrdConfig = config.get('lbrycrd');
|
||||||
const lbry = new bitcoin.Client(config);
|
const lbry = new bitcoin.Client(lbrycrdConfig);
|
||||||
|
|
||||||
exports.commands = [
|
exports.commands = ['tip', 'multitip', 'roletip', 'tipcommands'];
|
||||||
"tip",
|
|
||||||
"multitip",
|
|
||||||
"roletip",
|
|
||||||
"tipcommands"
|
|
||||||
]
|
|
||||||
exports.tip = {
|
exports.tip = {
|
||||||
usage: "<subcommand>",
|
usage: '<subcommand>',
|
||||||
description: 'Tip a given user with an amount of LBC or perform wallet specific operations.',
|
description: 'Tip a given user with an amount of LBC or perform wallet specific operations.',
|
||||||
process: async function (bot, msg, suffix) {
|
process: async function(bot, msg, suffix) {
|
||||||
let tipper = msg.author.id.replace('!', ''),
|
let tipper = msg.author.id.replace('!', ''),
|
||||||
words = msg.content.trim().split(' ').filter(function (n) { return n !== ""; }),
|
words = msg.content
|
||||||
|
.trim()
|
||||||
|
.split(' ')
|
||||||
|
.filter(function(n) {
|
||||||
|
return n !== '';
|
||||||
|
}),
|
||||||
subcommand = words.length >= 2 ? words[1] : 'help',
|
subcommand = words.length >= 2 ? words[1] : 'help',
|
||||||
helpmsgparts = [['[help]', 'Get this message.'],
|
helpmsgparts = [
|
||||||
['balance', 'Get your balance.'],
|
['[help]', 'Get this message.'],
|
||||||
['deposit', 'Get address for your deposits.'],
|
['balance', 'Get your balance.'],
|
||||||
['withdraw ADDRESS AMOUNT', 'Withdraw AMOUNT credits to ADDRESS'],
|
['deposit', 'Get address for your deposits.'],
|
||||||
['[private] <user> <amount>', 'Mention a user with @ and then the amount to tip them, or put private before the user to tip them privately.']],
|
['withdraw ADDRESS AMOUNT', 'Withdraw AMOUNT credits to ADDRESS'],
|
||||||
helpmsg = { "embed" : {
|
['[private] <user> <amount>', 'Mention a user with @ and then the amount to tip them, or put private before the user to tip them privately.']
|
||||||
"description": formatDescriptions(helpmsgparts) +
|
],
|
||||||
'\nKey: [] : Optionally include contained keyword, <> : Replace with appropriate value.',
|
helpmsg = {
|
||||||
"color": 1109218,
|
embed: {
|
||||||
"author": { "name": "!tip" } } },
|
description: formatDescriptions(helpmsgparts) + '\nKey: [] : Optionally include contained keyword, <> : Replace with appropriate value.',
|
||||||
channelwarning = 'Please use <'+ spamchannel + '> or DMs to talk to bots.';
|
color: 1109218,
|
||||||
|
author: { name: '!tip' }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
channelwarning = 'Please use <' + spamchannel + '> or DMs to talk to bots.';
|
||||||
switch (subcommand) {
|
switch (subcommand) {
|
||||||
case 'help': privateOrSandboxOnly(msg, channelwarning, doHelp, [helpmsg]); break;
|
case 'help':
|
||||||
case 'balance': doBalance(msg, tipper); break;
|
privateOrSandboxOnly(msg, channelwarning, doHelp, [helpmsg]);
|
||||||
case 'deposit': privateOrSandboxOnly(msg, channelwarning, doDeposit, [tipper]); break;
|
break;
|
||||||
case 'withdraw': privateOrSandboxOnly(msg, channelwarning, doWithdraw, [tipper, words, helpmsg]); break;
|
case 'balance':
|
||||||
default: doTip(msg, tipper, words, helpmsg);
|
doBalance(msg, tipper);
|
||||||
|
break;
|
||||||
|
case 'deposit':
|
||||||
|
privateOrSandboxOnly(msg, channelwarning, doDeposit, [tipper]);
|
||||||
|
break;
|
||||||
|
case 'withdraw':
|
||||||
|
privateOrSandboxOnly(msg, channelwarning, doWithdraw, [tipper, words, helpmsg]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
doTip(msg, tipper, words, helpmsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
exports.multitip = {
|
exports.multitip = {
|
||||||
usage: "<subcommand>",
|
usage: '<subcommand>',
|
||||||
description: 'Tip multiple users simultaneously for the same amount of LBC each.',
|
description: 'Tip multiple users simultaneously for the same amount of LBC each.',
|
||||||
process: async function (bot, msg, suffix) {
|
process: async function(bot, msg, suffix) {
|
||||||
let tipper = msg.author.id.replace('!', ''),
|
let tipper = msg.author.id.replace('!', ''),
|
||||||
words = msg.content.trim().split(' ').filter(function (n) { return n !== ""; }),
|
words = msg.content
|
||||||
subcommand = words.length >= 2 ? words[1] : 'help',
|
.trim()
|
||||||
helpmsgparts = [['[help]', 'Get this message.'],
|
.split(' ')
|
||||||
['<user>+ <amount>', 'Mention one or more users in a row, seperated by spaces, then an amount that each mentioned user will receive.'],
|
.filter(function(n) {
|
||||||
['private <user>+ <amount>','Put private before the user list to have each user tipped privately, without revealing other users tipped.']],
|
return n !== '';
|
||||||
helpmsg = { "embed" : {
|
}),
|
||||||
"description": formatDescriptions(helpmsgparts) +
|
subcommand = words.length >= 2 ? words[1] : 'help',
|
||||||
'\nKey: [] : Optionally include contained keyword, <> : Replace with appropriate value, + : Value can be repeated for multiple entries.',
|
helpmsgparts = [
|
||||||
"color": 1109218,
|
['[help]', 'Get this message.'],
|
||||||
"author": { "name": "!multitip" } } },
|
['<user>+ <amount>', 'Mention one or more users in a row, seperated by spaces, then an amount that each mentioned user will receive.'],
|
||||||
channelwarning = 'Please use <'+ spamchannel + '> or DMs to talk to bots.';
|
['private <user>+ <amount>', 'Put private before the user list to have each user tipped privately, without revealing other users tipped.']
|
||||||
switch(subcommand) {
|
],
|
||||||
case 'help': privateOrSandboxOnly(msg, channelwarning, doHelp, [helpmsg]); break;
|
helpmsg = {
|
||||||
default: doMultiTip(msg, tipper, words, helpmsg); break;
|
embed: {
|
||||||
|
description: formatDescriptions(helpmsgparts) + '\nKey: [] : Optionally include contained keyword, <> : Replace with appropriate value, + : Value can be repeated for multiple entries.',
|
||||||
|
color: 1109218,
|
||||||
|
author: { name: '!multitip' }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
channelwarning = 'Please use <' + spamchannel + '> or DMs to talk to bots.';
|
||||||
|
switch (subcommand) {
|
||||||
|
case 'help':
|
||||||
|
privateOrSandboxOnly(msg, channelwarning, doHelp, [helpmsg]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
doMultiTip(msg, tipper, words, helpmsg);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
exports.roletip = {
|
exports.roletip = {
|
||||||
usage: "<subcommand>",
|
usage: '<subcommand>',
|
||||||
description: 'Tip every user in a given role the same amount of LBC.',
|
description: 'Tip every user in a given role the same amount of LBC.',
|
||||||
process: async function (bot, msg, suffix) {
|
process: async function(bot, msg, suffix) {
|
||||||
let tipper = msg.author.id.replace('!', ''),
|
let tipper = msg.author.id.replace('!', ''),
|
||||||
words = msg.content.trim().split(' ').filter(function (n) { return n !== ""; }),
|
words = msg.content
|
||||||
subcommand = words.length >= 2 ? words[1] : 'help',
|
.trim()
|
||||||
helpmsgparts = [['[help]', 'Get this message'],
|
.split(' ')
|
||||||
['<role> <amount>', 'Mention a single role, then an amount that each user in that role will receive.'],
|
.filter(function(n) {
|
||||||
['private <role> <amount>','Put private before the role to have each user tipped privately, without revealing other users tipped.']],
|
return n !== '';
|
||||||
helpmsg = { "embed" : {
|
}),
|
||||||
"description": formatDescriptions(helpmsgparts) +
|
subcommand = words.length >= 2 ? words[1] : 'help',
|
||||||
'\nKey: [] : Optionally include contained keyword, <> : Replace with appropriate value.',
|
helpmsgparts = [
|
||||||
"color": 1109218,
|
['[help]', 'Get this message'],
|
||||||
"author": { "name": "!roletip" } } },
|
['<role> <amount>', 'Mention a single role, then an amount that each user in that role will receive.'],
|
||||||
channelwarning = 'Please use <'+ spamchannel + '> or DMs to talk to bots.';
|
['private <role> <amount>', 'Put private before the role to have each user tipped privately, without revealing other users tipped.']
|
||||||
switch(subcommand) {
|
],
|
||||||
case 'help': privateOrSandboxOnly(msg, channelwarning, doHelp, [helpmsg]); break;
|
helpmsg = {
|
||||||
default: doRoleTip(msg, tipper, words, helpmsg); break;
|
embed: {
|
||||||
|
description: formatDescriptions(helpmsgparts) + '\nKey: [] : Optionally include contained keyword, <> : Replace with appropriate value.',
|
||||||
|
color: 1109218,
|
||||||
|
author: { name: '!roletip' }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
channelwarning = `Please use <${spamchannel}> or DMs to talk to bots.`;
|
||||||
|
switch (subcommand) {
|
||||||
|
case 'help':
|
||||||
|
privateOrSandboxOnly(msg, channelwarning, doHelp, [helpmsg]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
doRoleTip(msg, tipper, words, helpmsg);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
exports.tipcommands = {
|
exports.tipcommands = {
|
||||||
usage: "",
|
usage: '',
|
||||||
description: 'Lists all available tipbot commands with brief descriptions for each one.',
|
description: 'Lists all available tipbot commands with brief descriptions for each one.',
|
||||||
process: async function (bot, msg, suffix) {
|
process: async function(bot, msg, suffix) {
|
||||||
let helpmsgparts = [['!tip', 'Tip a given user with an amount of LBC or perform wallet specific operations.'],
|
let helpmsgparts = [
|
||||||
['!multitip', 'Tip multiple users simultaneously for the same amount of LBC each.'],
|
['!tip', 'Tip a given user with an amount of LBC or perform wallet specific operations.'],
|
||||||
['!roletip','Tip every user in a given role the same amount of LBC.'],
|
['!multitip', 'Tip multiple users simultaneously for the same amount of LBC each.'],
|
||||||
['!tipcommands', 'Lists all available tipbot commands with brief descriptions for each one.']],
|
['!roletip', 'Tip every user in a given role the same amount of LBC.'],
|
||||||
helpmsg = { "embed" : {
|
['!tipcommands', 'Lists all available tipbot commands with brief descriptions for each one.']
|
||||||
"description": "These are all the commands that TipBot currently supports. Use `!<command> help` for usage instructions.\n" +
|
],
|
||||||
formatDescriptions(helpmsgparts),
|
helpmsg = {
|
||||||
"color": 1109218,
|
embed: {
|
||||||
"author": { "name": "Tipbot Commands" } } };
|
description: `These are all the commands that TipBot currently supports. Use \`!<command> help\` for usage instructions.
|
||||||
|
${formatDescriptions(helpmsgparts)}`,
|
||||||
|
color: 1109218,
|
||||||
|
author: { name: 'Tipbot Commands' }
|
||||||
|
}
|
||||||
|
};
|
||||||
msg.reply(helpmsg);
|
msg.reply(helpmsg);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
function privateOrSandboxOnly(message, wrongchannelmsg, fn, args) {
|
function privateOrSandboxOnly(message, wrongchannelmsg, fn, args) {
|
||||||
if (!inPrivateOrBotSandbox(message)) {
|
if (!inPrivateOrBotSandbox(message)) {
|
||||||
|
@ -113,69 +156,59 @@ function privateOrSandboxOnly(message, wrongchannelmsg, fn, args) {
|
||||||
fn.apply(null, [message, ...args]);
|
fn.apply(null, [message, ...args]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function doHelp(message, helpmsg) {
|
function doHelp(message, helpmsg) {
|
||||||
message.author.send(helpmsg);
|
message.author.send(helpmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function doBalance(message, tipper) {
|
function doBalance(message, tipper) {
|
||||||
lbry.getBalance(tipper, 1, function (err, balance) {
|
lbry.getBalance(tipper, 1, function(err, balance) {
|
||||||
if (err) {
|
if (err) {
|
||||||
message.reply('Error getting balance.').then(message => message.delete(5000));
|
message.reply('Error getting balance.').then(message => message.delete(5000));
|
||||||
}
|
} else {
|
||||||
else {
|
message.reply(`You have *${balance}* LBC`);
|
||||||
message.reply('You have *' + balance + '* LBC');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function doDeposit(message, tipper) {
|
function doDeposit(message, tipper) {
|
||||||
getAddress(tipper, function (err, address) {
|
getAddress(tipper, function(err, address) {
|
||||||
if (err) {
|
if (err) {
|
||||||
message.reply('Error getting your deposit address.').then(message => message.delete(5000));
|
message.reply('Error getting your deposit address.').then(message => message.delete(5000));
|
||||||
}
|
} else {
|
||||||
else {
|
message.reply(`Your address is ${address}`);
|
||||||
message.reply('Your address is ' + address);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function doWithdraw(message, tipper, words, helpmsg) {
|
function doWithdraw(message, tipper, words, helpmsg) {
|
||||||
if (words.length < 4) {
|
if (words.length < 4) {
|
||||||
doHelp(message, helpmsg);
|
return doHelp(message, helpmsg);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var address = words[2],
|
let address = words[2],
|
||||||
amount = getValidatedAmount(words[3]);
|
amount = getValidatedAmount(words[3]);
|
||||||
|
|
||||||
if (amount === null) {
|
if (amount === null) {
|
||||||
message.reply('I dont know how to withdraw that many coins...').then(message => message.delete(5000));
|
message.reply("I don't know how to withdraw that many credits...").then(message => message.delete(5000));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lbry.sendFrom(tipper, address, amount, function (err, txId) {
|
lbry.sendFrom(tipper, address, amount, function(err, txId) {
|
||||||
if (err) {
|
if (err) {
|
||||||
message.reply(err.message).then(message => message.delete(5000));
|
return message.reply(err.message).then(message => message.delete(5000));
|
||||||
}
|
|
||||||
else {
|
|
||||||
message.reply('You withdrew ' + amount + ' LBC to ' + address + '.\n' + txLink(txId));
|
|
||||||
}
|
}
|
||||||
|
message.reply(`You withdrew ${amount} LBC to ${address}.
|
||||||
|
${txLink(txId)}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function doTip(message, tipper, words, helpmsg) {
|
function doTip(message, tipper, words, helpmsg) {
|
||||||
if (words.length < 3 || !words) {
|
if (words.length < 3 || !words) {
|
||||||
doHelp(message, helpmsg);
|
return doHelp(message, helpmsg);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var prv = false;
|
let prv = false;
|
||||||
var amountOffset = 2;
|
let amountOffset = 2;
|
||||||
if (words.length >= 4 && words[1] === 'private') {
|
if (words.length >= 4 && words[1] === 'private') {
|
||||||
prv = true;
|
prv = true;
|
||||||
amountOffset = 3;
|
amountOffset = 3;
|
||||||
|
@ -184,19 +217,15 @@ function doTip(message, tipper, words, helpmsg) {
|
||||||
let amount = getValidatedAmount(words[amountOffset]);
|
let amount = getValidatedAmount(words[amountOffset]);
|
||||||
|
|
||||||
if (amount === null) {
|
if (amount === null) {
|
||||||
message.reply('I dont know how to tip that many coins...').then(message => message.delete(5000));
|
return message.reply("I don't know how to tip that many credits...").then(message => message.delete(5000));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.mentions.users.first().id) {
|
if (message.mentions.users.first().id) {
|
||||||
sendLBC(message, tipper, message.mentions.users.first().id.replace('!', ''), amount, prv);
|
return sendLbc(message, tipper, message.mentions.users.first().id.replace('!', ''), amount, prv);
|
||||||
}
|
|
||||||
else {
|
|
||||||
message.reply('Sorry, I could not find a user in your tip...').then(message => message.delete(5000));
|
|
||||||
}
|
}
|
||||||
|
message.reply('Sorry, I could not find a user in your tip...');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function doMultiTip(message, tipper, words, helpmsg) {
|
function doMultiTip(message, tipper, words, helpmsg) {
|
||||||
if (!words) {
|
if (!words) {
|
||||||
doHelp(message, helpmsg);
|
doHelp(message, helpmsg);
|
||||||
|
@ -206,128 +235,117 @@ function doMultiTip(message, tipper, words, helpmsg) {
|
||||||
doTip(message, tipper, words, helpmsg);
|
doTip(message, tipper, words, helpmsg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var prv = false;
|
let prv = false;
|
||||||
if (words.length >= 5 && words[1] === 'private') {
|
if (words.length >= 5 && words[1] === 'private') {
|
||||||
prv = true;
|
prv = true;
|
||||||
}
|
}
|
||||||
let [userIDs, amount] = findUserIDsAndAmount(message, words, prv);
|
let [userIDs, amount] = findUserIDsAndAmount(message, words, prv);
|
||||||
if (amount == null) {
|
if (amount == null) {
|
||||||
message.reply('I don\'t know how to tip that many coins...').then(message => message.delete(5000));
|
message.reply("I don't know how to tip that many coins...").then(message => message.delete(5000));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!userIDs) {
|
if (!userIDs) {
|
||||||
message.reply('Sorry, I could not find a user in your tip...').then(message => message.delete(5000));
|
message.reply('Sorry, I could not find a user in your tip...').then(message => message.delete(5000));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (var i = 0; i < userIDs.length; i++) {
|
for (let i = 0; i < userIDs.length; i++) {
|
||||||
sendLBC(message, tipper, userIDs[i].toString(), amount, prv);
|
sendLBC(message, tipper, userIDs[i].toString(), amount, prv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function doRoleTip(message, tipper, words, helpmsg) {
|
function doRoleTip(message, tipper, words, helpmsg) {
|
||||||
if (!words || words.length < 3) {
|
if (!words || words.length < 3) {
|
||||||
doHelp(message, helpmsg);
|
doHelp(message, helpmsg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var prv = false;
|
let prv = false;
|
||||||
var amountOffset = 2;
|
let amountOffset = 2;
|
||||||
if (words.length >= 4 && words[1] === 'private') {
|
if (words.length >= 4 && words[1] === 'private') {
|
||||||
prv = true;
|
prv = true;
|
||||||
amountOffset = 3;
|
amountOffset = 3;
|
||||||
}
|
}
|
||||||
let amount = getValidatedAmount(words[amountOffset]);
|
let amount = getValidatedAmount(words[amountOffset]);
|
||||||
if (amount == null) {
|
if (amount == null) {
|
||||||
message.reply('I don\'t know how to tip that many coins...').then(message => message.delete(5000));
|
message.reply("I don't know how to tip that many coins...").then(message => message.delete(5000));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (message.mentions.roles.first().id) {
|
if (message.mentions.roles.first().id) {
|
||||||
if (message.mentions.roles.first().members.first().id) {
|
if (message.mentions.roles.first().members.first().id) {
|
||||||
let userIDs = message.mentions.roles.first().members.map(member => member.user.id.replace('!', ''));
|
let userIDs = message.mentions.roles.first().members.map(member => member.user.id.replace('!', ''));
|
||||||
for (var i = 0; i < userIDs; i++) {
|
for (let i = 0; i < userIDs; i++) {
|
||||||
sendLBC(message, tipper, userIDs[i], amount, prv);
|
sendLBC(message, tipper, userIDs[i], amount, prv);
|
||||||
}
|
}
|
||||||
return;
|
} else {
|
||||||
}
|
|
||||||
else {
|
|
||||||
message.reply('Sorry, I could not find any users to tip in that role...').then(message => message.delete(5000));
|
message.reply('Sorry, I could not find any users to tip in that role...').then(message => message.delete(5000));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
message.reply('Sorry, I could not find any roles in your tip...').then(message => message.delete(5000));
|
message.reply('Sorry, I could not find any roles in your tip...').then(message => message.delete(5000));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function findUserIDsAndAmount(message, words, prv) {
|
function findUserIDsAndAmount(message, words, prv) {
|
||||||
var idList = [];
|
let idList = [];
|
||||||
var amount = null;
|
let amount = null;
|
||||||
var count = 0;
|
let count = 0;
|
||||||
var startOffset = 1;
|
let startOffset = 1;
|
||||||
if (prv) startOffset = 2;
|
if (prv) startOffset = 2;
|
||||||
var regex = new RegExp(/<@!?[0-9]+>/)
|
let regex = new RegExp(/<@!?[0-9]+>/);
|
||||||
for (var i = startOffset; i < words.length; i++) {
|
for (let i = startOffset; i < words.length; i++) {
|
||||||
if (regex.test(words[i])) {
|
if (regex.test(words[i])) {
|
||||||
count++;
|
count++;
|
||||||
idList.push(words[i].match(/[0-9]+/));
|
idList.push(words[i].match(/[0-9]+/));
|
||||||
} else {
|
} else {
|
||||||
amount = getValidatedAmount(words[Number(count)+1]);
|
amount = getValidatedAmount(words[Number(count) + 1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [idList, amount];
|
return [idList, amount];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function sendLBC(message, tipper, recipient, amount, privacyFlag) {
|
function sendLBC(message, tipper, recipient, amount, privacyFlag) {
|
||||||
getAddress(recipient.toString(), function (err, address) {
|
getAddress(recipient.toString(), function(err, address) {
|
||||||
if (err) {
|
if (err) {
|
||||||
message.reply(err.message).then(message => message.delete(5000));
|
message.reply(err.message).then(message => message.delete(5000));
|
||||||
}
|
} else {
|
||||||
else {
|
lbry.sendFrom(tipper, address, Number(amount), 1, null, null, function(err, txId) {
|
||||||
lbry.sendFrom(tipper, address, Number(amount), 1, null, null, function (err, txId) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
message.reply(err.message).then(message => message.delete(5000));
|
message.reply(err.message).then(message => message.delete(5000));
|
||||||
}
|
} else {
|
||||||
else {
|
let tx = txLink(txId);
|
||||||
var tx = txLink(txId);
|
let msgtail = `
|
||||||
var msgtail = '\nDM me with `' + message.content.split(" ", 1)[0] + '` for command specific instructions or with `!tipcommands` for all available commands';
|
DM me with \`${message.content.split(' ', 1)[0]}\` for command specific instructions or with \`!tipcommands\` for all available commands`;
|
||||||
if (privacyFlag) {
|
if (privacyFlag) {
|
||||||
var authmsg = 'You have just privately tipped <@' + recipient + '> ' + amount + ' LBC.\n' + tx + msgtail;
|
let authmsg = `You have just privately tipped <@${recipient}> ${amount} LBC.
|
||||||
|
${tx}${msgtail}`;
|
||||||
message.author.send(authmsg);
|
message.author.send(authmsg);
|
||||||
if (message.author.id != message.mentions.users.first().id) {
|
if (message.author.id !== message.mentions.users.first().id) {
|
||||||
var usr = message.guild.members.find('id', recipient).user;
|
let usr = message.guild.members.find('id', recipient).user;
|
||||||
var recipientmsg = 'You have just been privately tipped ' + amount + ' LBC by <@' + tipper + '>.\n' + tx + msgtail;
|
let recipientmsg = `You have just been privately tipped ${amount} LBC by <@${tipper}>.
|
||||||
|
${tx}${msgtail}`;
|
||||||
usr.send(recipientmsg);
|
usr.send(recipientmsg);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var generalmsg =
|
let generalmsg = `Wubba lubba dub dub! <@${tipper}> tipped <@${recipient}> ${amount} LBC.
|
||||||
'Wubba lubba dub dub! <@' + tipper + '> tipped <@' + recipient + '> ' + amount + ' LBC.\n' + tx + msgtail;
|
${tx}${msgtail}`;
|
||||||
message.reply(generalmsg);
|
message.reply(generalmsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
function getAddress(userId, cb) {
|
function getAddress(userId, cb) {
|
||||||
lbry.getAddressesByAccount(userId, function (err, addresses) {
|
lbry.getAddressesByAccount(userId, function(err, addresses) {
|
||||||
if (err) {
|
if (err) {
|
||||||
cb(err);
|
cb(err);
|
||||||
}
|
} else if (addresses.length > 0) {
|
||||||
else if (addresses.length > 0) {
|
|
||||||
cb(null, addresses[0]);
|
cb(null, addresses[0]);
|
||||||
}
|
} else {
|
||||||
else {
|
lbry.getNewAddress(userId, function(err, address) {
|
||||||
lbry.getNewAddress(userId, function (err, address) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
cb(err);
|
cb(err);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
cb(null, address);
|
cb(null, address);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -335,16 +353,10 @@ function getAddress(userId, cb) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function inPrivateOrBotSandbox(msg) {
|
function inPrivateOrBotSandbox(msg) {
|
||||||
if ((msg.channel.type == 'dm') || (msg.channel.id === spamchannel)) {
|
return msg.channel.type === 'dm' || msg.channel.id === spamchannel;
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getValidatedAmount(amount) {
|
function getValidatedAmount(amount) {
|
||||||
amount = amount.trim();
|
amount = amount.trim();
|
||||||
if (amount.toLowerCase().endsWith('lbc')) {
|
if (amount.toLowerCase().endsWith('lbc')) {
|
||||||
|
@ -353,13 +365,16 @@ function getValidatedAmount(amount) {
|
||||||
return amount.match(/^[0-9]+(\.[0-9]+)?$/) ? amount : null;
|
return amount.match(/^[0-9]+(\.[0-9]+)?$/) ? amount : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function txLink(txId) {
|
function txLink(txId) {
|
||||||
return "<https://explorer.lbry.io/tx/" + txId + ">";
|
return '<https://explorer.lbry.io/tx/' + txId + '>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function formatDescriptions(msgparts) {
|
function formatDescriptions(msgparts) {
|
||||||
return msgparts.map(elem => '\t**' + elem[0] + '**\n\t\t' + elem[1] + '\n')
|
return msgparts
|
||||||
.join('');
|
.map(
|
||||||
|
elem => `\t**${elem[0]}**
|
||||||
|
\t\t${elem[1]}
|
||||||
|
`
|
||||||
|
)
|
||||||
|
.join('');
|
||||||
}
|
}
|
||||||
|
|
910
package-lock.json
generated
910
package-lock.json
generated
File diff suppressed because it is too large
Load diff
13
package.json
13
package.json
|
@ -4,22 +4,23 @@
|
||||||
"babel-preset-node8": "^1.2.0",
|
"babel-preset-node8": "^1.2.0",
|
||||||
"bitcoin": "^3.0.1",
|
"bitcoin": "^3.0.1",
|
||||||
"chrono-node": "^1.3.5",
|
"chrono-node": "^1.3.5",
|
||||||
"config": "^1.27.0",
|
"config": "^1.29.4",
|
||||||
"discord.js": "^11.2.1",
|
"discord.js": "^11.3.0",
|
||||||
"embed-creator": "^1.1.4",
|
"embed-creator": "^1.1.4",
|
||||||
"jsonpath": "^0.2.12",
|
"jsonpath": "^0.2.12",
|
||||||
"moment": "^2.20.1",
|
"moment": "^2.20.1",
|
||||||
"mongoose": "^4.13.7",
|
"mongoose": "^4.13.11",
|
||||||
"node-config": "^0.0.2",
|
"node-config": "^0.0.2",
|
||||||
"numeral": "^2.0.6",
|
"numeral": "^2.0.6",
|
||||||
|
"regex": "^0.1.1",
|
||||||
"request": "^2.83.0"
|
"request": "^2.83.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prettier": "prettier * --write",
|
"prettier": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240",
|
||||||
"build": "babel bot -d dist",
|
"build": "babel bot -d dist",
|
||||||
"prod": "babel bot -d dist & node dist/bot.js",
|
"prod": "babel bot -d dist & node dist/bot.js",
|
||||||
"lint": "prettier --write bot/**/*.js",
|
"lint": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240",
|
||||||
"precommit": "prettier --write bot/**/*.js"
|
"precommit": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"prettier": "1.7.4"
|
"prettier": "1.7.4"
|
||||||
|
|
Loading…
Add table
Reference in a new issue