removed ! from IDs
formatted code upgraded dependencies
This commit is contained in:
parent
c1ad12824c
commit
09f50ffc5c
3 changed files with 56 additions and 57 deletions
|
@ -6,27 +6,27 @@ config = config.get('lbrycrd');
|
|||
const lbry = new bitcoin.Client(config);
|
||||
|
||||
exports.commands = [
|
||||
"tip"
|
||||
"tip"
|
||||
]
|
||||
exports.tip = {
|
||||
usage: "<subcommand>",
|
||||
description: 'balance: get your balance\n deposit: get address for your deposits\n withdraw ADDRESS AMOUNT: withdraw AMOUNT credits to ADDRESS\n [private] <user> <amount>: mention a user with @ and then the amount to tip them, or put private before the user to tip them privately.\n Key: [] : Optionally include contained keyword, <> : Replace with appropriate value.',
|
||||
process: async function(bot,msg,suffix){
|
||||
let tipper = msg.author.id,
|
||||
words = msg.content.trim().split(' ').filter( function(n){return n !== "";} ),
|
||||
subcommand = words.length >= 2 ? words[1] : 'help';
|
||||
usage: "<subcommand>",
|
||||
description: 'balance: get your balance\n deposit: get address for your deposits\n withdraw ADDRESS AMOUNT: withdraw AMOUNT credits to ADDRESS\n [private] <user> <amount>: mention a user with @ and then the amount to tip them, or put private before the user to tip them privately.\n Key: [] : Optionally include contained keyword, <> : Replace with appropriate value.',
|
||||
process: async function (bot, msg, suffix) {
|
||||
let tipper = msg.author.id.replace('!', ''),
|
||||
words = msg.content.trim().split(' ').filter(function (n) { return n !== ""; }),
|
||||
subcommand = words.length >= 2 ? words[1] : 'help';
|
||||
switch (subcommand) {
|
||||
case 'help': doHelp(msg); break;
|
||||
case 'balance': doBalance(msg, tipper); break;
|
||||
case 'deposit': doDeposit(msg, tipper); break;
|
||||
case 'withdraw': doWithdraw(msg, tipper, words); break;
|
||||
default: doTip(msg, tipper, words);
|
||||
}
|
||||
}
|
||||
case 'help': doHelp(msg); break;
|
||||
case 'balance': doBalance(msg, tipper); break;
|
||||
case 'deposit': doDeposit(msg, tipper); break;
|
||||
case 'withdraw': doWithdraw(msg, tipper, words); break;
|
||||
default: doTip(msg, tipper, words);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function doBalance(message, tipper) {
|
||||
lbry.getBalance(tipper, 1, function(err, balance) {
|
||||
lbry.getBalance(tipper, 1, function (err, balance) {
|
||||
if (err) {
|
||||
message.reply('Error getting balance');
|
||||
}
|
||||
|
@ -38,11 +38,11 @@ function doBalance(message, tipper) {
|
|||
|
||||
|
||||
function doDeposit(message, tipper) {
|
||||
if(!inPrivateOrBotSandbox(message)){
|
||||
if (!inPrivateOrBotSandbox(message)) {
|
||||
message.reply('Please use <#369896313082478594> or DMs to talk to bots.');
|
||||
return;
|
||||
}
|
||||
getAddress(tipper, function(err, address) {
|
||||
getAddress(tipper, function (err, address) {
|
||||
if (err) {
|
||||
message.reply('Error getting deposit address');
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ function doDeposit(message, tipper) {
|
|||
|
||||
|
||||
function doWithdraw(message, tipper, words) {
|
||||
if(!inPrivateOrBotSandbox(message)){
|
||||
if (!inPrivateOrBotSandbox(message)) {
|
||||
message.reply('Please use <#369896313082478594> or DMs to talk to bots.');
|
||||
return;
|
||||
}
|
||||
|
@ -64,14 +64,14 @@ function doWithdraw(message, tipper, words) {
|
|||
}
|
||||
|
||||
var address = words[2],
|
||||
amount = getValidatedAmount(words[3]);
|
||||
amount = getValidatedAmount(words[3]);
|
||||
|
||||
if (amount === null) {
|
||||
message.reply('I dont know how to withdraw that many credits');
|
||||
return;
|
||||
}
|
||||
|
||||
lbry.sendFrom(tipper, address, amount, function(err, txId) {
|
||||
lbry.sendFrom(tipper, address, amount, function (err, txId) {
|
||||
if (err) {
|
||||
message.reply(err.message);
|
||||
}
|
||||
|
@ -87,34 +87,33 @@ function doTip(message, tipper, words) {
|
|||
doHelp(message);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let prv = 0;
|
||||
let amountOffset = 2;
|
||||
if (words.length >= 4 && words[1] === 'private') {
|
||||
prv = 1;
|
||||
amountOffset = 3;
|
||||
prv = 1;
|
||||
amountOffset = 3;
|
||||
}
|
||||
|
||||
|
||||
let amount = getValidatedAmount(words[amountOffset]);
|
||||
|
||||
|
||||
if (amount === null) {
|
||||
message.reply('I dont know how to tip that many credits');
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.mentions.members.first().id) {
|
||||
let member = message.mentions.members.first();
|
||||
let member = message.mentions.members.first()
|
||||
sendLbc(message, tipper, member, amount, prv);
|
||||
}
|
||||
else
|
||||
{
|
||||
message.reply('Sorry, I could not find a user in your tip...');
|
||||
}
|
||||
else {
|
||||
message.reply('Sorry, I could not find a user in your tip...');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function doHelp(message) {
|
||||
if(!inPrivateOrBotSandbox(message)){
|
||||
if (!inPrivateOrBotSandbox(message)) {
|
||||
message.reply('Please use <#369896313082478594> or DMs to talk to bots.');
|
||||
return;
|
||||
}
|
||||
|
@ -124,12 +123,12 @@ function doHelp(message) {
|
|||
|
||||
|
||||
function sendLbc(message, tipper, member, amount, privacyFlag) {
|
||||
getAddress(member.id, function(err, address){
|
||||
getAddress(member.id.replace('!', ''), function (err, address) {
|
||||
if (err) {
|
||||
message.reply(err.message);
|
||||
}
|
||||
else {
|
||||
lbry.sendFrom(tipper, address, amount, 1, null, null, function(err, txId){
|
||||
lbry.sendFrom(tipper, address, amount, 1, null, null, function (err, txId) {
|
||||
if (err) {
|
||||
message.reply(err.message);
|
||||
}
|
||||
|
@ -137,12 +136,12 @@ function sendLbc(message, tipper, member, amount, privacyFlag) {
|
|||
var imessage =
|
||||
'Wubba lubba dub dub! <@' + tipper + '> tipped <@' + member.id + '> ' + amount + ' LBC (' + txLink(txId) + '). ' +
|
||||
'DM me `!tip` for tipbot instructions.'
|
||||
if (privacyFlag) {
|
||||
message.author.send(imessage);
|
||||
member.send(imessage);
|
||||
} else {
|
||||
message.reply(imessage);
|
||||
}
|
||||
if (privacyFlag) {
|
||||
message.author.send(imessage);
|
||||
member.send(imessage);
|
||||
} else {
|
||||
message.reply(imessage);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -151,15 +150,15 @@ function sendLbc(message, tipper, member, amount, privacyFlag) {
|
|||
|
||||
|
||||
function getAddress(userId, cb) {
|
||||
lbry.getAddressesByAccount(userId, function(err, addresses) {
|
||||
lbry.getAddressesByAccount(userId, function (err, addresses) {
|
||||
if (err) {
|
||||
cb(err);
|
||||
}
|
||||
else if(addresses.length > 0) {
|
||||
else if (addresses.length > 0) {
|
||||
cb(null, addresses[0]);
|
||||
}
|
||||
else {
|
||||
lbry.getNewAddress(userId, function(err, address) {
|
||||
lbry.getNewAddress(userId, function (err, address) {
|
||||
if (err) {
|
||||
cb(err);
|
||||
}
|
||||
|
@ -171,10 +170,10 @@ function getAddress(userId, cb) {
|
|||
});
|
||||
}
|
||||
|
||||
function inPrivateOrBotSandbox(msg){
|
||||
if((msg.channel.type == 'dm') || (msg.channel.id === '369896313082478594')){
|
||||
function inPrivateOrBotSandbox(msg) {
|
||||
if ((msg.channel.type == 'dm') || (msg.channel.id === '369896313082478594')) {
|
||||
return true;
|
||||
}else{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -182,7 +181,7 @@ function inPrivateOrBotSandbox(msg){
|
|||
function getValidatedAmount(amount) {
|
||||
amount = amount.trim();
|
||||
if (amount.toLowerCase().endsWith('lbc')) {
|
||||
amount = amount.substring(0, amount.length-3);
|
||||
amount = amount.substring(0, amount.length - 3);
|
||||
}
|
||||
return amount.match(/^[0-9]+(\.[0-9]+)?$/) ? amount : null;
|
||||
}
|
||||
|
|
16
package-lock.json
generated
16
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "lbry-tipbot",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.3",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -572,7 +572,7 @@
|
|||
"resolved": "https://registry.npmjs.org/chrono-node/-/chrono-node-1.3.5.tgz",
|
||||
"integrity": "sha1-oklSmKMtqCvMAa2b59d++l4kQSI=",
|
||||
"requires": {
|
||||
"moment": "2.19.3"
|
||||
"moment": "2.20.1"
|
||||
}
|
||||
},
|
||||
"cjson": {
|
||||
|
@ -1290,9 +1290,9 @@
|
|||
}
|
||||
},
|
||||
"moment": {
|
||||
"version": "2.19.3",
|
||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.19.3.tgz",
|
||||
"integrity": "sha1-vbmdJw1tf9p4zA+6zoVeJ/59pp8="
|
||||
"version": "2.20.1",
|
||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.20.1.tgz",
|
||||
"integrity": "sha512-Yh9y73JRljxW5QxN08Fner68eFLxM5ynNOAw2LbIB1YAGeQzZT8QFSUvkAz609Zf+IHhhaUxqZK8dG3W/+HEvg=="
|
||||
},
|
||||
"mongodb": {
|
||||
"version": "2.2.33",
|
||||
|
@ -1330,9 +1330,9 @@
|
|||
}
|
||||
},
|
||||
"mongoose": {
|
||||
"version": "4.13.6",
|
||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-4.13.6.tgz",
|
||||
"integrity": "sha512-H+loD0D8UCwGmbOzWV7rZAf6/efRr9CPGB1Bess/IIjiWvpRQNo4zH4UHkueKoEbMWdnSYenjdEL8A0Q8p7JXg==",
|
||||
"version": "4.13.7",
|
||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-4.13.7.tgz",
|
||||
"integrity": "sha512-3VPcGQWaTzT/OVK+TpE9dGpNHBnEqFX2RmbFr1XvbsKmxPsL9kaRBSHqaQ8QEMd6CUeOYMRdH1pKRrlnCenRsg==",
|
||||
"requires": {
|
||||
"async": "2.1.4",
|
||||
"bson": "1.0.4",
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
"discord.js": "^11.2.1",
|
||||
"embed-creator": "^1.1.4",
|
||||
"jsonpath": "^0.2.12",
|
||||
"moment": "^2.19.1",
|
||||
"mongoose": "^4.12.3",
|
||||
"moment": "^2.20.1",
|
||||
"mongoose": "^4.13.7",
|
||||
"node-config": "^0.0.2",
|
||||
"numeral": "^2.0.6",
|
||||
"request": "^2.83.0"
|
||||
|
@ -25,7 +25,7 @@
|
|||
"prettier": "1.7.4"
|
||||
},
|
||||
"name": "lbry-tipbot",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.3",
|
||||
"description": "LBRYs tipbot for Discord",
|
||||
"main": "app.js",
|
||||
"repository": "https://github.com/lbryio/lbry-tipbot",
|
||||
|
|
Loading…
Add table
Reference in a new issue