From 1cf36069c7de8468283aed6f6d322fc6bf0953a4 Mon Sep 17 00:00:00 2001 From: Argy Date: Wed, 23 Jun 2021 16:53:47 +0000 Subject: [PATCH] Added plant name in output message (#7) Co-authored-by: aphelion Co-authored-by: Arghyadeep Reviewed-on: https://tildegit.org/khuxkm/cosmicbot/pulls/7 Co-authored-by: Argy Co-committed-by: Argy --- commands/water.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/commands/water.py b/commands/water.py index 0d7b79a..2eb1668 100644 --- a/commands/water.py +++ b/commands/water.py @@ -7,22 +7,23 @@ def water(user): visitors.append(dict(timestamp=int(time.time()),user="cosmicbot")) with open(os.path.expanduser("~{}/.botany/visitors.json".format(user)),"w") as f: json.dump(visitors,f,indent=2) - return True # success + with open(os.path.expanduser("~{}/.botany/{}_plant_data.json".format(user,user))) as f: + return json.load(f)['description'] # Success except: - return False # failed + return False # Failure @plugin.command("water") def cmd_water(bot,channel,nick,user=None): if user is not None: - if water(user): - bot.say(channel,f"Watered {user}'s plant!") + if plant := water(user): + bot.say(channel,f"Watered {user}'s {plant}!") else: bot.say(channel,f"Unable to water {user}'s plant; are you sure they have one?") else: - if water(nick): - bot.say(channel,f"Watered {nick}'s plant!") + if plant := water(nick): + bot.say(channel,f"Watered {nick}'s {plant}!") return - if water(bot.event.source.user): - bot.say(channel,f"Watered {bot.event.source.user}'s plant!") + if plant := water(bot.event.source.user): + bot.say(channel,f"Watered {bot.event.source.user}'s {plant}!") return bot.say(channel,"I couldn't figure out which plant was yours. Give me your username as an argument.")