Compare commits

...

4 Commits

Author SHA1 Message Date
Argy c55849ee36 Updated return value for Failure case 2021-06-23 15:04:08 +00:00
Argy 03bcabfa94 Removed global var 2021-06-23 14:55:15 +00:00
Argy a69878043a Minor global var issue fix 2021-06-18 01:43:10 +00:00
Argy ae48ef5c9f Added plant name in output message 2021-06-18 01:17:51 +00:00
1 changed files with 9 additions and 8 deletions

View File

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