Add first draft of water command

This commit is contained in:
Robert Miles 2021-06-15 01:18:58 +00:00
parent 3fbfc5ce93
commit 3529f9c5f4
1 changed files with 28 additions and 0 deletions

28
commands/water.py Normal file
View File

@ -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.")