Пример #1
0
def run(config, debug, no_cache):
    # noinspection PyArgumentList
    logging.basicConfig(handlers=[InterceptHandler()], level=0)

    logger.remove()
    logger.enable("discord_chan")
    logger.add(sys.stderr, level="INFO", filter="discord_chan")
    logger.add(sys.stderr, level="ERROR", filter="discord")

    config = ConfigBox(config_dict(config))

    if not config.enviroment.bool("disable"):
        load_environ(
            **dict([var for var in config.enviroment.items() if var[0] != "disable"])
        )

    if debug:
        asyncio.get_event_loop().set_debug(True)
        logging.getLogger("asyncio").setLevel(logging.DEBUG)

    kwargs = {}
    if no_cache:
        kwargs["guild_subscriptions"] = False
        kwargs["fetch_offline_members"] = False

    bot = discord_chan.DiscordChan(config, **kwargs)

    # Todo: make sure to remove this debug call
    # bot.dispatch('ready')

    loop = asyncio.get_event_loop()
    with start_monitor(
        loop, monitor=discord_chan.DiscordChanMonitor, locals={"bot": bot}
    ):
        bot.run()
Пример #2
0
 def __init__(self):
     # Recover configs
     config = reusables.config_dict("config.ini")
     self.name_device_a = config["device_a"]["name"]
     self.name_device_b = config["device_b"]["name"]
     self.icon_device_a = config["device_a"]["icon"]
     self.icon_device_b = config["device_b"]["icon"]
Пример #3
0
 def read_file(file_path: str, bootstrap: bool = False) -> Dict:
     """Read the given file and parse and return raw settings from it."""
     config = {"mod_fix_settings": {}}
     settings = ConfigBox(reusables.config_dict(file_path))
     # extract bat settings
     config["bat"] = settings.bat.to_dict()
     # extract arma config settings
     config["config"] = settings.config.to_dict()
     # fix list element in odksm settings
     for el in [
             "user_mods_list", "mods_to_be_copied", "server_mods_list",
             "skip_keys"
     ]:
         if el in settings.ODKSM:
             el_list = settings.ODKSM.list(el)
             settings.ODKSM[el] = list(filter(lambda x: x != "", el_list))
     # now save the odksm section
     config["ODKSM"] = settings.ODKSM.to_dict()
     # check for mod fixes
     config["mod_fix_settings"] = settings.mod_fix_settings.to_dict()
     if "enabled_fixes" in settings.mod_fix_settings:
         config["mod_fix_settings"][
             "enabled_fixes"] = settings.mod_fix_settings.list(
                 "enabled_fixes")
     if bootstrap:
         config["bootstrap"] = settings.bootstrap.to_dict()
     return config
Пример #4
0
 def test_get_config_dict_multiple(self):
     resp = reusables.config_dict(
         [os.path.join(test_root, 'test_config.cfg')])
     assert resp == {
         'Section1': {
             'key 1': 'value 1',
             'key2': 'Value2'
         },
         'Section 2': {}
     }, resp
Пример #5
0
 def test_get_config_dict_no_verify(self):
     resp = reusables.config_dict('bad_loc.cfg', verify=False)
     assert resp == {}, resp
Пример #6
0
 def test_get_config_dict_auto(self):
     resp = reusables.config_dict(auto_find=test_root)
     assert resp.get('Section1') == {
         'key 1': 'value 1',
         'key2': 'Value2'
     }, resp.get('Section1')
Пример #7
0
 def test_get_config_dict(self):
     resp = reusables.config_dict(os.path.join(test_root,
                                               'test_config.cfg'))
     assert resp['Section1']['key 1'] == 'value 1'
     assert resp['Section 2'] == {}
Пример #8
0
 def test_get_config_dict_multiple(self):
     resp = reusables.config_dict([os.path.join(test_root, 'test_config.cfg')])
     assert resp == {'Section1': {'key 1': 'value 1', 'key2': 'Value2'}, 'Section 2': {}}, resp
Пример #9
0
 def test_get_config_dict_no_verify(self):
     resp = reusables.config_dict('bad_loc.cfg', verify=False)
     assert resp == {}, resp
Пример #10
0
 def test_get_config_dict_auto(self):
     resp = reusables.config_dict(auto_find=test_root)
     assert resp.get('Section1') == {'key 1': 'value 1', 'key2': 'Value2'}, resp.get('Section1')
Пример #11
0
 def test_get_config_dict(self):
     resp = reusables.config_dict(os.path.join(test_root, 'test_config.cfg'))
     assert resp['Section1']['key 1'] == 'value 1'
     assert resp['Section 2'] == {}