Exemple #1
0
 def regex(self, variables, counter):
     wildcard = self.wildcards[self.wild]
     if self.maximum == "1":
         return wildcard + r"\b"
     else:
         # we are going to try to match n-1 repetitions of the pattern
         # followed by a space plus 1 rep of the pattern followed by a
         # \b
         min_str = text_type(int(self.minimum) - 1)
         max_str = self.maximum
         if max_str != "":
             max_str = text_type(int(self.maximum) - 1)
         return (r"(" + wildcard + r"\s)" + r"{" + min_str + r"," +
                 max_str + r"}?" + wildcard + r"\b")
Exemple #2
0
    def __init__(self, tokens, text, terminator):
        self.wild = text[0]
        self.minimum = "1"
        self.maximum = ""

        m = re.match(self.__class__.regexc, text)
        groups = m.groups()
        if groups[0]:
            self.minimum = self.maximum = groups[0]
        if groups[1]:  # they gave us a ~
            self.maximum = groups[2]
        self.minimum = text_type(max(int(self.minimum), 1))
        if self.maximum:
            self.maximum = text_type(max(int(self.maximum), int(self.minimum)))
Exemple #3
0
    def __init__(self, tokens, text, terminator):
        self.wild = text[0]
        self.minimum = "1"
        self.maximum = ""

        m = re.match(self.__class__.regexc, text)
        groups = m.groups()
        if groups[0]:
            self.minimum = self.maximum = groups[0]
        if groups[1]:  # they gave us a ~
            self.maximum = groups[2]
        self.minimum = text_type(max(int(self.minimum), 1))
        if self.maximum:
            self.maximum = text_type(max(int(self.maximum), int(self.minimum)))
Exemple #4
0
 def regex(self, variables, counter):
     wildcard = self.wildcards[self.wild]
     if self.maximum == "1":
         return wildcard + r"\b"
     else:
         # we are going to try to match n-1 repetitions of the pattern
         # followed by a space plus 1 rep of the pattern followed by a
         # \b
         min_str = text_type(int(self.minimum) - 1)
         max_str = self.maximum
         if max_str != "":
             max_str = text_type(int(self.maximum) - 1)
         return (r"(" + wildcard + r"\s)" +
                 r"{" + min_str + r"," + max_str + r"}?" +
                 wildcard + r"\b")
Exemple #5
0
if __name__ == "__main__":
    log = logging.getLogger()
    handler = logging.StreamHandler()
    formatter = logging.Formatter("[%(name)s] %(message)s")
    handler.setFormatter(formatter)
    log.addHandler(handler)
    log.setLevel(logging.ERROR)

    ch = ChatbotEngine()
    ch.load_script_directory("scripts")
    print ("Type /quit to quit, "
           "/botvars or /uservars to see values of variables, "
           "/reload to reload the scripts directory,"
           "/log plus debug, info, warning or error to set logging level.")
    while True:
        msg = text_type(input("You> "))
        if msg == "/quit":
            break
        elif msg == "/botvars":
            print(text_type(ch._botvars))
        elif msg == "/uservars":
            if "local" in ch._users:
                print(text_type(ch._users["local"].vars))
            else:
                print("No user variables have been defined.")
        elif msg == "/reload":
            ch.clear_rules()
            ch.load_script_directory("scripts")
        elif msg == "/log debug":
            log.setLevel(logging.DEBUG)
        elif msg == "/log info":