From 7f2878ce585ea227d890f50ce0298d198891c407 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 11 Apr 2016 18:23:02 +0000 Subject: [PATCH] api function --- modules/dns/dns.js | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/modules/dns/dns.js b/modules/dns/dns.js index 82b6bbb..c22a9c4 100644 --- a/modules/dns/dns.js +++ b/modules/dns/dns.js @@ -11,6 +11,27 @@ var dns = function(dbot) { dbot.db.ip = {}; } var ips = dbot.db.ip; + + this.api = { + 'getGeoIp': function(ip, callback) { + if(_.has(ips, ip)) { + body = ips[ip]; + callback(ip + ' is located in '+ body.city + ', ' + body.country + '. Hostname: ' + body.hostname + '. ISP: ' + body.org); + } else { + request.get('http://ipinfo.io/'+ip, { + 'json': true + }, function(err, res, body) { + if(!err && body) { + callback(ip + ' is located in '+ body.city + ', ' + body.country + '. Hostname: ' + body.hostname + '. ISP: ' + body.org); + } else { + callback('No info about ' + ip); + } + ips[ip] = body; + }); + } + }.bind(this) + }; + var commands = { '~lookup': function(event) { domain = event.params[1]; @@ -36,21 +57,7 @@ var dns = function(dbot) { '~geoip': function(event) { var ip = event.params[1]; - if(_.has(ips, ip)) { - body = ips[ip]; - event.reply(ip + ' is located in '+ body.city + ', ' + body.country + '. Hostname: ' + body.hostname + '. ISP: ' + body.org); - } else { - request.get('http://ipinfo.io/'+ip, { - 'json': true - }, function(err, res, body) { - if(!err && body) { - event.reply(ip + ' is located in '+ body.city + ', ' + body.country + '. Hostname: ' + body.hostname + '. ISP: ' + body.org); - } else { - event.reply('No info about ' + ip); - } - ips[ip] = body; - }); - } + this.api.getGeoIp(ip, function(result) { event.reply(result); }); }, '~dnsbl': function(event) {