From 1d10ed86e6bc6bd1af086621382d1bd557d24dad Mon Sep 17 00:00:00 2001 From: reality Date: Wed, 28 Jan 2015 06:16:17 +0000 Subject: [PATCH] weather --- modules/weather/weather.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 modules/weather/weather.js diff --git a/modules/weather/weather.js b/modules/weather/weather.js new file mode 100644 index 0000000..7310f38 --- /dev/null +++ b/modules/weather/weather.js @@ -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); +};