from datetime import datetime class Aliases: def __init__(self, filepath): self.filepath = filepath self.users = {} self.load() def __getitem__(self, key): if key in self.users: return self.users[key] else: try: index = [key.lower() for key in self.users].index(key.lower()) return self.users[list(self.users.keys())[index]] except ValueError: # key really not found pass return key def load(self): with open(self.filepath) as file_handle: lines = file_handle.read().splitlines() for line in lines: if line.strip() != "" and not line.startswith("#"): datas = line.split("=") real_name = datas[0] for nick in datas[1].split(","): self.users[nick] = real_name