-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweather.lua
39 lines (35 loc) · 1.23 KB
/
weather.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function get_weather(location)
print("Finding weather in ", location)
b, c, h = http.request("http://api.openweathermap.org/data/2.5/weather?q=" .. location .. "&units=metric")
weather = json:decode(b)
print("Weather returns", weather)
local city = weather.name
local country = weather.sys.country
temp = 'The temperature in ' .. city .. ' (' .. country .. ')'
temp = temp .. ' is ' .. weather.main.temp .. '°C'
conditions = 'Current conditions are: ' .. weather.weather[1].description
if weather.weather[1].main == 'Clear' then
conditions = conditions .. ' ☀'
elseif weather.weather[1].main == 'Clouds' then
conditions = conditions .. ' ☁☁'
elseif weather.weather[1].main == 'Rain' then
conditions = conditions .. ' ☔'
elseif weather.weather[1].main == 'Thunderstorm' then
conditions = conditions .. ' ☔☔☔☔'
end
return temp .. '\n' .. conditions
end
function run(msg, matches)
if string.len(matches[1]) > 2 then
city = matches[1]
else
city = "Moscow,RU"
end
return get_weather(city)
end
return {
description = "weather in that city (Madrid is default)",
usage = "!weather (city)",
patterns = {"^!weather(.*)$"},
run = run
}