How to use the ehforwarderbot.utils.get_config_path function in ehforwarderbot

To help you get started, we’ve selected a few ehforwarderbot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github blueset / ehForwarderBot / tests / test_channel_loading.py View on Github external
def dump_and_load_config(config):
    config_path = ehforwarderbot.utils.get_config_path()
    with config_path.open('w') as f:
        yaml.dump(config, f)
    return ehforwarderbot.config.load_config()
github blueset / efb-telegram-master / efb_telegram_master / __init__.py View on Github external
def load_config(self):
        """
        Load configuration from path specified by the framework.

        Configuration file is in YAML format.
        """
        config_path = efb_utils.get_config_path(self.channel_id)
        if not config_path.exists():
            raise FileNotFoundError(self._("Config File does not exist. ({path})").format(path=config_path))
        with config_path.open() as f:
            data = YAML().load(f)

            # Verify configuration
            if not isinstance(data.get('token', None), str):
                raise ValueError(self._('Telegram bot token must be a string'))
            if isinstance(data.get('admins', None), int):
                data['admins'] = [data['admins']]
            if isinstance(data.get('admins', None), str) and data['admins'].isdigit():
                data['admins'] = [int(data['admins'])]
            if not isinstance(data.get('admins', None), list) or not data['admins']:
                raise ValueError(self._("Admins' user IDs must be a list of one number or more."))
            for i in range(len(data['admins'])):
                if isinstance(data['admins'][i], str) and data['admins'][i].isdigit():
github blueset / ehForwarderBot / ehforwarderbot / config.py View on Github external
def load_config() -> Dict[str, Any]:
    _ = coordinator.translator.gettext
    # Include custom channels
    custom_channel_path = str(utils.get_custom_modules_path())
    if custom_channel_path not in sys.path:
        sys.path.insert(0, custom_channel_path)

    conf_path = utils.get_config_path()
    if not conf_path.exists():
        raise FileNotFoundError(_("Config File does not exist. ({})").format(conf_path))
    with conf_path.open() as f:
        data: Dict[str, Any] = OPTIONAL_DEFAULTS.copy()
        data.update(YAML().load(f))

        # Verify configuration

        # - Master channel
        master_channel_id = data.get("master_channel", None)
        if not master_channel_id:
            raise ValueError(_("Master Channel is not specified in the profile config."))
        elif not isinstance(master_channel_id, str):
            raise ValueError(_("Master Channel ID is expected to be a string, but "
                               "\"{0}\" is of type {1}.").format(master_channel_id, type(master_channel_id)))
        channel = utils.locate_module(data['master_channel'], 'master')
github blueset / efb-wechat-slave / efb_wechat_slave / wizard.py View on Github external
def __init__(self, profile: str, instance_id: str):
        coordinator.profile = profile
        self.profile = profile
        self.instance_id = instance_id
        self.channel_id = WeChatChannel.channel_id
        if instance_id:
            self.channel_id = ModuleID(self.channel_id + "#" + instance_id)
        self.config_path = utils.get_config_path(self.channel_id)
        self.yaml = YAML()
        if not self.config_path.exists():
            self.build_default_config()
        else:
            self.data = self.yaml.load(self.config_path.open())
github zhangzhishan / efb-filter-middleware / efb_filter_middleware / __init__.py View on Github external
def process_message(self, message: EFBMsg) -> Optional[EFBMsg]:
        config = yaml.load(open(utils.get_config_path(self.middleware_id), encoding ="UTF-8"))
        if message.author.is_self:
            return message
        if self.config_version != config.get('version'):
            self.logger.debug("config changed!")
            self.config_version = config.get('version')
            self.work_modes = config.get('work_mode')
        for work_mode in WorkMode:
            # print(self.work_modes)
            # print(work_mode.value)
            if work_mode.value in self.work_modes:
                # print(config.get(work_mode.value))
                if config.get(work_mode.value) and self.is_keep_message(work_mode, message, config.get(work_mode.value)):
                    return message