How to use the errbot.Command 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 / dyna_plugin / dyna.py View on Github external
def add_simple(self, _, _1):
        simple1 = Command(lambda plugin, msg, args: 'yep %s' % type(plugin), name='say_yep')
        simple2 = Command(say_foo)

        self.create_dynamic_plugin('simple with special#', (simple1, simple2), doc='documented')

        return 'added'
github errbotio / errbot / tests / dyna_plugin / dyna.py View on Github external
def add_re(self, _, _1):
        re1 = Command(lambda plugin, msg, match: 'fffound',
                      name='ffound',
                      cmd_type=botmatch,
                      cmd_args=(r'^.*cheese.*$',))
        self.create_dynamic_plugin('re', (re1, ))
        return 'added'
github errbotio / errbot / tests / dyna_plugin / dyna.py View on Github external
def add_simple(self, _, _1):
        simple1 = Command(lambda plugin, msg, args: 'yep %s' % type(plugin), name='say_yep')
        simple2 = Command(say_foo)

        self.create_dynamic_plugin('simple with special#', (simple1, simple2), doc='documented')

        return 'added'
github errbotio / errbot / tests / dyna_plugin / dyna.py View on Github external
def add_arg(self, _, _1):
        cmd1_name = 'echo_to_me'
        cmd1 = Command(lambda plugin, msg, args: 'string to echo is %s' % args.positional_arg,
                       cmd_type=arg_botcmd, cmd_args=('positional_arg',),
                       cmd_kwargs={'unpack_args': False, 'name': cmd1_name},
                       name=cmd1_name)

        self.create_dynamic_plugin('arg', (cmd1,), doc='documented')

        return 'added'
github errbotio / errbot / tests / dyna_plugin / dyna.py View on Github external
def add_clashing(self, _, _1):
        simple1 = Command(lambda plugin, msg, args: 'dynamic', name='clash')
        self.create_dynamic_plugin('clashing', (simple1, ))
        return 'added'
github errbotio / errbot / tests / dyna_plugin / dyna.py View on Github external
def add_saw(self, _, _1):
        re1 = Command(lambda plugin, msg, args: '+'.join(args),
                      name='splitme',
                      cmd_type=botcmd,
                      cmd_kwargs={'split_args_with': ','})
        self.create_dynamic_plugin('saw', (re1, ))
        return 'added'
github nzlosh / err-stackstorm / st2.py View on Github external
self.create_dynamic_plugin(
            name="St2",
            doc="err-stackstorm v{} - A StackStorm plugin for authentication and Action Alias "
                "execution.  Use {}{}help for action alias help.".format(
                    ERR_STACKSTORM_VERSION, self.cfg.bot_prefix, self.cfg.plugin_prefix
                ),
            commands=(
                Command(
                    lambda plugin, msg, args: self.st2sessionlist(msg, args),
                    name="{}session_list".format(self.cfg.plugin_prefix),
                    cmd_type=botcmd,
                    cmd_kwargs={"admin_only": True},
                    doc="List any established sessions between the chat service and StackStorm API."
                ),
                Command(
                    lambda plugin, msg, args: self.st2sessiondelete(msg, args),
                    name="{}session_cancel".format(self.cfg.plugin_prefix),
                    cmd_type=botcmd,
                    cmd_kwargs={"admin_only": True},
                    doc="Allow an administrator to cancel a users session."
                ),
                Command(
                    lambda plugin, msg, args: self.st2disconnect(msg, args),
                    name="{}session_end".format(self.cfg.plugin_prefix),
                    cmd_type=botcmd,
                    cmd_kwargs={"admin_only": False},
                    doc="End a user session.  StackStorm credentials are "
                        "purged when the session is closed."
                ),
                Command(
                    lambda plugin, msg, args: self.st2authenticate(msg, args),
github nzlosh / err-stackstorm / st2.py View on Github external
Register commands.
        """

        def st2help(plugin, msg, pack=None, filter=None, limit=None, offset=None):
            return self.st2help(msg, pack, filter, limit, offset)

        def append_args(func, args, kwargs):
            wrapper = func.definition
            wrapper._err_command_parser.add_argument(*args, **kwargs)
            wrapper.__doc__ = wrapper._err_command_parser.format_help()
            fmt = wrapper._err_command_parser.format_usage()
            wrapper._err_command_syntax = fmt[
                len('usage: ') + len(wrapper._err_command_parser.prog) + 1:-1
            ]

        Help_Command = Command(
            st2help,
            name="{}help".format(self.cfg.plugin_prefix),
            cmd_type=arg_botcmd,
            cmd_args=("--pack",),
            cmd_kwargs={"dest": "pack", "type": str},
            doc="Provide help for StackStorm action aliases."
        )
        append_args(Help_Command, ("--filter",), {"dest": "filter", "type": str})
        append_args(Help_Command, ("--limit",), {"dest": "limit", "type": int})
        append_args(Help_Command, ("--offset",), {"dest": "offset", "type": int})

        self.create_dynamic_plugin(
            name="St2",
            doc="err-stackstorm v{} - A StackStorm plugin for authentication and Action Alias "
                "execution.  Use {}{}help for action alias help.".format(
                    ERR_STACKSTORM_VERSION, self.cfg.bot_prefix, self.cfg.plugin_prefix
github nzlosh / err-stackstorm / st2.py View on Github external
commands=(
                Command(
                    lambda plugin, msg, args: self.st2sessionlist(msg, args),
                    name="{}session_list".format(self.cfg.plugin_prefix),
                    cmd_type=botcmd,
                    cmd_kwargs={"admin_only": True},
                    doc="List any established sessions between the chat service and StackStorm API."
                ),
                Command(
                    lambda plugin, msg, args: self.st2sessiondelete(msg, args),
                    name="{}session_cancel".format(self.cfg.plugin_prefix),
                    cmd_type=botcmd,
                    cmd_kwargs={"admin_only": True},
                    doc="Allow an administrator to cancel a users session."
                ),
                Command(
                    lambda plugin, msg, args: self.st2disconnect(msg, args),
                    name="{}session_end".format(self.cfg.plugin_prefix),
                    cmd_type=botcmd,
                    cmd_kwargs={"admin_only": False},
                    doc="End a user session.  StackStorm credentials are "
                        "purged when the session is closed."
                ),
                Command(
                    lambda plugin, msg, args: self.st2authenticate(msg, args),
                    name="{}session_start".format(self.cfg.plugin_prefix),
                    cmd_type=botcmd,
                    cmd_kwargs={"admin_only": False},
                    doc="Usage: {}session_start .\n"
                        "Authenticate with StackStorm API over an out of bands communication"
                        " channel.  User Token or API Key are stored in a user session managed by"
                        " err-stackstorm.".format(self.cfg.plugin_prefix)