Skip to content

Commit 5c51574

Browse files
committed
Fix casing problems in %Previous and @reDIrect
The `reply_regexp()` function now lowercases the result so that any tags like `<bot>` get properly lowercased (fixes aichaos#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.
1 parent 76a3381 commit 5c51574

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

rivescript/brain.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def _getreply(self, user, msg, context='normal', step=0, ignore_object_errors=Tr
228228
for trig in self.master._sorted["thats"][top]:
229229
pattern = trig[1]["previous"]
230230
botside = self.reply_regexp(user, pattern)
231-
self.say("Try to match lastReply (" + lastReply + ") to " + pattern)
231+
self.say("Try to match lastReply ({}) to {} ({})".format(lastReply, pattern, repr(botside)))
232232

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

503-
return re.compile(r'^' + regexp + r'$')
504+
return re.compile(r'^' + regexp.lower() + r'$')
504505

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

0 commit comments

Comments
 (0)