From 3cbf27109763411091fc6db39ebe01130e3d3e58 Mon Sep 17 00:00:00 2001 From: ahmedbodi Date: Fri, 1 Aug 2014 16:34:13 +0100 Subject: [PATCH 1/3] Add Cryptsy Price Ticker for MYR --- bin/tipbot.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bin/tipbot.js b/bin/tipbot.js index c8913b9..39ff8ce 100644 --- a/bin/tipbot.js +++ b/bin/tipbot.js @@ -4,6 +4,7 @@ var irc = require('irc'), yaml = require('js-yaml'), coin = require('node-dogecoin'), webadmin = require('../lib/webadmin/app'); +var Cryptsy = require('cryptsy'); // check if the config file exists if(!fs.existsSync('./config/config.yml')) { @@ -22,6 +23,9 @@ process.on('exit', function() { // load settings var settings = yaml.load(fs.readFileSync('./config/config.yml', 'utf-8')); +// Load Cryptsy +var cryptsy = new Cryptsy(settings.cryptsy.key, settings.cryptsy.secret); + // load winston's cli defaults winston.cli(); @@ -268,6 +272,23 @@ client.addListener('message', function(from, channel, message) { } }) break; + case 'price': + cryptsy.api('singlemarketdata', { marketid: 200 }, function (err, data) { + if(err) { + winston.error('Error in !price command.', err); + client.say(channel, settings.messages.error.expand({name: from})); + return; + } + winston.info('Fetched MYR Price From Cryptsy') + client.say(channel, settings.messages.tipped.expand({amount: data})); + }); + coin.getBalance(settings.rpc.prefix + from.toLowerCase(), settings.coin.min_confirmations, function(err, balance) { + if(err) { + winston.error('Error in !tip command.', err); + client.say(channel, settings.messages.error.expand({name: from})); + return; + } + case 'tip': var match = message.match(/^.?tip (\S+) (random)?([\d\.]+)/); if(match == null || match.length < 3) { From 10bf260caab43df58be29ff421c0107e25bc5a43 Mon Sep 17 00:00:00 2001 From: ahmedbodi Date: Fri, 1 Aug 2014 16:36:55 +0100 Subject: [PATCH 2/3] Fixed Syntax --- bin/tipbot.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/bin/tipbot.js b/bin/tipbot.js index 39ff8ce..3263010 100644 --- a/bin/tipbot.js +++ b/bin/tipbot.js @@ -280,15 +280,9 @@ client.addListener('message', function(from, channel, message) { return; } winston.info('Fetched MYR Price From Cryptsy') - client.say(channel, settings.messages.tipped.expand({amount: data})); + client.say(channel, settings.messages.price.expand({amount: data})); }); - coin.getBalance(settings.rpc.prefix + from.toLowerCase(), settings.coin.min_confirmations, function(err, balance) { - if(err) { - winston.error('Error in !tip command.', err); - client.say(channel, settings.messages.error.expand({name: from})); - return; - } - + break; case 'tip': var match = message.match(/^.?tip (\S+) (random)?([\d\.]+)/); if(match == null || match.length < 3) { From f3352cbc1166abf0158af3e4c03a90e009440cf5 Mon Sep 17 00:00:00 2001 From: ahmedbodi Date: Fri, 1 Aug 2014 16:38:20 +0100 Subject: [PATCH 3/3] MYR Price Cryptsy --- config/config.sample.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config/config.sample.yml b/config/config.sample.yml index 4e813c1..56f7f5d 100644 --- a/config/config.sample.yml +++ b/config/config.sample.yml @@ -12,6 +12,9 @@ channels: - '##tipbots' log: file: tipbot.log +cryptsy: + key: API_KEY_HERE + secret: API_SECRET_HERE rpc: host: localhost port: 22555 @@ -50,11 +53,15 @@ commands: terms: pm: true channel: false + price: + pm: true + channel: true rain: pm: false channel: true rain_on_last_active: 0 # amount in seconds. rain tips will fall only on users active within x seconds. leave 0 for no such behavior. messages: + price: 'MYR is current priced at %amount% BTC on cryptsy' error: 'Sorry %name%, something went wrong.' no_funds: "Sorry %name%, you don't have enough funds (you're %short%%short_name% short)" not_identified: '%name%: You need to be identified with NickServ to tip.'