bitbot-3.11-fork/src/Config.py

23 lines
662 B
Python
Raw Normal View History

import configparser, os
2016-03-29 11:56:58 +00:00
class Config(object):
def __init__(self, location):
self.location = location
2018-09-28 15:51:36 +00:00
self._config = {}
self.load()
2016-03-29 11:56:58 +00:00
2018-09-28 15:51:36 +00:00
def load(self):
if os.path.isfile(self.location):
with open(self.location) as config_file:
parser = configparser.ConfigParser()
parser.read_string(config_file.read())
2018-09-28 15:51:36 +00:00
self._config = dict(parser["bot"].items())
def __getitem__(self, key):
return self._config[key]
def get(self, key, default=None):
return self._config.get(key, default)
def __contains__(self, key):
return key in self._config
2018-09-28 15:51:36 +00:00