import plugin, os.path, json, time def water(user,by="cosmicbot"): try: with open(os.path.expanduser("~{}/.botany/visitors.json".format(user))) as f: visitors = json.load(f) visitors.append(dict(timestamp=int(time.time()),user=by)) with open(os.path.expanduser("~{}/.botany/visitors.json".format(user)),"w") as f: json.dump(visitors,f,indent=2) with open(os.path.expanduser("~{}/.botany/{}_plant_data.json".format(user,user))) as f: return json.load(f)['description'] # Success except: return False # Failure @plugin.command("water") def cmd_water(bot,channel,nick,user=None): if user is not None: if plant := water(user,nick): 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 plant := water(nick): bot.say(channel,f"Watered _{nick}_'s {plant}!") return 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.")