From 6000593dbc96e9dc8b6a8b6013fc1845e9a248c7 Mon Sep 17 00:00:00 2001 From: Flummi Date: Tue, 28 Nov 2017 19:50:05 +0100 Subject: [PATCH] nxy_weather --- src/inc/trigger/wttr.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/inc/trigger/wttr.js b/src/inc/trigger/wttr.js index 3b310cf..3d2a05a 100644 --- a/src/inc/trigger/wttr.js +++ b/src/inc/trigger/wttr.js @@ -3,8 +3,6 @@ const rp = require("request-promise"); module.exports = bot => { bot._trigger.set("wttr", new bot.trigger({ call: /^\.wttr .*/i, - level: 0, - active: true, clients: ["irc"], f: e => { let args = e.message.trim().substring(6); @@ -59,4 +57,31 @@ module.exports = bot => { }); } })); + + bot._trigger.set("weather", new bot.trigger({ + call: /^(\.|\/)weather .*/i, + f: e => { + const loc = e.message.trim().substring(9); + const url = `https://query.yahooapis.com/v1/public/yql?format=json&q=` + + `select * from weather.forecast where u="c" and woeid in` + + `(select woeid from geo.places(1) where text="${encodeURIComponent(loc)}")`; + rp(url, { json: true }).then(data => { + if(!data.query.results) + return e.reply("Location not found"); + const res = data.query.results.channel; + const location = res.location; + const condition = res.item.condition; + const units = res.units; + const wind = res.wind; + e.reply( + `${location.city}, ${location.region.trim()}, ${location.country}: ` + + `${condition.temp}°${units.temperature} ${condition.text}, ` + + `${[...'↑↗→↘↓↙←↖'][-~(parseInt(wind.direction) / 45) % 8]} ${wind.speed} ${units.speed}` + ); + }) + .catch(err => { + console.log(err); + }); + } + })); }; \ No newline at end of file