cosmicbot/commands/water.py

29 lines
946 B
Python
Raw Normal View History

2021-06-15 01:18:58 +00:00
import plugin, os.path, json
def water(user):
2021-06-15 01:21:03 +00:00
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)
2021-06-15 01:18:58 +00:00
return True # success
2021-06-15 01:21:03 +00:00
except:
2021-06-15 01:18:58 +00:00
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:
2021-06-15 01:22:12 +00:00
bot.say(channel,f"Unable to water {user}'s plant; are you sure they have one?")
2021-06-15 01:18:58 +00:00
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.")