From 8166a4da5ec9d3cee49bde0a81b0bb3770da643e Mon Sep 17 00:00:00 2001 From: filipnyquist Date: Fri, 6 Jul 2018 15:47:49 +0200 Subject: [PATCH] Started work on the next version of tipbot. --- index.js | 20 ++++++++------------ move_helper.js | 3 +-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 8d88110..4e0f63f 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,6 @@ const winston = require("winston"); require("winston-daily-rotate-file"); const Client = require("bitcoin-core"); const lbry = new Client({ - version: "0.12.0", username: config.get("lbrycrd.username"), password: config.get("lbrycrd.password"), port: config.get("lbrycrd.port") @@ -44,7 +43,7 @@ stream.on("tweet", function(tweet) { if(tweet.user.screen_name === config.get("bot.handle").substring(1)) return; let msg = checkTrunc(tweet); msg = msg.slice(msg.indexOf(config.get("bot.handle"))).split(" "); - checkTweet(tweet, msg); + if (msg.length >= 2) checkTweet(tweet, msg); }); function checkTweet(tweet, msg) { @@ -84,7 +83,8 @@ async function doHelp(tweet, msg) { "balance - Get your balance. \n" + "deposit - Get address for your deposits. \n" + "withdraw ADDRESS AMOUNT - Withdraw AMOUNT credits to ADDRESS. \n" + - "tip USER AMOUNT - Tip USER AMOUNT.", + "tip USER AMOUNT - Tip USER AMOUNT.\n"+ + "terms - Sends you the TOS.", in_reply_to_status_id: tweet.id_str }); logger.info( @@ -100,7 +100,7 @@ async function doTerms(tweet, msg){ status: `@${tweet.user.screen_name} `+ "There are no fees to use this bot except the automatic daemon fee. \n"+ - "In no event shall LBRY Inc be responsible in the event of lost, stolen or misdirected funds.", + "Under no circumstances shall LBRY Inc. be held responsible for lost, stolen or misdirected funds.", in_reply_to_status_id: tweet.id_str }); } @@ -173,7 +173,7 @@ async function doTip(tweet, msg) { }); } const userToTip = tweet.entities.user_mentions.find(u => `@${u.screen_name}` === msg[2]).id_str; - await getAddress(id(userToTip)) // Call this to ensure user has an account. + let tipToAddress = await getAddress(id(userToTip)) // Call this to ensure user has an account. if (userToTip === null) { return await T.post("statuses/update", { status: `@${tweet.user.screen_name} I could not find that user...`, @@ -183,19 +183,15 @@ async function doTip(tweet, msg) { const balanceFromUser = await lbry.getBalance(id(tweet.user.id_str), config.get("bot.requiredConfirms")); if (balanceFromUser < amount) { return await T.post("statuses/update", { - status: `@${tweet.user.screen_name} You tried to tip, but you are missing ${amount-balanceFromUser} LBC.`, + status: `@${tweet.user.screen_name} You tried tipping more than you have! You are ${amount-balanceFromUser} LBC short.`, in_reply_to_status_id: tweet.id_str }); } - const txId = await lbry.move( - id(tweet.user.id_str), - id(userToTip), - Number(amount) - ); + const txId = await lbry.sendFrom(id(tweet.user.id_str), tipToAddress, Number(amount), 1); await T.post("statuses/update", { status: `@${tweet.user.screen_name} Tipped ${ msg[2] - } ${amount} LBC! \n See https://lbry.io/faq/tipbot-twitter for more information.`, + } ${amount} LBC! \nTransaction: ${txLink(txId)} \nSee https://lbry.io/faq/tipbot-twitter for more information.`, in_reply_to_status_id: tweet.id_str }); logger.info( diff --git a/move_helper.js b/move_helper.js index 20b0437..5dc63d8 100644 --- a/move_helper.js +++ b/move_helper.js @@ -85,9 +85,8 @@ async function getAddress(userId) { let uAddresses = await lbry.getAddressesByAccount(userId); if (uAddresses.length > 0) return; await lbry.getNewAddress(userId); - return; } catch (e) { - logger.error(e); + throw("Something went wrong while creating an account for the user: ", e); } }