bots: Allow optional config files for bots.

This commit is contained in:
Rohitt Vashishtha 2017-06-17 17:42:58 +05:30 committed by showell
parent ea3dd2bd87
commit c1f3544e33

View file

@ -100,13 +100,18 @@ class ExternalBotHandler(object):
else: else:
self._rate_limit.show_error_and_exit() self._rate_limit.show_error_and_exit()
def get_config_info(self, bot_name, section=None): def get_config_info(self, bot_name, section=None, optional=False):
# type: (str, Optional[str]) -> Dict[str, Any] # type: (str, Optional[str], Optional[bool]) -> Dict[str, Any]
conf_file_path = os.path.realpath(os.path.join( conf_file_path = os.path.realpath(os.path.join(
our_dir, '..', 'bots', bot_name, bot_name + '.conf')) our_dir, '..', 'bots', bot_name, bot_name + '.conf'))
section = section or bot_name section = section or bot_name
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.readfp(open(conf_file_path)) # type: ignore try:
config.readfp(open(conf_file_path)) # type: ignore
except IOError:
if optional:
return dict()
raise
return dict(config.items(section)) return dict(config.items(section))
class StateHandler(object): class StateHandler(object):