update commands

This commit is contained in:
Thomas Zarebczan 2018-04-13 13:56:28 -04:00
parent ce34ab6b85
commit 6745eeacf5

View file

@ -71,7 +71,7 @@ if(!fs.existsSync('./config/config.yml')) {
function replytweet(to, replyid, themessage) { function replytweet(to, replyid, themessage) {
winston.info('Preparing tweet' + '@' + to + ' :' + themessage); winston.info('Preparing tweet' + '@' + to + ' :' + themessage);
var newtweet = '@' + to + ' ' + themessage + ' (' + makeid() + ')'; var newtweet = '@' + to + ' ' + themessage + ' \nMsg_ID:(' + makeid() + ')';
winston.info('' + '@' + to + ' :' + newtweet); winston.info('' + '@' + to + ' :' + newtweet);
client.post('statuses/update', {status: newtweet, in_reply_to_status_id: replyid}, function (error, params, response) { client.post('statuses/update', {status: newtweet, in_reply_to_status_id: replyid}, function (error, params, response) {
if (error) { if (error) {
@ -173,7 +173,7 @@ if(!fs.existsSync('./config/config.yml')) {
coin.getBalance(settings.rpc.prefix + from.toLowerCase(), settings.coin.min_confirmations, function (err, balance) { coin.getBalance(settings.rpc.prefix + from.toLowerCase(), settings.coin.min_confirmations, function (err, balance) {
if (err) { if (err) {
locks[from.toLowerCase()] = null; locks[from.toLowerCase()] = null;
winston.error('Error in !tip command.', err); winston.error('Error in tip command.', err);
replytweet(from, replyid, settings.messages.error.expand({name: from})); replytweet(from, replyid, settings.messages.error.expand({name: from}));
return; return;
@ -182,8 +182,8 @@ if(!fs.existsSync('./config/config.yml')) {
if (balance >= amount) { if (balance >= amount) {
coin.send('move', settings.rpc.prefix + from.toLowerCase(), settings.rpc.prefix + to.toLowerCase(), amount, function (err, reply) { coin.send('move', settings.rpc.prefix + from.toLowerCase(), settings.rpc.prefix + to.toLowerCase(), amount, function (err, reply) {
locks[from.toLowerCase()] = null; locks[from.toLowerCase()] = null;
if (err || !reply) { if (err || reply) {
winston.error('Error in !tip command', err); winston.error('Error in tip command', err);
replytweet(from, replyid, settings.messages.error.expand({name: from})); replytweet(from, replyid, settings.messages.error.expand({name: from}));
return; return;
} }
@ -202,7 +202,7 @@ if(!fs.existsSync('./config/config.yml')) {
var user = from.toLowerCase(); var user = from.toLowerCase();
getAddress(user, function (err, address) { getAddress(user, function (err, address) {
if (err) { if (err) {
winston.error('Error in !address command', err); winston.error('Error in address command', err);
replytweet(from, replyid, settings.messages.error.expand({name: from})); replytweet(from, replyid, settings.messages.error.expand({name: from}));
return; return;
} }
@ -214,14 +214,14 @@ if(!fs.existsSync('./config/config.yml')) {
var user = from.toLowerCase(); var user = from.toLowerCase();
coin.getBalance(settings.rpc.prefix + user, settings.coin.min_confirmations, function (err, balance) { coin.getBalance(settings.rpc.prefix + user, settings.coin.min_confirmations, function (err, balance) {
if (err) { if (err) {
winston.error('Error in !balance command', err); winston.error('Error in balance command', err);
replytweet(from, replyid, settings.messages.error.expand({name: from})); replytweet(from, replyid, settings.messages.error.expand({name: from}));
return; return;
} }
var balance = typeof (balance) == 'object' ? balance.result : balance; var balance = typeof (balance) == 'object' ? balance.result : balance;
coin.getBalance(settings.rpc.prefix + user, 0, function (err, unconfirmed_balance) { coin.getBalance(settings.rpc.prefix + user, 0, function (err, unconfirmed_balance) {
if (err) { if (err) {
winston.error('Error in !balance command', err); winston.error('Error in balance command', err);
replytweet(from, replyid, settings.messages.balance.expand({balance: balance, name: user})); replytweet(from, replyid, settings.messages.balance.expand({balance: balance, name: user}));
return; return;
} }
@ -235,20 +235,20 @@ if(!fs.existsSync('./config/config.yml')) {
var user = from.toLowerCase(); var user = from.toLowerCase();
var match = message.match(/.?withdraw (\S+)$/); var match = message.match(/.?withdraw (\S+)$/);
if (match == null) { if (match == null) {
replytweet(from, replyid, 'Usage: !withdraw <' + settings.coin.full_name + ' address>'); replytweet(from, replyid, 'Usage: withdraw <' + settings.coin.full_name + ' address>');
return; return;
} }
var address = match[1]; var address = match[1];
coin.validateAddress(address, function (err, reply) { coin.validateAddress(address, function (err, reply) {
if (err) { if (err) {
winston.error('Error in !withdraw command', err); winston.error('Error in withdraw command', err);
replytweet(from, replyid, settings.messages.error.expand({name: from})); replytweet(from, replyid, settings.messages.error.expand({name: from}));
return; return;
} }
if (reply.isvalid) { if (reply.isvalid) {
coin.getBalance(settings.rpc.prefix + from.toLowerCase(), settings.coin.min_confirmations, function (err, balance) { coin.getBalance(settings.rpc.prefix + from.toLowerCase(), settings.coin.min_confirmations, function (err, balance) {
if (err) { if (err) {
winston.error('Error in !withdraw command', err); winston.error('Error in withdraw command', err);
replytweet(from, replyid, settings.messages.error.expand({name: from})); replytweet(from, replyid, settings.messages.error.expand({name: from}));
return; return;
} }
@ -260,7 +260,7 @@ if(!fs.existsSync('./config/config.yml')) {
} }
coin.sendFrom(settings.rpc.prefix + from.toLowerCase(), address, balance - settings.coin.withdrawal_fee, function (err, reply) { coin.sendFrom(settings.rpc.prefix + from.toLowerCase(), address, balance - settings.coin.withdrawal_fee, function (err, reply) {
if (err) { if (err) {
winston.error('Error in !withdraw command', err); winston.error('Error in withdraw command', err);
replytweet(from, replyid, settings.messages.error.expand({name: from})); replytweet(from, replyid, settings.messages.error.expand({name: from}));
return; return;
} }
@ -290,6 +290,8 @@ if(!fs.existsSync('./config/config.yml')) {
break; break;
default: default:
winston.warn("Invalid Command" + command); winston.warn("Invalid Command" + command);
replytweet(from, replyid, 'Invalid command. Tweet "@LBC_TipBot lbryian help" for list of commands or see reply below')
break; break;
} }
}); });