Beispiel #1
0
def test_merge_dict():
    a = {"a": 1, "b": [2, 3], "c": {"x": 1, "y": [2, 3], "z": {}}}
    b_ok = {"a": 1, "b": [2, 3], "c": {"x": 1, "y": [2, 3], "z": {}}}
    c_ok = {"a": 1, "b": [4, 5], "c": {"x": 1, "y": [2, 3], "z": {}}}

    b = {}
    b = merge_dict(b, a)
    assert b == b_ok

    c = {"b": [4, 5], "c": {"x": 1}}
    c = merge_dict(c, a)
    assert c == c_ok
Beispiel #2
0
    def _configure(self):
        """
        Configure the core of sirbot

        Merge the config with the default core config and configure logging.
        The default logging level is `INFO`
        """
        path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            'config.yml')

        with open(path) as file:
            defaultconfig = yaml.load(file)

        self.config = merge_dict(self.config, defaultconfig)

        if 'logging' in self.config:
            logging.config.dictConfig(self.config['logging'])
        else:
            logging.getLogger('sirbot').setLevel('INFO')
Beispiel #3
0
    def _configure(self) -> None:
        """
        Configure Sirbot

        :return: None
        """

        path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            'config.yml')

        with open(path) as file:
            defaultconfig = yaml.load(file)

        self.config = merge_dict(self.config, defaultconfig)

        if 'logging' in self.config:
            logging.config.dictConfig(self.config['logging'])
        else:
            logging.getLogger('sirbot').setLevel('INFO')
Beispiel #4
0
    async def configure(self, config, router, session):

        path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            'config.yml')

        with open(path) as file:
            defaultconfig = yaml.load(file)

        self._config = merge_dict(config, defaultconfig[self.__name__])
        self._connection = sqlite3.connect(self._config['file'])
        self._connection.row_factory = sqlite3.Row

        db = self._connection.cursor()
        db.execute('''
                   CREATE TABLE IF NOT EXISTS metadata
                   (
                   plugin TEXT PRIMARY KEY,
                   version TEXT
                   )
                   ''')
        self._connection.commit()
Beispiel #5
0
    async def configure(self, config, router, session):
        logger.debug('Configuring github plugin')

        self._verification = os.environ.get('SIRBOT_GITHUB_SECRET')
        if not self._verification:
            raise GitHubSetupError('SIRBOT_GITHUB_SECRET NOT SET')

        path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..',
                            'config.yml')

        with open(path) as file:
            defaultconfig = yaml.load(file)

        self._config = merge_dict(config, defaultconfig[self.__name__])
        self._session = session
        self._http_router = router
        self._github_router = routing.Router()

        logger.debug('Adding github endpoint: %s', self._config['endpoint'])
        self._http_router.add_route('POST', self._config['endpoint'],
                                    self._dispatch)

        self._started = True
Beispiel #6
0
    async def configure(self, config, router, session, registry):
        logger.debug('Configuring slack plugin')
        path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            'config.yml')

        with open(path) as file:
            defaultconfig = yaml.load(file)

        self._config = merge_dict(config, defaultconfig[self.__name__])

        self._router = router
        self._session = session
        self._registry = registry

        self._bot_token = os.environ.get('SIRBOT_SLACK_BOT_TOKEN', '')
        self._app_token = os.environ.get('SIRBOT_SLACK_TOKEN', '')
        self._verification_token = os.environ.get(
            'SIRBOT_SLACK_VERIFICATION_TOKEN')

        if 'database' not in self._registry:
            raise SlackSetupError('A database is required')

        if not self._bot_token and not self._app_token:
            raise SlackSetupError(
                'One of SIRBOT_SLACK_BOT_TOKEN or SIRBOT_SLACK_TOKEN'
                ' must be set')

        if self._config['rtm'] and not self._bot_token:
            raise SlackSetupError('SIRBOT_SLACK_BOT_TOKEN must be set to use'
                                  'the rtm API')

        if self._app_token and not self._verification_token:
            raise SlackSetupError(
                'SIRBOT_SLACK_VERIFICATION_TOKEN must be set')

        self._http_client = HTTPClient(bot_token=self._bot_token,
                                       app_token=self._app_token,
                                       loop=self._loop,
                                       session=self._session)

        self._users = UserStore(client=self._http_client,
                                registry=self._registry,
                                refresh=self._config['refresh']['user'])

        self._channels = ChannelStore(
            client=self._http_client,
            registry=self._registry,
            refresh=self._config['refresh']['channel'])

        self._groups = GroupStore(client=self._http_client,
                                  registry=self._registry,
                                  refresh=self._config['refresh']['group'])

        self._messages = MessageStore(client=self._http_client,
                                      registry=self._registry)

        if self._config['rtm'] or self._config['endpoints']['events']:
            logger.debug('Adding events endpoint: %s',
                         self._config['endpoints']['events'])

            self._dispatcher['message'] = MessageDispatcher(
                http_client=self._http_client,
                users=self._users,
                channels=self._channels,
                groups=self._groups,
                plugins=self._pm,
                registry=self._registry,
                save=self._config['save']['messages'],
                ping=self._config['ping'],
                loop=self._loop,
                threads=self._threads)

            self._dispatcher['event'] = EventDispatcher(
                http_client=self._http_client,
                users=self._users,
                channels=self._channels,
                groups=self._groups,
                plugins=self._pm,
                registry=self._registry,
                loop=self._loop,
                message_dispatcher=self._dispatcher['message'],
                event_save=self._config['save']['events'],
                token=self._verification_token)

            if self._config['rtm']:
                self._rtm_client = RTMClient(bot_token=self._bot_token,
                                             loop=self._loop,
                                             callback=self._incoming_rtm,
                                             session=self._session)

            if self._config['endpoints']['events']:
                self._router.add_route('POST',
                                       self._config['endpoints']['events'],
                                       self._dispatcher['event'].incoming_web)

        if self._config['endpoints']['actions']:
            logger.debug('Adding actions endpoint: %s',
                         self._config['endpoints']['actions'])
            self._dispatcher['action'] = ActionDispatcher(
                http_client=self._http_client,
                users=self._users,
                channels=self._channels,
                groups=self._groups,
                plugins=self._pm,
                registry=self._registry,
                loop=self._loop,
                save=self._config['save']['actions'],
                token=self._verification_token)

            self._router.add_route('POST',
                                   self._config['endpoints']['actions'],
                                   self._dispatcher['action'].incoming)

        if self._config['endpoints']['commands']:
            logger.debug('Adding commands endpoint: %s',
                         self._config['endpoints']['commands'])
            self._dispatcher['command'] = CommandDispatcher(
                http_client=self._http_client,
                users=self._users,
                channels=self._channels,
                groups=self._groups,
                plugins=self._pm,
                registry=self._registry,
                loop=self._loop,
                save=self._config['save']['commands'],
                token=self._verification_token)
            self._router.add_route('POST',
                                   self._config['endpoints']['commands'],
                                   self._dispatcher['command'].incoming)