add support for lowercasing the usernames; there isn't uppercase names, are there?

This commit is contained in:
randomuser 2021-06-23 20:53:53 +00:00
parent 75054c469a
commit 48096c3c6b
1 changed files with 7 additions and 6 deletions

View File

@ -7,8 +7,9 @@ class Botany:
plant = "/home/{}/.botany/{}_plant_data.json" plant = "/home/{}/.botany/{}_plant_data.json"
def __init__(self, user): def __init__(self, user):
self.user = user self.user = user
self.euser = user.lower()
def getVisitors(self): def getVisitors(self):
formatted = self.visitors.format(self.user) formatted = self.visitors.format(self.euser)
try: try:
if os.stat(formatted).st_size > 0: if os.stat(formatted).st_size > 0:
with open(formatted) as fd: with open(formatted) as fd:
@ -20,7 +21,7 @@ class Botany:
return False return False
def insertVisitor(self, data, waterer): def insertVisitor(self, data, waterer):
if data == False: return False if data == False: return False
formatted = self.visitors.format(self.user) formatted = self.visitors.format(self.euser)
data.append({"timestamp": int(time.time()), "user": waterer}) data.append({"timestamp": int(time.time()), "user": waterer})
try: try:
with open(formatted, "w") as fd: with open(formatted, "w") as fd:
@ -33,7 +34,7 @@ class Botany:
print("FileNotFoundError in insertVisitor()") print("FileNotFoundError in insertVisitor()")
return False return False
def getInfo(self): def getInfo(self):
formatted = self.plant.format(self.user, self.user) formatted = self.plant.format(self.euser, self.euser)
try: try:
with open(formatted) as fd: with open(formatted) as fd:
return json.load(fd) return json.load(fd)
@ -48,10 +49,10 @@ class IRCBotany(Botany):
def plantDescription(self): def plantDescription(self):
string = "" string = ""
data = self.getInfo() data = self.getInfo()
if(data == []): return "{}'s invisible plant".format(self.user) if(data == []): return "{}'s invisible plant".format(self.euser)
string += self.user string += self.euser
print(self.user) print(self.euser)
string += "'s " string += "'s "
if(data['is_dead']): string += "dead " if(data['is_dead']): string += "dead "
string += data['description'] string += data['description']