diff --git a/commands/water.py b/commands/water.py new file mode 100644 index 0000000..44534bf --- /dev/null +++ b/commands/water.py @@ -0,0 +1,28 @@ +import plugin, os.path, json + +def water(user): + 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="cosmicbot")) + with open(os.path.expanduser("~{}/.botany/visitors.json".format(user)),"w") as f: + json.dump(visitors,f,indent=2) + return True # success + except: + return False # failed + +@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!") + else: + bot.say(channel,"Unable to water {user}'s plant; are you sure they have one?") + else: + if 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!") + return + bot.say(channel,"I couldn't figure out which plant was yours. Give me your username as an argument.")