mirror of
https://github.com/reality/dbot.git
synced 2024-11-23 20:39:25 +01:00
weather
This commit is contained in:
parent
ff342bc932
commit
1d10ed86e6
35
modules/weather/weather.js
Normal file
35
modules/weather/weather.js
Normal file
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Module Name: weather
|
||||
* Description: weather and ting
|
||||
*/
|
||||
var request = require('request'),
|
||||
_ = require('underscore')._;
|
||||
|
||||
var weather = function(dbot) {
|
||||
this.ApiRoot = 'http://api.openweathermap.org/data/2.5/';
|
||||
this.commands = {
|
||||
'~weather': function(event) {
|
||||
var city = event.input[1];
|
||||
|
||||
request.get({
|
||||
'url': this.ApiRoot + 'weather',
|
||||
'qs': {
|
||||
'q': city,
|
||||
'units': 'metric'
|
||||
},
|
||||
'json': true
|
||||
}, function(err, response, body) {
|
||||
if(!err && body && _.has(body, 'cod') && body.cod === 200) {
|
||||
event.reply('Weather in ' + city + ': Temp: ' + body.main.temp + 'C Condition: ' + body.weather[0].description);
|
||||
} else {
|
||||
event.reply('There is no weather in ' + city);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
this.commands['~weather'].regex = [/^weather (.*)/, 2];
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return new weather(dbot);
|
||||
};
|
Loading…
Reference in New Issue
Block a user