wttr
This commit is contained in:
		| @@ -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 = []; | ||||||
|  |           let icon = ""; | ||||||
|  |  | ||||||
|  |           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 = [ | ||||||
|  |               "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.weather[0].description, | ||||||
|             `${res.main.temp} °C`, |               `${res.main.temp_min} - ${res.main.temp_max} °C`, | ||||||
|             `${[..."↓↙←↖↑↗→↘"][-~parseInt((res.wind.deg + 22) % 360 / 45)]} ${res.wind.speed} km/h`, |               `${[..."↓↙←↖↑↗→↘"][-~parseInt((res.wind.deg + 22) % 360 / 45)] || ""} ${res.wind.speed} km/h`, | ||||||
|               "", |               "", | ||||||
|               "" |               "" | ||||||
|             ]; |             ]; | ||||||
|           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")}`); |             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; |  | ||||||
|           const units = res.units; |  | ||||||
|           const wind = res.wind; |  | ||||||
|             e.reply( |             e.reply( | ||||||
|               `${location.city}, ${location.region.trim()}, ${location.country}: ` |                 `Bremen, DE: ` | ||||||
|             + `${condition.temp}°${units.temperature} ${condition.text}, ` |               + `${temp}² °C Schwere Gewitter mit Hagal und Sturzfluten, ` | ||||||
|             + `${[...'↑↗→↘↓↙←↖'][-~(parseInt(wind.direction) / 45) % 8]} ${wind.speed} ${units.speed}` |               + `${[..."↓↙←↖↑↗→↘"][-~parseInt((res.wind.deg + 22) % 360 / 45)] || ""} ${res.wind.speed} km/h` | ||||||
|             ); |             ); | ||||||
|         }).catch(err => console.log(err));*/ |           } | ||||||
|  |           else { | ||||||
|  |             e.reply( | ||||||
|  |                 `${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)); | ||||||
|     } |     } | ||||||
|   })); |   })); | ||||||
| }; | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user