hebdobot/review/aliases.py

32 lines
931 B
Python
Raw Permalink Normal View History

2024-01-11 08:17:25 +01:00
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