def get_config_info(self, bot_name, optional=False):
# type: (str, Optional[bool]) -> Dict[str, Any]
if self.bot_config_file is None:
if optional:
return dict()
# Well written bots should catch this exception
# and provide nice error messages with instructions
# on setting up the configuration specfic to this bot.
# And then `run.py` should also catch exceptions on how
# to specify the file in the command line.
raise NoBotConfigException(bot_name)
if bot_name not in self.bot_config_file:
print('''
WARNING!
{} does not adhere to the
file naming convention, and it could be a
sign that you passed in the
wrong third-party configuration file.
The suggested name is {}.conf
We will proceed anyway.
'''.format(self.bot_config_file, bot_name))
# We expect the caller to pass in None if the user does
# not specify a bot_config_file. If they pass in a bogus
# filename, we'll let an IOError happen here. Callers
# like `run.py` will do the command line parsing and checking
# for the existence of the file.
config = configparser.ConfigParser()
with open(self.bot_config_file) as conf:
try:
config.readfp(conf) # type: ignore # readfp->read_file in python 3, so not in stubs
except configparser.Error as e:
display_config_file_errors(str(e), self.bot_config_file)
sys.exit(1)
return dict(config.items(bot_name))
评论列表
文章目录