Пример #1
0
    def __init__(self, config):
        super().__init__(config)
        identity = config.BOT_IDENTITY

        self.jid = identity['username']  # backward compatibility
        self.password = identity['password']
        self.server = identity.get('server', None)
        self.feature = config.__dict__.get('XMPP_FEATURE_MECHANISMS', {})
        self.keepalive = config.__dict__.get('XMPP_KEEPALIVE_INTERVAL', None)
        self.ca_cert = config.__dict__.get(
            'XMPP_CA_CERT_FILE', '/etc/ssl/certs/ca-certificates.crt')
        self.xhtmlim = config.__dict__.get('XMPP_XHTML_IM', False)

        # generic backend compatibility
        self.bot_identifier = self._build_person(self.jid)

        self.conn = self.create_connection()
        self.conn.add_event_handler("message", self.incoming_message)
        self.conn.add_event_handler("session_start", self.connected)
        self.conn.add_event_handler("disconnected", self.disconnected)
        # presence related handlers
        self.conn.add_event_handler("got_online", self.contact_online)
        self.conn.add_event_handler("got_offline", self.contact_offline)
        self.conn.add_event_handler("changed_status", self.user_changed_status)
        # MUC subject events
        self.conn.add_event_handler("groupchat_subject", self.chat_topic)
        self._room_topics = {}
        self.md_xhtml = xhtml()
        self.md_text = text()
Пример #2
0
 def __init__(self, config):
     super(SkypeBackend, self).__init__(config)
     self.bot_config.SKYPE_ACCEPT_CONTACT_REQUESTS = getattr(config, 'SKYPE_ACCEPT_CONTACT_REQUESTS', True)
     self.skype = Skype4Py.Skype()
     self.skype.OnMessageStatus = self._message_event_handler
     self.skype.OnUserAuthorizationRequestReceived = self._contact_request_event_handler
     self.md_converter = text()
Пример #3
0
    def __init__(self, config):
        super().__init__(config)
        log.debug("Text Backend Init.")

        if hasattr(
                self.bot_config,
                'BOT_IDENTITY') and 'username' in self.bot_config.BOT_IDENTITY:
            self.bot_identifier = self.build_identifier(
                self.bot_config.BOT_IDENTITY['username'])
        else:
            # Just a default identity for the bot if nothing has been specified.
            self.bot_identifier = self.build_identifier('@errbot')

        log.debug('Bot username set at %s.', self.bot_identifier)
        self._inroom = False
        self._rooms = []
        self._multiline = False

        self.demo_mode = self.bot_config.TEXT_DEMO_MODE if hasattr(
            self.bot_config, 'TEXT_DEMO_MODE') else False
        if not self.demo_mode:
            self.md_html = xhtml()  # for more debug feedback on md
            self.md_text = text()  # for more debug feedback on md
            self.md_borderless_ansi = borderless_ansi()
            self.md_im = imtext()
            self.md_lexer = get_lexer_by_name("md", stripall=True)

        self.md_ansi = ansi()
        self.html_lexer = get_lexer_by_name("html", stripall=True)
        self.terminal_formatter = Terminal256Formatter(style='paraiso-dark')
        self.user = self.build_identifier(self.bot_config.BOT_ADMINS[0])
        self._register_identifiers_pickling()
Пример #4
0
    def __init__(self, config):
        super().__init__(config)
        log.debug("Text Backend Init.")

        try:
            # Load readline for better editing/history behaviour
            import readline
        except ImportError:
            # Readline is Unix-only
            log.debug("Python readline module is not available")
            pass

        self.bot_identifier = self.build_identifier('Err')
        self.demo_mode = self.bot_config.TEXT_DEMO_MODE if hasattr(
            self.bot_config, 'TEXT_DEMO_MODE') else False
        self._rooms = set()
        if not self.demo_mode:
            self.md_html = xhtml()  # for more debug feedback on md
            self.md_text = text()  # for more debug feedback on md
            self.md_borderless_ansi = borderless_ansi()
            self.md_im = imtext()
            self.md_lexer = get_lexer_by_name("md", stripall=True)

        self.md_ansi = ansi()
        self.html_lexer = get_lexer_by_name("html", stripall=True)
        self.terminal_formatter = Terminal256Formatter(style='paraiso-dark')
        self.user = self.build_identifier(self.bot_config.BOT_ADMINS[0])
Пример #5
0
    def __init__(self, config):
        super().__init__(config)
        identity = config.BOT_IDENTITY

        self.jid = identity['username']  # backward compatibility
        self.password = identity['password']
        self.server = identity.get('server', None)
        self.feature = config.__dict__.get('XMPP_FEATURE_MECHANISMS', {})
        self.keepalive = config.__dict__.get('XMPP_KEEPALIVE_INTERVAL', None)
        self.ca_cert = config.__dict__.get('XMPP_CA_CERT_FILE', '/etc/ssl/certs/ca-certificates.crt')
        self.xhtmlim = config.__dict__.get('XMPP_XHTML_IM', False)
        self.use_ipv6 = config.__dict__.get('XMPP_USE_IPV6', None)

        # generic backend compatibility
        self.bot_identifier = self._build_person(self.jid)

        self.conn = self.create_connection()
        self.conn.add_event_handler("message", self.incoming_message)
        self.conn.add_event_handler("session_start", self.connected)
        self.conn.add_event_handler("disconnected", self.disconnected)
        # presence related handlers
        self.conn.add_event_handler("got_online", self.contact_online)
        self.conn.add_event_handler("got_offline", self.contact_offline)
        self.conn.add_event_handler("changed_status", self.user_changed_status)
        # MUC subject events
        self.conn.add_event_handler("groupchat_subject", self.chat_topic)
        self._room_topics = {}
        self.md_xhtml = xhtml()
        self.md_text = text()
Пример #6
0
    def __init__(self, config):
        super().__init__(config)
        log.debug("Text Backend Init.")

        try:
            # Load readline for better editing/history behaviour
            import readline
        except ImportError:
            # Readline is Unix-only
            log.debug("Python readline module is not available")
            pass

        self.bot_identifier = self.build_identifier('Err')
        self.demo_mode = self.bot_config.TEXT_DEMO_MODE if hasattr(self.bot_config, 'TEXT_DEMO_MODE') else False
        self._rooms = set()
        if not self.demo_mode:
            self.md_html = xhtml()  # for more debug feedback on md
            self.md_text = text()  # for more debug feedback on md
            self.md_borderless_ansi = borderless_ansi()
            self.md_im = imtext()
            self.md_lexer = get_lexer_by_name("md", stripall=True)

        self.md_ansi = ansi()
        self.html_lexer = get_lexer_by_name("html", stripall=True)
        self.terminal_formatter = Terminal256Formatter(style='paraiso-dark')
        self.user = self.build_identifier(self.bot_config.BOT_ADMINS[0])
Пример #7
0
    def __init__(self, extra_config=None):
        self.outgoing_message_queue = Queue()
        if extra_config is None:
            extra_config = {}
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop('errbot.config-template', None)
        __import__('errbot.config-template')
        config = ShallowConfig()
        config.__dict__.update(sys.modules['errbot.config-template'].__dict__)
        bot_config_defaults(config)

        # It injects itself as a plugin. Changed the name to be sure we distinguish it.
        self.name = 'DummyBackendRealName'

        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = tempdir + sep + 'log.txt'
        config.BOT_PLUGIN_INDEXES = tempdir + sep + 'repos.json'
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {'username': '******'}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = '!'
        config.CHATROOM_FN = 'blah'

        # Writeout the made up repos file
        with open(config.BOT_PLUGIN_INDEXES, "w") as index_file:
            index_file.write(SIMPLE_JSON_PLUGINS_INDEX)

        for key in extra_config:
            setattr(config, key, extra_config[key])
        super().__init__(config)
        self.bot_identifier = self.build_identifier('err')
        self.md = text()  # We just want simple text for testing purposes

        # setup a memory based storage
        spm = SpecificPluginManager(config, 'storage', StoragePluginBase, CORE_STORAGE, None)
        storage_plugin = spm.get_plugin_by_name('Memory')

        # setup the plugin_manager just internally
        botplugins_dir = os.path.join(config.BOT_DATA_DIR, PLUGINS_SUBDIR)
        if not os.path.exists(botplugins_dir):
            os.makedirs(botplugins_dir, mode=0o755)

        # get it back from where we publish it.
        repo_index_paths = (os.path.join(os.path.dirname(__file__), '..', 'docs', '_extra', 'repos.json'),)
        repo_manager = BotRepoManager(storage_plugin,
                                      botplugins_dir,
                                      repo_index_paths)
        self.attach_storage_plugin(storage_plugin)
        self.attach_repo_manager(repo_manager)
        self.attach_plugin_manager(BotPluginManager(storage_plugin,
                                                    repo_manager,
                                                    config.BOT_EXTRA_PLUGIN_DIR,
                                                    config.AUTOINSTALL_DEPS,
                                                    getattr(config, 'CORE_PLUGINS', None),
                                                    getattr(config, 'PLUGINS_CALLBACK_ORDER', (None, ))))
        self.inject_commands_from(self)
        self.inject_command_filters_from(ACLS(self))
Пример #8
0
    def __init__(self, config):
        super(XMPPBackend, self).__init__(config)
        identity = config.BOT_IDENTITY

        self.jid = identity["username"]  # backward compatibility
        self.password = identity["password"]
        self.server = identity.get("server", None)
        self.feature = config.__dict__.get("XMPP_FEATURE_MECHANISMS", {})
        self.keepalive = config.__dict__.get("XMPP_KEEPALIVE_INTERVAL", None)
        self.ca_cert = config.__dict__.get("XMPP_CA_CERT_FILE", "/etc/ssl/certs/ca-certificates.crt")

        # generic backend compatibility
        self.bot_identifier = self.build_identifier(self.jid)

        self.conn = self.create_connection()
        self.conn.add_event_handler("message", self.incoming_message)
        self.conn.add_event_handler("session_start", self.connected)
        self.conn.add_event_handler("disconnected", self.disconnected)
        # presence related handlers
        self.conn.add_event_handler("got_online", self.contact_online)
        self.conn.add_event_handler("got_offline", self.contact_offline)
        self.conn.add_event_handler("changed_status", self.user_changed_status)
        # MUC subject events
        self.conn.add_event_handler("groupchat_subject", self.chat_topic)
        self._room_topics = {}
        self.md_xhtml = xhtml()
        self.md_text = text()
Пример #9
0
    def __init__(self, config):
        super().__init__(config)
        log.debug("Text Backend Init.")

        if hasattr(self.bot_config, 'BOT_IDENTITY') and 'username' in self.bot_config.BOT_IDENTITY:
            self.bot_identifier = self.build_identifier(self.bot_config.BOT_IDENTITY['username'])
        else:
            # Just a default identity for the bot if nothing has been specified.
            self.bot_identifier = self.build_identifier('@errbot')

        log.debug('Bot username set at %s.', self.bot_identifier)
        self._inroom = False
        self._rooms = []
        self._multiline = False

        self.demo_mode = self.bot_config.TEXT_DEMO_MODE if hasattr(self.bot_config, 'TEXT_DEMO_MODE') else False
        if not self.demo_mode:
            self.md_html = xhtml()  # for more debug feedback on md
            self.md_text = text()  # for more debug feedback on md
            self.md_borderless_ansi = borderless_ansi()
            self.md_im = imtext()
            self.md_lexer = get_lexer_by_name("md", stripall=True)

        self.md_ansi = ansi()
        self.html_lexer = get_lexer_by_name("html", stripall=True)
        self.terminal_formatter = Terminal256Formatter(style='paraiso-dark')
        self.user = self.build_identifier(self.bot_config.BOT_ADMINS[0])
        self._register_identifiers_pickling()
Пример #10
0
    def __init__(self, extra_config=None):
        if extra_config is None:
            extra_config = {}
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop("errbot.config-template", None)
        __import__("errbot.config-template")
        config = sys.modules["errbot.config-template"]
        bot_config_defaults(config)
        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = tempdir + sep + "log.txt"
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {"username": "******"}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = "!"
        config.CHATROOM_FN = "blah"

        for key in extra_config:
            setattr(config, key, extra_config[key])
        super(DummyBackend, self).__init__(config)
        self.bot_identifier = self.build_identifier("err")
        self.inject_commands_from(self)
        self.inject_command_filters_from(ACLS(self))
        self.md = text()  # We just want simple text for testing purposes
Пример #11
0
    def __init__(self, extra_config=None):
        self.outgoing_message_queue = Queue()
        if extra_config is None:
            extra_config = {}
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop('errbot.config-template', None)
        __import__('errbot.config-template')
        config = sys.modules['errbot.config-template']
        bot_config_defaults(config)
        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = tempdir + sep + 'log.txt'
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {'username': '******'}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = '!'
        config.CHATROOM_FN = 'blah'

        for key in extra_config:
            setattr(config, key, extra_config[key])
        super().__init__(config)
        self.bot_identifier = self.build_identifier('err')
        self.inject_commands_from(self)
        self.inject_command_filters_from(ACLS(self))
        self.md = text()  # We just want simple text for testing purposes
Пример #12
0
    def __init__(self, extra_config=None):
        self.outgoing_message_queue = Queue()
        if extra_config is None:
            extra_config = {}
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop('errbot.config-template', None)
        __import__('errbot.config-template')
        config = ShallowConfig()
        config.__dict__.update(sys.modules['errbot.config-template'].__dict__)
        bot_config_defaults(config)

        # It injects itself as a plugin. Changed the name to be sure we distinguish it.
        self.name = 'DummyBackendRealName'

        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = tempdir + sep + 'log.txt'
        config.BOT_PLUGIN_INDEXES = tempdir + sep + 'repos.json'
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {'username': '******'}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = '!'
        config.CHATROOM_FN = 'blah'

        # Writeout the made up repos file
        with open(config.BOT_PLUGIN_INDEXES, "w") as index_file:
            index_file.write(SIMPLE_JSON_PLUGINS_INDEX)

        for key in extra_config:
            setattr(config, key, extra_config[key])
        super().__init__(config)
        self.bot_identifier = self.build_identifier('err')
        self.md = text()  # We just want simple text for testing purposes

        # setup a memory based storage
        spm = SpecificPluginManager(config, 'storage', StoragePluginBase, CORE_STORAGE, None)
        storage_plugin = spm.get_plugin_by_name('Memory')

        # setup the plugin_manager just internally
        botplugins_dir = os.path.join(config.BOT_DATA_DIR, PLUGINS_SUBDIR)
        if not os.path.exists(botplugins_dir):
            os.makedirs(botplugins_dir, mode=0o755)

        # get it back from where we publish it.
        repo_index_paths = (os.path.join(os.path.dirname(__file__), '..', 'docs', '_extra', 'repos.json'),)
        repo_manager = BotRepoManager(storage_plugin,
                                      botplugins_dir,
                                      repo_index_paths)
        self.attach_storage_plugin(storage_plugin)
        self.attach_repo_manager(repo_manager)
        self.attach_plugin_manager(BotPluginManager(storage_plugin,
                                                    repo_manager,
                                                    config.BOT_EXTRA_PLUGIN_DIR,
                                                    config.AUTOINSTALL_DEPS,
                                                    getattr(config, 'CORE_PLUGINS', None),
                                                    getattr(config, 'PLUGINS_CALLBACK_ORDER', (None, ))))
        self.inject_commands_from(self)
        self.inject_command_filters_from(ACLS(self))
Пример #13
0
    def __init__(self, extra_config=None):
        self.outgoing_message_queue = Queue()
        if extra_config is None:
            extra_config = {}
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop('errbot.config-template', None)
        __import__('errbot.config-template')
        config = sys.modules['errbot.config-template']
        bot_config_defaults(config)
        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = tempdir + sep + 'log.txt'
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {'username': '******'}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = '!'
        config.CHATROOM_FN = 'blah'

        for key in extra_config:
            setattr(config, key, extra_config[key])
        super(DummyBackend, self).__init__(config)
        self.bot_identifier = self.build_identifier('err')
        self.inject_commands_from(self)
        self.inject_command_filters_from(ACLS(self))
        self.md = text()  # We just want simple text for testing purposes
Пример #14
0
 def __init__(self, config):
     super(SkypeBackend, self).__init__(config)
     self.bot_config.SKYPE_ACCEPT_CONTACT_REQUESTS = getattr(
         config, 'SKYPE_ACCEPT_CONTACT_REQUESTS', True)
     self.skype = Skype4Py.Skype()
     self.skype.OnMessageStatus = self._message_event_handler
     self.skype.OnUserAuthorizationRequestReceived = self._contact_request_event_handler
     self.md_converter = text()
Пример #15
0
    def __init__(self, extra_config=None):
        self.outgoing_message_queue = Queue()
        if extra_config is None:
            extra_config = {}
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop("errbot.config-template", None)
        __import__("errbot.config-template")
        config = ShallowConfig()
        config.__dict__.update(sys.modules["errbot.config-template"].__dict__)
        bot_config_defaults(config)
        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = tempdir + sep + "log.txt"
        config.BOT_PLUGIN_INDEXES = tempdir + sep + "repos.json"
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {"username": "******"}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = "!"
        config.CHATROOM_FN = "blah"

        # Writeout the made up repos file
        with open(config.BOT_PLUGIN_INDEXES, "w") as index_file:
            index_file.write(SIMPLE_JSON_PLUGINS_INDEX)

        for key in extra_config:
            setattr(config, key, extra_config[key])
        super().__init__(config)
        self.bot_identifier = self.build_identifier("err")
        self.md = text()  # We just want simple text for testing purposes

        # setup a memory based storage
        spm = SpecificPluginManager(config, "storage", StoragePluginBase, CORE_STORAGE, None)
        storage_plugin = spm.get_plugin_by_name("Memory")

        # setup the plugin_manager just internally
        botplugins_dir = os.path.join(config.BOT_DATA_DIR, PLUGINS_SUBDIR)
        if not os.path.exists(botplugins_dir):
            os.makedirs(botplugins_dir, mode=0o755)

        # get it back from where we publish it.
        repo_index_paths = (os.path.join(os.path.dirname(__file__), "..", "docs", "_extra", "repos.json"),)
        repo_manager = BotRepoManager(storage_plugin, botplugins_dir, repo_index_paths)
        self.attach_storage_plugin(storage_plugin)
        self.attach_repo_manager(repo_manager)
        self.attach_plugin_manager(
            BotPluginManager(
                storage_plugin,
                repo_manager,
                config.BOT_EXTRA_PLUGIN_DIR,
                config.AUTOINSTALL_DEPS,
                getattr(config, "CORE_PLUGINS", None),
                getattr(config, "PLUGINS_CALLBACK_ORDER", (None,)),
            )
        )
        self.inject_commands_from(self)
        self.inject_command_filters_from(ACLS(self))
Пример #16
0
 def __init__(self, config):
     super().__init__(config)
     log.debug("Text Backend Init.")
     self.bot_identifier = self.build_identifier('Err')
     self.rooms = set()
     self.md_html = xhtml()  # for more debug feedback on md
     self.md_text = text()  # for more debug feedback on md
     self.md_ansi = ansi()
     self.md_lexer = get_lexer_by_name("md", stripall=True)
     self.html_lexer = get_lexer_by_name("html", stripall=True)
     self.terminal_formatter = Terminal256Formatter(style='paraiso-dark')
Пример #17
0
 def __init__(self, config):
     super().__init__(config)
     log.debug("Text Backend Init.")
     self.bot_identifier = self.build_identifier('Err')
     self.rooms = set()
     self.md_html = xhtml()  # for more debug feedback on md
     self.md_text = text()  # for more debug feedback on md
     self.md_ansi = ansi()
     self.md_im = imtext()
     self.md_lexer = get_lexer_by_name("md", stripall=True)
     self.html_lexer = get_lexer_by_name("html", stripall=True)
     self.terminal_formatter = Terminal256Formatter(style='paraiso-dark')
Пример #18
0
    def __init__(self, config):
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.CHATROOM_PRESENCE = ('testroom',)  # we are testing with simple identfiers
        config.BOT_IDENTITY = {'username': '******'}  # we are testing with simple identfiers
        self.bot_identifier = self.build_identifier('Err')  # whatever

        super().__init__(config)
        self.incoming_stanza_queue = Queue()
        self.outgoing_message_queue = Queue()
        self.sender = self.build_identifier(config.BOT_ADMINS[0])  # By default, assume this is the admin talking
        self.reset_rooms()
        self.md = text()
Пример #19
0
    def __init__(self, config):
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.CHATROOM_PRESENCE = ('testroom',)  # we are testing with simple identfiers
        config.BOT_IDENTITY = {'username': '******'}  # we are testing with simple identfiers
        self.bot_identifier = self.build_identifier('Err')  # whatever

        super().__init__(config)
        self.incoming_stanza_queue = Queue()
        self.outgoing_message_queue = Queue()
        self.sender = self.build_identifier(config.BOT_ADMINS[0])  # By default, assume this is the admin talking
        self.reset_rooms()
        self.md = text()
Пример #20
0
    def __init__(self, config):
        super().__init__(config)
        logging.getLogger('telegram.bot').addFilter(TelegramBotFilter())

        identity = config.BOT_IDENTITY
        self.token = identity.get('token', None)
        if not self.token:
            log.fatal(
                "You need to supply a token for me to use. You can obtain "
                "a token by registering your bot with the Bot Father (@BotFather)"
            )
            sys.exit(1)
        self.telegram = None  # Will be initialized in serve_once
        self.bot_instance = None  # Will be set in serve_once
        self.md_converter = text()
Пример #21
0
    def __init__(self, config):
        super().__init__(config)
        config.MESSAGE_SIZE_LIMIT = TELEGRAM_MESSAGE_SIZE_LIMIT
        logging.getLogger('telegram.bot').addFilter(TelegramBotFilter())

        identity = config.BOT_IDENTITY
        self.token = identity.get('token', None)
        if not self.token:
            log.fatal(
                "You need to supply a token for me to use. You can obtain "
                "a token by registering your bot with the Bot Father (@BotFather)"
            )
            sys.exit(1)
        self.telegram = None  # Will be initialized in serve_once
        self.bot_instance = None  # Will be set in serve_once
        self.md_converter = text()
Пример #22
0
    def __init__(self, config):
        super().__init__(config)
        log.debug("Text Backend Init.")
        self.bot_identifier = self.build_identifier('Err')
        self.demo_mode = self.bot_config.TEXT_DEMO_MODE if hasattr(self.bot_config, 'TEXT_DEMO_MODE') else False
        self._rooms = set()
        if not self.demo_mode:
            self.md_html = xhtml()  # for more debug feedback on md
            self.md_text = text()  # for more debug feedback on md
            self.md_borderless_ansi = borderless_ansi()
            self.md_im = imtext()
            self.md_lexer = get_lexer_by_name("md", stripall=True)

        self.md_ansi = ansi()
        self.html_lexer = get_lexer_by_name("html", stripall=True)
        self.terminal_formatter = Terminal256Formatter(style='paraiso-dark')
Пример #23
0
    def __init__(self, extra_config=None):
        self.outgoing_message_queue = Queue()
        if extra_config is None:
            extra_config = {}
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop("errbot.config-template", None)
        __import__("errbot.config-template")
        config = sys.modules["errbot.config-template"]
        bot_config_defaults(config)
        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = tempdir + sep + "log.txt"
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {"username": "******"}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = "!"
        config.CHATROOM_FN = "blah"

        for key in extra_config:
            setattr(config, key, extra_config[key])
        super().__init__(config)
        self.bot_identifier = self.build_identifier("err")
        self.md = text()  # We just want simple text for testing purposes

        # setup a memory based storage
        spm = SpecificPluginManager(config, "storage", StoragePluginBase, CORE_STORAGE, None)
        storage_plugin = spm.get_plugin_by_name("Memory")

        # setup the plugin_manager just internally
        botplugins_dir = os.path.join(config.BOT_DATA_DIR, PLUGINS_SUBDIR)
        if not os.path.exists(botplugins_dir):
            os.makedirs(botplugins_dir, mode=0o755)

        self.attach_plugin_manager(
            BotPluginManager(
                storage_plugin,
                botplugins_dir,
                config.BOT_EXTRA_PLUGIN_DIR,
                config.AUTOINSTALL_DEPS,
                getattr(config, "CORE_PLUGINS", None),
            )
        )
        self.attach_storage_plugin(storage_plugin)
        self.inject_commands_from(self)
        self.inject_command_filters_from(ACLS(self))
Пример #24
0
    def __init__(self, config):
        super().__init__(config)
        log.debug("Text Backend Init.")
        self.bot_identifier = self.build_identifier('Err')
        self.demo_mode = self.bot_config.TEXT_DEMO_MODE if hasattr(
            self.bot_config, 'TEXT_DEMO_MODE') else False
        self._rooms = set()
        if not self.demo_mode:
            self.md_html = xhtml()  # for more debug feedback on md
            self.md_text = text()  # for more debug feedback on md
            self.md_borderless_ansi = borderless_ansi()
            self.md_im = imtext()
            self.md_lexer = get_lexer_by_name("md", stripall=True)

        self.md_ansi = ansi()
        self.html_lexer = get_lexer_by_name("html", stripall=True)
        self.terminal_formatter = Terminal256Formatter(style='paraiso-dark')
Пример #25
0
    def __init__(self, config):
        super().__init__(config)
        logging.getLogger('telegram.bot').addFilter(TelegramBotFilter())

        identity = config.BOT_IDENTITY
        self.token = identity.get('token', None)
        if not self.token:
            log.fatal(
                "You need to supply a token for me to use. You can obtain "
                "a token by registering your bot with the Bot Father (@BotFather)"
            )
            sys.exit(1)
        self.telegram = None  # Will be initialized in serve_once
        self.bot_instance = None  # Will be set in serve_once

        compact = config.COMPACT_OUTPUT if hasattr(config, 'COMPACT_OUTPUT') else False
        enable_format('text', TEXT_CHRS, borders=not compact)
        self.md_converter = text()
Пример #26
0
    def __init__(self, extra_config=None):
        self.outgoing_message_queue = Queue()
        if extra_config is None:
            extra_config = {}
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop('errbot.config-template', None)
        __import__('errbot.config-template')
        config = sys.modules['errbot.config-template']
        bot_config_defaults(config)
        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = tempdir + sep + 'log.txt'
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {'username': '******'}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = '!'
        config.CHATROOM_FN = 'blah'

        for key in extra_config:
            setattr(config, key, extra_config[key])
        super().__init__(config)
        self.bot_identifier = self.build_identifier('err')
        self.md = text()  # We just want simple text for testing purposes

        # setup a memory based storage
        spm = SpecificPluginManager(config, 'storage', StoragePluginBase,
                                    CORE_STORAGE, None)
        storage_plugin = spm.get_plugin_by_name('Memory')

        # setup the plugin_manager just internally
        botplugins_dir = os.path.join(config.BOT_DATA_DIR, PLUGINS_SUBDIR)
        if not os.path.exists(botplugins_dir):
            os.makedirs(botplugins_dir, mode=0o755)

        self.attach_plugin_manager(
            BotPluginManager(storage_plugin, botplugins_dir,
                             config.BOT_EXTRA_PLUGIN_DIR,
                             config.AUTOINSTALL_DEPS,
                             getattr(config, 'CORE_PLUGINS', None)))
        self.attach_storage_plugin(storage_plugin)
        self.inject_commands_from(self)
        self.inject_command_filters_from(ACLS(self))
Пример #27
0
 def output_ip(self, data):
     url = ("%s/?page=subnets&section=%s"
            "&subnetId=%s&sPage=address-details&ipaddrid=%s"
            % (ipam_baseurl, ipam_sectionid, data['subnetId'], data['id']))
     message = ("IPAM says:\n"
                " ========== \n"
                "[ip address] %s\n"
                "[hostname] %s\n"
                "[description] %s\n"
                "[owner] %s\n"
                "[link] %s\n"
                " ========== \n"
                % (data['ip'],
                   data['hostname'],
                   data['description'],
                   data['owner'],
                   url))
     md = text()
     return md.convert(message)
Пример #28
0
    def __init__(self, config):
        super().__init__(config)
        config.MESSAGE_SIZE_LIMIT = TELEGRAM_MESSAGE_SIZE_LIMIT
        logging.getLogger('telegram.bot').addFilter(TelegramBotFilter())

        identity = config.BOT_IDENTITY
        self.token = identity.get('token', None)
        if not self.token:
            log.fatal(
                "You need to supply a token for me to use. You can obtain "
                "a token by registering your bot with the Bot Father (@BotFather)"
            )
            sys.exit(1)
        self.telegram = None  # Will be initialized in serve_once
        self.bot_instance = None  # Will be set in serve_once

        compact = config.COMPACT_OUTPUT if hasattr(config, 'COMPACT_OUTPUT') else False
        enable_format('text', TEXT_CHRS, borders=not compact)
        self.md_converter = text()
Пример #29
0
 def output_subnet(self, data):
     url = ("%s/?page=subnets&section=%s&subnetId=%s"
            % (ipam_baseurl, data['sectionId'], data['id']))
     message = ("IPAM says:\n"
                " ========== \n"
                "[subnet] %s/%s\n"
                "[description] %s\n"
                "[used] %s/%s\n"
                "[first free ip] %s\n"
                "[link] %s\n"
                " ========== \n"
                % (data['subnet'],
                   data['mask'],
                   data['description'],
                   data['used'],
                   data['maxhosts'],
                   data['first_free'],
                   url))
     md = text()
     return md.convert(message)
Пример #30
0
    def __init__(self, config):
        super().__init__(config)
        config.MESSAGE_SIZE_LIMIT = MESSAGE_SIZE_LIMIT
        logging.getLogger('VK.bot').addFilter(VKBotFilter())

        identity = config.BOT_IDENTITY
        if identity.get('token', None):
            self.token = identity.get('token')
        else:

            self.login = identity.get('login', None)
            self.password = identity.get('password', None)
            self.token = None

        self.vk = None  # Will be initialized in serve_once
        self.bot_instance = None  # Will be set in serve_once

        compact = config.COMPACT_OUTPUT if hasattr(config,
                                                   'COMPACT_OUTPUT') else False
        enable_format('text', TEXT_CHRS, borders=not compact)
        self.md_converter = text()
Пример #31
0
def test_escaping():
    mdc = rendering.text()
    original = "#not a title\n*not italic*\n`not code`\ntoto{not annotation}"
    escaped = rendering.md_escape(original)
    assert original == mdc.convert(escaped)
Пример #32
0
def test_text():
    mdc = rendering.text()
    assert mdc.convert("*woot*") == "woot"
    assert mdc.convert("# woot") == "WOOT"
Пример #33
0
def test_escaping():
    mdc = rendering.text()
    original = '#not a title\n*not italic*\n`not code`\ntoto{not annotation}'
    escaped = rendering.md_escape(original)
    assert original == mdc.convert(escaped)
Пример #34
0
    def __init__(self, extra_config=None):
        self.outgoing_message_queue = Queue()
        if extra_config is None:
            extra_config = {}
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop("errbot.config-template", None)
        __import__("errbot.config-template")
        config = ShallowConfig()
        config.__dict__.update(sys.modules["errbot.config-template"].__dict__)
        bot_config_defaults(config)

        # It injects itself as a plugin. Changed the name to be sure we distinguish it.
        self.name = "DummyBackendRealName"

        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = tempdir + sep + "log.txt"
        config.BOT_PLUGIN_INDEXES = tempdir + sep + "repos.json"
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {"username": "******"}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = "!"
        config.CHATROOM_FN = "blah"

        # Writeout the made up repos file
        with open(config.BOT_PLUGIN_INDEXES, "w") as index_file:
            index_file.write(SIMPLE_JSON_PLUGINS_INDEX)

        for key in extra_config:
            setattr(config, key, extra_config[key])
        super().__init__(config)
        self.bot_identifier = self.build_identifier("err")
        self.md = text()  # We just want simple text for testing purposes

        # setup a memory based storage
        spm = BackendPluginManager(config, "errbot.storage", "Memory",
                                   StoragePluginBase, CORE_STORAGE)
        storage_plugin = spm.load_plugin()

        # setup the plugin_manager just internally
        botplugins_dir = os.path.join(config.BOT_DATA_DIR, PLUGINS_SUBDIR)
        if not os.path.exists(botplugins_dir):
            os.makedirs(botplugins_dir, mode=0o755)

        # get it back from where we publish it.
        repo_index_paths = (os.path.join(os.path.dirname(__file__), "..",
                                         "docs", "_extra", "repos.json"), )
        repo_manager = BotRepoManager(storage_plugin, botplugins_dir,
                                      repo_index_paths)
        self.attach_storage_plugin(storage_plugin)
        self.attach_repo_manager(repo_manager)
        self.attach_plugin_manager(
            BotPluginManager(
                storage_plugin,
                config.BOT_EXTRA_PLUGIN_DIR,
                config.AUTOINSTALL_DEPS,
                getattr(config, "CORE_PLUGINS", None),
                lambda name, clazz: clazz(self, name),
                getattr(config, "PLUGINS_CALLBACK_ORDER", (None, )),
            ))
        self.inject_commands_from(self)
        self.inject_command_filters_from(ACLS(self))
Пример #35
0
def test_text():
    mdc = rendering.text()
    assert mdc.convert("*woot*") == "woot"
    assert mdc.convert("# woot") == "WOOT"
Пример #36
0
 def test_escaping(self):
     mdc = text()
     original = '#not a title\n*not italic*\n`not code`\ntoto{not annotation}'
     escaped = md_escape(original)
     self.assertEquals(original, mdc.convert(escaped))
Пример #37
0
 def test_text(self):
     mdc = text()
     self.assertEquals(mdc.convert("*woot*"), "woot")
     self.assertEquals(mdc.convert("# woot"), "WOOT")