How to use the karmabot.command.CommandSet function in karmabot

To help you get started, we’ve selected a few karmabot 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 chromakode / karmabot / karmabot / command.py View on Github external
for command in traverse_commands(self):
            regex = command.to_regex()
            formatted_regex = self.regex_format.format(regex)

            command_info = {"re":        re.compile(formatted_regex, re.U),
                            "command":   command,
                            "exclusive": command.exclusive}
            command_infos.append(command_info)
        
        # Sort exclusive commands before non-exclusive ones
        command_infos.sort(key=lambda c:c["exclusive"], reverse=True)
        
        return CommandParser(command_infos)


class FacetCommandSet(CommandSet):
    def add(self, *args, **kwargs):
        def doit(handler):
            return CommandSet.add(self, *args, **kwargs)(thing_command(handler, self.name))
        
        return doit

# TODO: stripping listen commands such as --/++
class Command(object):

    def __init__(self, parent, format, handler, help=None, visible=True, exclusive=False):
        self.parent = parent
        self.format = format
        self.handler = handler
        self.help = help
        self.visible = visible
        self.exclusive = exclusive
github chromakode / karmabot / karmabot / command.py View on Github external
def doit(handler):
            return CommandSet.add(self, *args, **kwargs)(thing_command(handler, self.name))
github chromakode / karmabot / karmabot / command.py View on Github external
if name == "thing":
                parameter_regex = r"(?:\([^()]+\))|[#!\w]+"
            else:
                # This regex may come back to haunt me.
                parameter_regex = r".+"

            return r"(?P<{name}>{regex})".format(name=name,
                                                 regex=parameter_regex)

        regex = self.format
        regex = regex.replace("+", r"\+")
        regex = re.sub(r"{(\w+)}", sub_parameter, regex)
        return regex

listen = CommandSet("listen")
thing = CommandSet("thing", regex_format="(^{0}$)")
github chromakode / karmabot / karmabot / command.py View on Github external
name = match.group(1)
            if name == "thing":
                parameter_regex = r"(?:\([^()]+\))|[#!\w]+"
            else:
                # This regex may come back to haunt me.
                parameter_regex = r".+"

            return r"(?P<{name}>{regex})".format(name=name,
                                                 regex=parameter_regex)

        regex = self.format
        regex = regex.replace("+", r"\+")
        regex = re.sub(r"{(\w+)}", sub_parameter, regex)
        return regex

listen = CommandSet("listen")
thing = CommandSet("thing", regex_format="(^{0}$)")