mirror of
https://github.com/reality/dbot.git
synced 2024-11-27 14:29:29 +01:00
r2rio
This commit is contained in:
parent
0a6f1bd82a
commit
b2188ea036
3
modules/r2rio/config.json
Normal file
3
modules/r2rio/config.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"api_key": ""
|
||||
}
|
42
modules/r2rio/r2rio.js
Normal file
42
modules/r2rio/r2rio.js
Normal file
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Module Name: rome2rio
|
||||
* Description: Maps and ting
|
||||
*/
|
||||
var request = require('request'),
|
||||
_ = require('underscore')._;
|
||||
|
||||
var gmaps = function(dbot) {
|
||||
this.ApiRoot = 'http://free.rome2rio.com/api/1.2/json/';
|
||||
this.commands = {
|
||||
'~from': function(event) {
|
||||
var from = event.input[1],
|
||||
to = event.input[2];
|
||||
|
||||
request.get({
|
||||
'url': this.ApiRoot + 'Search',
|
||||
'qs': {
|
||||
'key': this.config.api_key,
|
||||
'oName': from,
|
||||
'dName': to,
|
||||
'currencyCode': 'GBP'
|
||||
},
|
||||
'json': true
|
||||
}, function(err, response, body) {
|
||||
if(!err && body && _.has(body, 'routes')) {
|
||||
var route = body.routes[0];
|
||||
event.reply('If you left right now, it would take you ' + Math.floor(route.duration / 60) + ' hours and ' +
|
||||
(route.duration % 60) + ' minutes to get the ' + Math.floor(route.distance) + 'KM from ' + from + ' to ' + to + ', and cost you about £' +
|
||||
route.indicativePrice.price);
|
||||
} else {
|
||||
event.reply('Apparently one cannot get from ' + from + ' to ' + to + ' using public transport. Do you accept the challenge?');
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
this.commands['~from'].regex = [/^from (.*) to (.*)/, 3];
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return new gmaps(dbot);
|
||||
};
|
Loading…
Reference in New Issue
Block a user