How to use the errbot.errBot.ErrBot function in errbot

To help you get started, we’ve selected a few errbot 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 errbotio / errbot / tests / backend_manager_tests.py View on Github external
def test_builtins():
    bpm = SpecificPluginManager(
            {},
            'backends',
            ErrBot,
            CORE_BACKENDS,
            extra_search_dirs=())
    backend_plug = bpm.getPluginCandidates()
    names = [plug.name for (_, _, plug) in backend_plug]
    assert 'Text' in names
    assert 'Test' in names
    assert 'Null' in names
github errbotio / errbot / errbot / backends / slack.py View on Github external
class SlackMUCOccupant(MUCIdentifier, SlackIdentifier):
    """
    This class represents a person inside a MUC.
    """
    room = SlackIdentifier.channelname

    def __unicode__(self):
        return "#%s/%s" % (self.room, self.username)

    def __str__(self):
        return self.__unicode__()


class SlackBackend(ErrBot):
    def __init__(self, config):
        super().__init__(config)
        identity = config.BOT_IDENTITY
        self.token = identity.get('token', None)
        if not self.token:
            log.fatal(
                'You need to set your token (found under "Bot Integration" on Slack) in '
                'the BOT_IDENTITY setting in your configuration. Without this token I '
                'cannot connect to Slack.'
            )
            sys.exit(1)
        self.sc = None  # Will be initialized in serve_once
        self.md = imtext()

    def api_call(self, method, data=None, raise_errors=True):
        """
github errbotio / errbot / errbot / backends / tox.py View on Github external
for friend_id in identifiers:
                log.debug("Invite friend %i in group %i", int(friend_id), self.group_number)
                self.conn.invite_friend(int(friend_id), self.group_number)
        raise ValueError("This chatgroup is not joined, you cannot invite anybody.")

    def __str__(self):
        return self.__unicode__()

    def __unicode__(self):
        if self.joined:
            return "ChatRoom #%s: %s" % (self.node, self.topic)
        else:
            return "Unjoined Room"


class ToxBackend(ErrBot):
    def __init__(self, config):
        if not hasattr(config, 'TOX_BOOTSTRAP_SERVER'):
            log.fatal("""
            You need to provide a server to bootstrap from in config.TOX_BOOTSTRAP_SERVER.
            for example :
            TOX_BOOTSTRAP_SERVER = ["54.199.139.199", 33445,
                                    "7F9C31FE850E97CEFD4C4591DF93FC757C7C12549DDD55F8EEAECC34FE76C029"]

            You can find currently active public ones on :
            https://wiki.tox.im/Nodes """)
            sys.exit(-1)

        username = config.BOT_IDENTITY['username']
        super(ToxBackend, self).__init__(config)
        self.conn = ToxConnection(self, username)
        self.bot_identifier = ToxIdentifier(userid=str(self.conn.get_address()), username=username)
github errbotio / err-backend-gitter / gitter.py View on Github external
m = Message(json_message['text'],
                                extras={'id': json_message['id']})
                    if self.room._uri == from_user['url']:
                        m.to = self.backend.bot_identifier
                    else:
                        m.to = self.room
                        m.extras['url'] = 'https://gitter.im/%s?at=%s' % (
                            self.room.uri, m.extras['id'])
                    m.frm = GitterRoomOccupant.build_from_json(self.room, from_user)
                    self.backend.callback_message(m)
                else:
                    log.debug('Received keep-alive on %s', self.room.name)
        except:
            log.exception('An exception occured while streaming the room: ')

class GitterBackend(ErrBot):
    """
    This is the Gitter backend for errbot.
    """

    def __init__(self, config):
        super().__init__(config)
        if config.MESSAGE_SIZE_LIMIT > GITTER_MESSAGE_SIZE_LIMIT:
            log.info(
                "Capping MESSAGE_SIZE_LIMIT to %s which is the maximum length allowed by Gitter",
                GITTER_MESSAGE_SIZE_LIMIT
            )
            config.MESSAGE_SIZE_LIMIT = GITTER_MESSAGE_SIZE_LIMIT
        self.md = md()
        identity = config.BOT_IDENTITY

        self.token = identity.get('token', None)
github errbotio / errbot / errbot / backends / xmpp.py View on Github external
Use the methods on :class:`XMPPMUCRoom` instead.
        """
        warnings.warn(
            "Using invite_in_room is deprecated, use invite from the "
            "MUCRoom class instead.",
            DeprecationWarning,
        )
        self._bot.query_room(room).invite(jids_to_invite)

XMPP_TO_ERR_STATUS = {'available': ONLINE,
                      'away': AWAY,
                      'dnd': DND,
                      'unavailable': OFFLINE}


class XMPPBackend(ErrBot):

    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()
github errbotio / errbot / errbot / backends / campfire.py View on Github external
self.rooms[name] = (room, stream)


ENCODING_INPUT = sys.stdin.encoding


class CampfireIdentifier(object):
    def __init__(self, user):
        self._user = user   # it is just one room for the moment

    @property
    def user(self):
        return self._user


class CampfireBackend(ErrBot):
    exit_lock = Condition()

    def __init__(self, config):
        super(CampfireBackend, self).__init__(config)
        identity = config.BOT_IDENTITY
        self.conn = None
        self.subdomain = identity['subdomain']
        self.username = identity['username']
        self.password = identity['password']
        if not hasattr(config, 'CHATROOM_PRESENCE') or len(config['CHATROOM_PRESENCE']) < 1:
            raise Exception('Your bot needs to join at least one room, please set'
                            ' CHATROOM_PRESENCE with at least a room in your config')
        self.chatroom = config.CHATROOM_PRESENCE[0]
        self.room = None
        self.ssl = identity['ssl'] if 'ssl' in identity else True
        self.bot_identifier = None
github errbotio / errbot / errbot / errBot.py View on Github external
def __init__(self, bot_config):
        log.debug("ErrBot init.")
        self.bot_config = bot_config

        self.plugin_dir = os.path.join(bot_config.BOT_DATA_DIR, PLUGINS_SUBDIR)

        self.open_storage(os.path.join(bot_config.BOT_DATA_DIR, 'core.db'))
        self.prefix = bot_config.BOT_PREFIX
        # be sure we have a configs entry for the plugin configurations
        if CONFIGS not in self:
            self[CONFIGS] = {}
        super(ErrBot, self).__init__(bot_config)

        # init the plugin manager part
        self._init_plugin_manager()
github sinkingpoint / GHC-Errbot / hangouts_chat.py View on Github external
return self.display_name

    @property
    def client(self):
        return 'Hangouts Chat'

    @property
    def nick(self):
        return self.display_name

    @property
    def aclattr(self):
        return self.email


class GoogleHangoutsChatBackend(ErrBot):
    def __init__(self, config):
        super().__init__(config)
        identity = config.BOT_IDENTITY
        self.at_name = config.BOT_PREFIX
        self.creds_file = identity['GOOGLE_CREDS_FILE']
        self.gce_project = identity['GOOGLE_CLOUD_ENGINE_PROJECT']
        self.gce_topic = identity['GOOGLE_CLOUD_ENGINE_PUBSUB_TOPIC']
        self.gce_subscription = identity['GOOGLE_CLOUD_ENGINE_PUBSUB_SUBSCRIPTION']
        self.chat_api = GoogleHangoutsChatAPI(self.creds_file)
        self.bot_identifier = HangoutsChatUser(None, self.at_name, None, None)
        self.message_cache = LRUCache(1024)
        self.md = hangoutschat_markdown_converter()

    def _subscribe_to_pubsub_topic(self, project, topic_name, subscription_name, callback):
        subscriber = pubsub.SubscriberClient()
        subscription_name = 'projects/{}/subscriptions/{}'.format(project, subscription_name)
github errbotio / errbot / errbot / backends / jabber.py View on Github external
self.send(mess)


def is_from_history(mess):
    props = mess.getProperties()
    return 'urn:xmpp:delay' in props or NS_DELAY in props


class Identity(JID):
    def __init__(self, jid=None, node='', domain='', resource=''):
        if jid:
            node, domain, resource = parse_jid(jid)
        JID.__init__(self, node=node, domain=domain, resource=resource)


class JabberBot(ErrBot):
    # Show types for presence
    AVAILABLE, AWAY, CHAT = None, 'away', 'chat'
    DND, XA, OFFLINE = 'dnd', 'xa', 'unavailable'

    # UI-messages (overwrite to change content)
    MSG_AUTHORIZE_ME = 'Hey there. You are not yet on my roster. '\
                       'Authorize my request and I will do the same.'
    MSG_NOT_AUTHORIZED = 'You did not authorize my subscription request. '\
                         'Access denied.'

    PING_FREQUENCY = 10  # Set to the number of seconds, e.g. 60.
    PING_TIMEOUT = 2  # Seconds to wait for a response.
    RETRY_FREQUENCY = 10  # Set to the number of seconds to attempt another connection attempt in case of connectivity loss

    return_code = 0  # code for the process exit
github errbotio / errbot / errbot / errBot.py View on Github external
def __init__(self, bot_config):
        log.debug("ErrBot init.")
        super(ErrBot, self).__init__(bot_config)
        self._init_plugin_manager(bot_config)
        self.bot_config = bot_config
        self.prefix = bot_config.BOT_PREFIX
        if bot_config.BOT_ASYNC:
            self.thread_pool = ThreadPool(3)
            log.debug('created the thread pool' + str(self.thread_pool))
        self.commands = {}  # the dynamically populated list of commands available on the bot
        self.re_commands = {}  # the dynamically populated list of regex-based commands available on the bot
        self.command_filters = []  # the dynamically populated list of filters
        self.MSG_UNKNOWN_COMMAND = 'Unknown command: "%(command)s". ' \
                                   'Type "' + bot_config.BOT_PREFIX + 'help" for available commands.'
        if bot_config.BOT_ALT_PREFIX_CASEINSENSITIVE:
            self.bot_alt_prefixes = tuple(prefix.lower() for prefix in bot_config.BOT_ALT_PREFIXES)
        else:
            self.bot_alt_prefixes = bot_config.BOT_ALT_PREFIXES