Query weather for given args if they don't look like a user

This commit is contained in:
jesopo 2019-05-05 00:16:55 +01:00
parent 920dce0221
commit f04d9d966e

View file

@ -21,6 +21,8 @@ class Module(ModuleManager.BaseModule):
location = None
if event["args"]:
if len(event["args_split"]) == 1 and event["server"].has_user_id(
event["args_split"][0]):
target_user = event["server"].get_user(event["args_split"][0])
location = self._user_location(target_user)
if location == None:
@ -31,10 +33,16 @@ class Module(ModuleManager.BaseModule):
if location == None:
raise utils.EventError("You don't have a location set")
args = {"units": "metric", "APPID": api_key}
if location:
lat, lon = location
page = utils.http.request(URL_WEATHER, get_params={
"units": "metric", "lat": lat, "lon": lon, "APPID": api_key},
json=True)
args["lat"] = lat
args["lon"] = lon
else:
args["q"] = event["args"]
page = utils.http.request(URL_WEATHER, get_params=args, json=True)
if page:
if "weather" in page.data:
location = "%s, %s" % (page.data["name"], page.data["sys"][