diff options
| author | Brian Sherson <caretaker82@euclid.shersonb.net> | 2013-12-08 14:17:54 -0800 | 
|---|---|---|
| committer | Brian Sherson <caretaker82@euclid.shersonb.net> | 2013-12-08 14:17:54 -0800 | 
| commit | 043ad3074979b1d772f97b2253032bcc5ac7ddeb (patch) | |
| tree | c10515f4b223c7f404b0ddf778eb0aa33d2a9e9b /sedbot.py | |
| parent | db4e4be167af2767fd2c12252cdf15c3281900ff (diff) | |
Fixed SEDBOT, added v flag
Diffstat (limited to 'sedbot.py')
| -rw-r--r-- | sedbot.py | 61 | 
1 files changed, 35 insertions, 26 deletions
@@ -10,37 +10,46 @@ class SED(object):          self.__version__ = "0.0.2"          self.expiry = expiry          self.history = [] -        self.pattern = r"^!?s([,/#])((?:.|\\\1)*)\1((?:.|\\\1)*)\1([ig]*)$" +        self.trigger = r"^!?s([,/#])(.*)$" +        self.pattern = r"^((?:[^%(delimiter)s]|\\.)*)%(delimiter)s((?:[^%(delimiter)s]|\\.)*)%(delimiter)s([igv]*)$"      def onChanMsg(self, IRC, user, channel, targetprefix, msg): -        matches = re.findall(self.pattern, msg) +        matches = re.findall(self.trigger, msg)          if matches: -            separator, find, replace, flags = matches[0] -            find = re.sub("\\\\([,/#\\\\])", "\\1", find) -            replace = re.sub("\\\\(,/#\\\\)", "\\1", replace) -            match = False -            for t, IRC2, user2, channel2, msg2, isaction in self.history.__reversed__(): -                if channel != channel2: -                    continue -                try: -                    if re.findall(find, msg2): -                        sub = re.sub(find, replace, msg2, flags=re.I if "i" in flags else 0) -                        match = True -                    else: +            delimiter, args = matches[0] +            validate = re.findall(self.pattern%vars(), args) +            if validate: +                find, replace, flags = validate[0] +                find = re.sub(r"\\([,/#\\])", r"\1", find) +                replace = re.sub(r"\\([,/#\\])", r"\1", replace) +                if "v" in flags: +                    channel.msg("Delimiter: '%s', Search pattern: '%s', Replacement: '%s', Flags: '%s'" % (delimiter, find, replace, flags), origin=self) +                match = False +                for t, IRC2, user2, channel2, targetprefix2, msg2, isaction in self.history.__reversed__(): +                    if channel != channel2:                          continue -                except: -                    channel.msg("%s: Invalid syntax" % user.nick, origin=self) -                    raise -                if isaction: -                    channel.msg("What %s really meant was: *%s %s" % (user2.nick, user2.nick, sub), origin=self) -                else: -                    channel.msg("What %s really meant to say was: %s" % -                                (user2.nick, sub), origin=self) -                break -            if not match: -                channel.msg("%s: I tried. I really tried! But I could not find the pattern: %s" % (user.nick, find), origin=self) +                    try: +                        if re.findall(find, msg2): +                            sub = re.sub(find, replace, msg2, flags=re.I if "i" in flags else 0) +                            match = True +                        else: +                            continue +                    except: +                        channel.msg("%s: Invalid syntax" % +                                    user.nick, origin=self) +                        raise +                    if isaction: +                        channel.msg("What %s really meant was: *%s %s" % (user2.nick, user2.nick, sub), origin=self) +                    else: +                        channel.msg("What %s really meant to say was: %s" % (user2.nick, sub), origin=self) +                    break +                if not match: +                    channel.msg("%s: I tried. I really tried! But I could not find the pattern: %s" % (user.nick, find), origin=self) +            else: +                channel.msg("%s: Invalid syntax. Did you forget a trailing delimiter?" % user.nick, origin=self)          else: -            self.history.append((time.time(), IRC, user, channel, msg, False)) +            self.history.append((time.time( +            ), IRC, user, channel, targetprefix, msg, False))          while len(self.history) and self.history[0][0] < time.time()-1800:              del self.history[0]  | 
