예제 #1
0
 def __init__(self, plugin_actions, settings=None):
     self._client = Slack()
     self._plugin_actions = plugin_actions
     self._pool = ThreadPool()
     alias_regex = ''
     if settings and "ALIASES" in settings:
         logger.info("Setting aliases to {}".format(settings['ALIASES']))
         alias_regex = '|(?P<alias>{})'.format(
             '|'.join([re.escape(s) for s in settings['ALIASES'].split(',')]))
     self.RESPOND_MATCHER = re.compile(
         r"^(?:<@(?P<atuser>\w+)>:?|(?P<username>\w+):{}) ?(?P<text>.*)$".format(
             alias_regex
         ),
         re.DOTALL,
     )
예제 #2
0
파일: core.py 프로젝트: bvujnovac/breakbot
    def __init__(self, settings=None):
        announce("Initializing Slack Machine:")

        with indent(4):
            puts("Loading settings...")
            if settings:
                self._settings = settings
                found_local_settings = True
            else:
                self._settings, found_local_settings = import_settings()
            fmt = '[%(asctime)s][%(levelname)s] %(name)s %(filename)s:%(funcName)s:%(lineno)d |' \
                  ' %(message)s'
            date_fmt = '%Y-%m-%d %H:%M:%S'
            log_level = self._settings.get('LOGLEVEL', logging.ERROR)
            logging.basicConfig(
                level=log_level,
                format=fmt,
                datefmt=date_fmt,
            )
            if not found_local_settings:
                warn(
                    "No local_settings found! Are you sure this is what you want?"
                )
            if 'SLACK_API_TOKEN' not in self._settings:
                error(
                    "No SLACK_API_TOKEN found in settings! I need that to work..."
                )
                sys.exit(1)
            self._client = Slack()
            puts("Initializing storage using backend: {}".format(
                self._settings['STORAGE_BACKEND']))
            self._storage = Storage.get_instance()
            logger.debug("Storage initialized!")

            self._plugin_actions = {
                'process': {},
                'listen_to': {},
                'respond_to': {},
                'catch_all': {}
            }
            self._help = {'human': {}, 'robot': {}}
            puts("Loading plugins...")
            self.load_plugins()
            logger.debug("The following plugin actions were registered: %s",
                         self._plugin_actions)
            self._dispatcher = EventDispatcher(self._plugin_actions,
                                               self._settings)
예제 #3
0
 def __init__(self, plugin_actions):
     self._client = Slack()
     self._plugin_actions = plugin_actions
     self._pool = ThreadPool()