Skip to content

Commit

Permalink
Fix casing problems in %Previous and @reDIrect
Browse files Browse the repository at this point in the history
The `reply_regexp()` function now lowercases the result so that any tags
like `<bot>` get properly lowercased (fixes #80 WRT %Previous)

Also implements a fix from the Go version where redirects weren't
getting lowercased before being followed, which caused similar matching
issues.
  • Loading branch information
kirsle committed Feb 10, 2017
1 parent 76a3381 commit 5c51574
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions rivescript/brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _getreply(self, user, msg, context='normal', step=0, ignore_object_errors=Tr
for trig in self.master._sorted["thats"][top]:
pattern = trig[1]["previous"]
botside = self.reply_regexp(user, pattern)
self.say("Try to match lastReply (" + lastReply + ") to " + pattern)
self.say("Try to match lastReply ({}) to {} ({})".format(lastReply, pattern, repr(botside)))

# Match??
match = re.match(botside, lastReply)
Expand Down Expand Up @@ -307,6 +307,7 @@ def _getreply(self, user, msg, context='normal', step=0, ignore_object_errors=Tr
self.say("Redirecting us to " + matched["redirect"])
redirect = self.process_tags(user, msg, matched["redirect"], stars, thatstars, step,
ignore_object_errors)
redirect = redirect.lower()
self.say("Pretend user said: " + redirect)
reply = self._getreply(user, redirect, step=(step + 1), ignore_object_errors=ignore_object_errors)
break
Expand Down Expand Up @@ -500,7 +501,7 @@ def reply_regexp(self, user, regexp):
self.format_message(history[type][0]))
# TODO: the Perl version doesn't do just <input>/<reply> in trigs!

return re.compile(r'^' + regexp + r'$')
return re.compile(r'^' + regexp.lower() + r'$')

def do_expand_array(self, array_name, depth=0):
"""Do recurrent array expansion, returning a set of keywords.
Expand Down

0 comments on commit 5c51574

Please sign in to comment.