Add user nickname to \!weather prefix

This commit is contained in:
Anton McClure 2019-07-03 12:03:48 +00:00
parent 655f00ce84
commit b443202030
No known key found for this signature in database
GPG key ID: 6B7731930DB6DEA9

View file

@ -25,6 +25,7 @@ class Module(ModuleManager.BaseModule):
api_key = self.bot.config["openweathermap-api-key"] api_key = self.bot.config["openweathermap-api-key"]
location = None location = None
nickname = None
if event["args"]: if event["args"]:
if len(event["args_split"]) == 1 and event["server"].has_user_id( if len(event["args_split"]) == 1 and event["server"].has_user_id(
event["args_split"][0]): event["args_split"][0]):
@ -33,8 +34,11 @@ class Module(ModuleManager.BaseModule):
if location == None: if location == None:
raise utils.EventError("%s doesn't have a location set" raise utils.EventError("%s doesn't have a location set"
% target_user.nickname) % target_user.nickname)
else:
nickname = target_user.nickname
else: else:
location = self._user_location(event["user"]) location = self._user_location(event["user"])
nickname = event["user"].nickname
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")
@ -69,6 +73,8 @@ class Module(ModuleManager.BaseModule):
wind_speed_k = "%sKMh" % round(wind_speed, 1) wind_speed_k = "%sKMh" % round(wind_speed, 1)
wind_speed_m = "%sMPh" % round(0.6214*wind_speed, 1) wind_speed_m = "%sMPh" % round(0.6214*wind_speed, 1)
if not nickname == None:
event["stdout"].set_prefix("Weather|%s" % nickname)
event["stdout"].write( event["stdout"].write(
"(%s) %s/%s | %s | Humidity: %s | Wind: %s/%s" % ( "(%s) %s/%s | %s | Humidity: %s | Wind: %s/%s" % (
location_str, celsius, fahrenheit, description, humidity, location_str, celsius, fahrenheit, description, humidity,