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,20 +21,28 @@ class Module(ModuleManager.BaseModule):
location = None location = None
if event["args"]: if event["args"]:
target_user = event["server"].get_user(event["args_split"][0]) if len(event["args_split"]) == 1 and event["server"].has_user_id(
location = self._user_location(target_user) event["args_split"][0]):
if location == None: target_user = event["server"].get_user(event["args_split"][0])
raise utils.EventError("%s doesn't have a location set" location = self._user_location(target_user)
% target_user.nickname) if location == None:
raise utils.EventError("%s doesn't have a location set"
% target_user.nickname)
else: else:
location = self._user_location(event["user"]) location = self._user_location(event["user"])
if location == None: if location == None:
raise utils.EventError("You don't have a location set") raise utils.EventError("You don't have a location set")
lat, lon = location args = {"units": "metric", "APPID": api_key}
page = utils.http.request(URL_WEATHER, get_params={
"units": "metric", "lat": lat, "lon": lon, "APPID": api_key}, if location:
json=True) lat, lon = location
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 page:
if "weather" in page.data: if "weather" in page.data:
location = "%s, %s" % (page.data["name"], page.data["sys"][ location = "%s, %s" % (page.data["name"], page.data["sys"][