Esempio n. 1
0
    def __init__(self, messaging, prompt=None):

        super().__init__()
        if SubprocessManager is not None:
            self.subprocess_manager = SubprocessManager()
        else:
            self.subprocess_manager = None

        cache_dir = get_cache_dir()
        mkdir = not path.isdir(cache_dir)
        if mkdir:
            os.makedirs(cache_dir, exist_ok=True)

        filepath = get_cache(__name__ + '.pickle')
        init = not path.isfile(filepath)

        # NOTE: The `u` means: Do not lock the database.
        # This can easily corrupt the database
        self._config = shelve.open(filepath, flag='cu', writeback=True)

        if init:
            self._config['extensions'] = {}
            self._config['disabled'] = {}
            self._config['modules'] = {}

        self._prompt = prompt
        self.messaging = messaging
        # Get the root logger to set it to different levels
        self.root_logger = logging.getLogger()
        self.logger = logging.getLogger(__name__)

        self._bot_callback = None
        self._no_bot_callback = None
        self._commands = {}
        self.init_commands()
Esempio n. 2
0
    def __init__(self, configuration, bot_name="vex"):
        # get the settings path and then load the settings from file
        settings_path = configuration.get('settings_path')
        settings = configuration.load_settings(settings_path)
        self.messaging = Messaging(settings)

        # create the plugin manager
        self.plugin_manager = pluginmanager.PluginInterface()
        # add the entry points of interest
        self.plugin_manager.add_entry_points(
            ('vexbot.plugins', 'vexbot.adapters'))

        # create the subprocess manager and add in the plugins
        self.subprocess_manager = SubprocessManager()
        self._update_plugins(settings, self.subprocess_manager,
                             self.plugin_manager)

        subprocesses_to_start = settings.get('startup_adapters', [])
        subprocesses_to_start.extend(settings.get('startup_plugins', []))
        self.subprocess_manager.start(subprocesses_to_start)

        self.name = bot_name
        self._logger = logging.getLogger(__name__)
        self.command_manager = BotCommandManager(robot=self)
        try:
            import setproctitle
            setproctitle.setproctitle(bot_name)
        except ImportError:
            pass
Esempio n. 3
0
    def __init__(self,
                 bot_name: str,
                 connection: dict=None,
                 subprocess_manager=None):

        if connection is None:
            connection = _get_default_port_config()

        self.messaging = _Messaging(bot_name, **connection)
        log_name = __name__ if __name__ != '__main__' else 'vexbot.robot'
        self._logger = _logging.getLogger(log_name)
        if subprocess_manager is None and SubprocessManager:
            subprocess_manager = SubprocessManager()
        else:
            err = ('If you would like to use the subporcess manager, please '
                   'run `pip install -e .[process_manager]` from the '
                   'directory')

            self._logger.warn(err)

        # NOTE: probably need some kind of config here
        if Language:
            self.language = Language()
        else:
            err = ('If you would like to use natural language processing,'
                   ' please run `pip install -e.[nlp]` from the directory')
            self._logger.warn(err)
            self.language = False

        # self.intents = BotIntents()
        self.subprocess_manager = subprocess_manager
        self.command_observer = _CommandObserver(self,
                                                 self.messaging,
                                                 self.subprocess_manager,
                                                 self.language)

        self.messaging.command.subscribe(self.command_observer)
        self.messaging.chatter.subscribe(LogObserver(pass_through=True))
Esempio n. 4
0
 def setUp(self):
     self.subprocess_manager = SubprocessManager()
Esempio n. 5
0
 def __init__(self):
     self.messaging = Message()
     self.subprocess_manager = SubprocessManager()