From 8fba251b69b313465096bda938eecd0d00127c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20H=C3=B6nig?= Date: Sat, 10 Jun 2017 13:56:00 +0200 Subject: [PATCH] bots: Add `get_config_info` function for bots. --- bots_api/bot_lib.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bots_api/bot_lib.py b/bots_api/bot_lib.py index ddf115c..ecdccea 100644 --- a/bots_api/bot_lib.py +++ b/bots_api/bot_lib.py @@ -7,6 +7,8 @@ import sys import time import re +from six.moves import configparser + if False: from mypy_extensions import NoReturn from typing import Any, Optional, List, Dict @@ -94,6 +96,16 @@ class BotHandlerApi(object): content=response, )) + def get_config_info(self, bot_name, section=None): + # type: (str, Optional[str]) -> Dict[str, Any] + conf_file_path = os.path.realpath(os.path.join( + our_dir, '..', 'bots', bot_name, bot_name + '.conf')) + section = section or bot_name + config = configparser.ConfigParser() + config.read(conf_file_path) + return dict(config.items(section)) + + class StateHandler(object): def __init__(self): # type: () -> None