mirror of
https://github.com/LBRYFoundation/lbry-tipbot.git
synced 2025-08-23 16:57:24 +00:00
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);
|
const lbry = new bitcoin.Client(config);
|
||||||
|
|
||||||
exports.commands = [
|
exports.commands = [
|
||||||
"tip"
|
"tip"
|
||||||
]
|
]
|
||||||
exports.tip = {
|
exports.tip = {
|
||||||
usage: "<subcommand>",
|
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.',
|
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){
|
process: async function (bot, msg, suffix) {
|
||||||
let tipper = msg.author.id,
|
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';
|
||||||
switch (subcommand) {
|
switch (subcommand) {
|
||||||
case 'help': doHelp(msg); break;
|
case 'help': doHelp(msg); break;
|
||||||
case 'balance': doBalance(msg, tipper); break;
|
case 'balance': doBalance(msg, tipper); break;
|
||||||
case 'deposit': doDeposit(msg, tipper); break;
|
case 'deposit': doDeposit(msg, tipper); break;
|
||||||
case 'withdraw': doWithdraw(msg, tipper, words); break;
|
case 'withdraw': doWithdraw(msg, tipper, words); break;
|
||||||
default: doTip(msg, tipper, words);
|
default: doTip(msg, tipper, words);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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');
|
message.reply('Error getting balance');
|
||||||
}
|
}
|
||||||
|
@ -38,11 +38,11 @@ function doBalance(message, tipper) {
|
||||||
|
|
||||||
|
|
||||||
function doDeposit(message, tipper) {
|
function doDeposit(message, tipper) {
|
||||||
if(!inPrivateOrBotSandbox(message)){
|
if (!inPrivateOrBotSandbox(message)) {
|
||||||
message.reply('Please use <#369896313082478594> or DMs to talk to bots.');
|
message.reply('Please use <#369896313082478594> or DMs to talk to bots.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getAddress(tipper, function(err, address) {
|
getAddress(tipper, function (err, address) {
|
||||||
if (err) {
|
if (err) {
|
||||||
message.reply('Error getting deposit address');
|
message.reply('Error getting deposit address');
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ function doDeposit(message, tipper) {
|
||||||
|
|
||||||
|
|
||||||
function doWithdraw(message, tipper, words) {
|
function doWithdraw(message, tipper, words) {
|
||||||
if(!inPrivateOrBotSandbox(message)){
|
if (!inPrivateOrBotSandbox(message)) {
|
||||||
message.reply('Please use <#369896313082478594> or DMs to talk to bots.');
|
message.reply('Please use <#369896313082478594> or DMs to talk to bots.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -64,14 +64,14 @@ function doWithdraw(message, tipper, words) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var address = words[2],
|
var 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 credits');
|
message.reply('I dont know how to withdraw that many credits');
|
||||||
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);
|
message.reply(err.message);
|
||||||
}
|
}
|
||||||
|
@ -87,34 +87,33 @@ function doTip(message, tipper, words) {
|
||||||
doHelp(message);
|
doHelp(message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let prv = 0;
|
let prv = 0;
|
||||||
let amountOffset = 2;
|
let amountOffset = 2;
|
||||||
if (words.length >= 4 && words[1] === 'private') {
|
if (words.length >= 4 && words[1] === 'private') {
|
||||||
prv = 1;
|
prv = 1;
|
||||||
amountOffset = 3;
|
amountOffset = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 credits');
|
message.reply('I dont know how to tip that many credits');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.mentions.members.first().id) {
|
if (message.mentions.members.first().id) {
|
||||||
let member = message.mentions.members.first();
|
let member = message.mentions.members.first()
|
||||||
sendLbc(message, tipper, member, amount, prv);
|
sendLbc(message, tipper, member, amount, prv);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
message.reply('Sorry, I could not find a user in your tip...');
|
||||||
message.reply('Sorry, I could not find a user in your tip...');
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function doHelp(message) {
|
function doHelp(message) {
|
||||||
if(!inPrivateOrBotSandbox(message)){
|
if (!inPrivateOrBotSandbox(message)) {
|
||||||
message.reply('Please use <#369896313082478594> or DMs to talk to bots.');
|
message.reply('Please use <#369896313082478594> or DMs to talk to bots.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -124,12 +123,12 @@ function doHelp(message) {
|
||||||
|
|
||||||
|
|
||||||
function sendLbc(message, tipper, member, amount, privacyFlag) {
|
function sendLbc(message, tipper, member, amount, privacyFlag) {
|
||||||
getAddress(member.id, function(err, address){
|
getAddress(member.id.replace('!', ''), function (err, address) {
|
||||||
if (err) {
|
if (err) {
|
||||||
message.reply(err.message);
|
message.reply(err.message);
|
||||||
}
|
}
|
||||||
else {
|
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) {
|
if (err) {
|
||||||
message.reply(err.message);
|
message.reply(err.message);
|
||||||
}
|
}
|
||||||
|
@ -137,12 +136,12 @@ function sendLbc(message, tipper, member, amount, privacyFlag) {
|
||||||
var imessage =
|
var imessage =
|
||||||
'Wubba lubba dub dub! <@' + tipper + '> tipped <@' + member.id + '> ' + amount + ' LBC (' + txLink(txId) + '). ' +
|
'Wubba lubba dub dub! <@' + tipper + '> tipped <@' + member.id + '> ' + amount + ' LBC (' + txLink(txId) + '). ' +
|
||||||
'DM me `!tip` for tipbot instructions.'
|
'DM me `!tip` for tipbot instructions.'
|
||||||
if (privacyFlag) {
|
if (privacyFlag) {
|
||||||
message.author.send(imessage);
|
message.author.send(imessage);
|
||||||
member.send(imessage);
|
member.send(imessage);
|
||||||
} else {
|
} else {
|
||||||
message.reply(imessage);
|
message.reply(imessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -151,15 +150,15 @@ function sendLbc(message, tipper, member, amount, privacyFlag) {
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -171,10 +170,10 @@ function getAddress(userId, cb) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function inPrivateOrBotSandbox(msg){
|
function inPrivateOrBotSandbox(msg) {
|
||||||
if((msg.channel.type == 'dm') || (msg.channel.id === '369896313082478594')){
|
if ((msg.channel.type == 'dm') || (msg.channel.id === '369896313082478594')) {
|
||||||
return true;
|
return true;
|
||||||
}else{
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,7 +181,7 @@ function inPrivateOrBotSandbox(msg){
|
||||||
function getValidatedAmount(amount) {
|
function getValidatedAmount(amount) {
|
||||||
amount = amount.trim();
|
amount = amount.trim();
|
||||||
if (amount.toLowerCase().endsWith('lbc')) {
|
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;
|
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",
|
"name": "lbry-tipbot",
|
||||||
"version": "0.0.2",
|
"version": "0.0.3",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -572,7 +572,7 @@
|
||||||
"resolved": "https://registry.npmjs.org/chrono-node/-/chrono-node-1.3.5.tgz",
|
"resolved": "https://registry.npmjs.org/chrono-node/-/chrono-node-1.3.5.tgz",
|
||||||
"integrity": "sha1-oklSmKMtqCvMAa2b59d++l4kQSI=",
|
"integrity": "sha1-oklSmKMtqCvMAa2b59d++l4kQSI=",
|
||||||
"requires": {
|
"requires": {
|
||||||
"moment": "2.19.3"
|
"moment": "2.20.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cjson": {
|
"cjson": {
|
||||||
|
@ -1290,9 +1290,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"moment": {
|
"moment": {
|
||||||
"version": "2.19.3",
|
"version": "2.20.1",
|
||||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.19.3.tgz",
|
"resolved": "https://registry.npmjs.org/moment/-/moment-2.20.1.tgz",
|
||||||
"integrity": "sha1-vbmdJw1tf9p4zA+6zoVeJ/59pp8="
|
"integrity": "sha512-Yh9y73JRljxW5QxN08Fner68eFLxM5ynNOAw2LbIB1YAGeQzZT8QFSUvkAz609Zf+IHhhaUxqZK8dG3W/+HEvg=="
|
||||||
},
|
},
|
||||||
"mongodb": {
|
"mongodb": {
|
||||||
"version": "2.2.33",
|
"version": "2.2.33",
|
||||||
|
@ -1330,9 +1330,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mongoose": {
|
"mongoose": {
|
||||||
"version": "4.13.6",
|
"version": "4.13.7",
|
||||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-4.13.6.tgz",
|
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-4.13.7.tgz",
|
||||||
"integrity": "sha512-H+loD0D8UCwGmbOzWV7rZAf6/efRr9CPGB1Bess/IIjiWvpRQNo4zH4UHkueKoEbMWdnSYenjdEL8A0Q8p7JXg==",
|
"integrity": "sha512-3VPcGQWaTzT/OVK+TpE9dGpNHBnEqFX2RmbFr1XvbsKmxPsL9kaRBSHqaQ8QEMd6CUeOYMRdH1pKRrlnCenRsg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"async": "2.1.4",
|
"async": "2.1.4",
|
||||||
"bson": "1.0.4",
|
"bson": "1.0.4",
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
"discord.js": "^11.2.1",
|
"discord.js": "^11.2.1",
|
||||||
"embed-creator": "^1.1.4",
|
"embed-creator": "^1.1.4",
|
||||||
"jsonpath": "^0.2.12",
|
"jsonpath": "^0.2.12",
|
||||||
"moment": "^2.19.1",
|
"moment": "^2.20.1",
|
||||||
"mongoose": "^4.12.3",
|
"mongoose": "^4.13.7",
|
||||||
"node-config": "^0.0.2",
|
"node-config": "^0.0.2",
|
||||||
"numeral": "^2.0.6",
|
"numeral": "^2.0.6",
|
||||||
"request": "^2.83.0"
|
"request": "^2.83.0"
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
"prettier": "1.7.4"
|
"prettier": "1.7.4"
|
||||||
},
|
},
|
||||||
"name": "lbry-tipbot",
|
"name": "lbry-tipbot",
|
||||||
"version": "0.0.2",
|
"version": "0.0.3",
|
||||||
"description": "LBRYs tipbot for Discord",
|
"description": "LBRYs tipbot for Discord",
|
||||||
"main": "app.js",
|
"main": "app.js",
|
||||||
"repository": "https://github.com/lbryio/lbry-tipbot",
|
"repository": "https://github.com/lbryio/lbry-tipbot",
|
||||||
|
|
Loading…
Add table
Reference in a new issue