nxy_weather

This commit is contained in:
Flummi 2017-11-28 19:50:05 +01:00
parent 31985a96f2
commit 6000593dbc

View File

@ -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);
});
}
}));
};