diff --git a/bin/tipbot.js b/bin/tipbot.js index c8913b9..3263010 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,17 @@ 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.price.expand({amount: data})); + }); + break; case 'tip': var match = message.match(/^.?tip (\S+) (random)?([\d\.]+)/); if(match == null || match.length < 3) { 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.'