This commit is contained in:
Flummi 2019-01-08 08:04:56 +01:00
parent 1897e3c1b5
commit 3bf47324bf

View File

@ -64,7 +64,7 @@ export default bot => {
} }
})); }));
bot._trigger.set("weather", new bot.trigger({ bot._trigger.set("wttrnew", new bot.trigger({
call: /^(\.|\/)w .*/i, call: /^(\.|\/)w .*/i,
set: "all", set: "all",
help: { help: {
@ -72,7 +72,7 @@ export default bot => {
usage: "[b].w[/b] [i]<location>[/i]" usage: "[b].w[/b] [i]<location>[/i]"
}, },
f: e => { f: e => {
const loc = e.message.trim().substring(3); const loc = encodeURIComponent(e.message.trim().substring(3));
const key = cfg.main.owm.val.key; const key = cfg.main.owm.val.key;
const api = `http://api.openweathermap.org/data/2.5/weather?q=${loc}&appid=${key}&units=metric&lang=de`; const api = `http://api.openweathermap.org/data/2.5/weather?q=${loc}&appid=${key}&units=metric&lang=de`;
@ -81,36 +81,70 @@ export default bot => {
.then(res => { .then(res => {
if(res.cod !== 200) if(res.cod !== 200)
return e.reply(res.message); return e.reply(res.message);
const data = [ let data = [];
res.weather[0].description, let icon = "";
`${res.main.temp} °C`,
`${[..."↓↙←↖↑↗→↘"][-~parseInt((res.wind.deg + 22) % 360 / 45)]} ${res.wind.speed} km/h`, if(/^bremen/i.test(loc)) {
"", const temp_min = (res.main.temp_min / Math.PI).toFixed(2);
"" const temp_max = Math.sqrt(res.main.temp_max).toFixed(2);
]; data = [
e.reply(`Wetterbericht für: ${res.name}, ${res.sys.country}\n${[...Array(5)].map((_, i) => `${conds(res.weather[0].id)[i].padEnd(15)} ${data[i]}`).join("\n")}`); "Gewitter mit Hagal",
`${temp_min} * π bis ${temp_max}² °C`,
`${[..."↓↙←↖↑↗→↘"][-~parseInt((res.wind.deg + 22) % 360 / 45)] || ""} ${res.wind.speed} km/h`,
"Mathe macht Spaß,",
"wenn's vorbei ist."
];
icon = conds(202);
}
else {
data = [
res.weather[0].description,
`${res.main.temp_min} - ${res.main.temp_max} °C`,
`${[..."↓↙←↖↑↗→↘"][-~parseInt((res.wind.deg + 22) % 360 / 45)] || ""} ${res.wind.speed} km/h`,
"",
""
];
icon = conds(res.weather[0].id);
}
e.reply(`Wetterbericht für: ${res.name}, ${res.sys.country}\n${[...Array(5)].map((_, i) => `${icon[i].padEnd(15)} ${data[i]}`).join("\n")}`);
}).catch(err => console.log(err)); }).catch(err => console.log(err));
}
}));
bot._trigger.set("weather", new bot.trigger({
call: /^(\.|\/)weather .*/i,
set: "all",
help: {
text: "Gets the weather from OWM",
usage: "[b].weather[/b] [i]<location>[/i]"
},
f: e => {
const loc = encodeURIComponent(e.message.trim().substring(9));
const key = cfg.main.owm.val.key;
const api = `http://api.openweathermap.org/data/2.5/weather?q=${loc}&appid=${key}&units=metric&lang=de`;
/*const url = `https://query.yahooapis.com/v1/public/yql?format=json&q=` fetch(api)
+ `select * from weather.forecast where u="c" and woeid in`
+ `(select woeid from geo.places(1) where text="${encodeURIComponent(loc)}")`;
fetch(url)
.then(res => res.json()) .then(res => res.json())
.then(data => { .then(res => {
if(!data.query.results) if(res.cod !== 200)
return e.reply("Location not found"); return e.reply(res.message);
const res = data.query.results.channel; if(/^bremen/i.test(loc)) {
const location = res.location; const temp = Math.sqrt(res.main.temp).toFixed(2);
const condition = res.item.condition; e.reply(
const units = res.units; `Bremen, DE: `
const wind = res.wind; + `${temp}² °C Schwere Gewitter mit Hagal und Sturzfluten, `
e.reply( + `${[..."↓↙←↖↑↗→↘"][-~parseInt((res.wind.deg + 22) % 360 / 45)] || ""} ${res.wind.speed} km/h`
`${location.city}, ${location.region.trim()}, ${location.country}: ` );
+ `${condition.temp}°${units.temperature} ${condition.text}, ` }
+ `${[...'↑↗→↘↓↙←↖'][-~(parseInt(wind.direction) / 45) % 8]} ${wind.speed} ${units.speed}` else {
); e.reply(
}).catch(err => console.log(err));*/ `${res.name}, ${res.sys.country}: `
+ `${res.main.temp}°C ${res.weather[0].description}, `
+ `${[..."↓↙←↖↑↗→↘"][-~parseInt((res.wind.deg + 22) % 360 / 45)] || ""} ${res.wind.speed} km/h`
);
}
}).catch(err => e.reply(err));
} }
})); }));
}; };