55#
66# https://www.rivescript.com/
77
8- from __future__ import unicode_literals
8+ from __future__ import unicode_literals , division
99from .regexp import RE
1010from .exceptions import (
1111 RiveScriptError , RepliesNotSortedError , NoDefaultRandomTopicError ,
@@ -438,7 +438,7 @@ def reply_regexp(self, user, regexp):
438438 regexp = regexp .replace ('*' , '(.+?)' ) # Convert * into (.+?)
439439 regexp = regexp .replace ('#' , '(\d+?)' ) # Convert # into (\d+?)
440440 regexp = regexp .replace ('_' , '(\w+?)' ) # Convert _ into (\w+?)
441- regexp = re .sub (r'\s*\{ weight=\d+\}' , '' , regexp ) # Remove {weight} tags, allow spaces before the bracket
441+ regexp = re .sub (RE . weight , '' , regexp ) # Remove {weight} tags, allow spaces before the bracket
442442 regexp = regexp .replace ('<zerowidthstar>' , r'(.*?)' )
443443
444444 # Optionals.
@@ -461,7 +461,7 @@ def reply_regexp(self, user, regexp):
461461 '(?:' + pipes + r'|(?:\\s|\\b))' , regexp )
462462
463463 # _ wildcards can't match numbers!
464- regexp = re .sub (RE .literal_w , r'[A-Za-z ]' , regexp )
464+ regexp = re .sub (RE .literal_w , r'[^\s\d ]' , regexp )
465465
466466 # Filter in arrays.
467467 arrays = re .findall (RE .array , regexp )
@@ -566,6 +566,16 @@ def process_tags(self, user, msg, reply, st=[], bst=[], depth=0, ignore_object_e
566566 if len (botstars ) == 1 :
567567 botstars .append ("undefined" )
568568
569+ matcher = re .findall (RE .reply_array , reply )
570+ for match in matcher :
571+ name = match
572+ if name in self .master ._array :
573+ result = "{random}" + "|" .join (self .master ._array [name ]) + "{/random}"
574+ else :
575+ result = "\x00 @" + name + "\x00 "
576+ reply = reply .replace ("(@" + name + ")" , result )
577+ reply = re .sub (RE .ph_array , r'(@\1)' , reply )
578+
569579 # Tag shortcuts.
570580 reply = reply .replace ('<person>' , '{person}<star>{/person}' )
571581 reply = reply .replace ('<@>' , '{@<star>}' )
@@ -696,7 +706,7 @@ def process_tags(self, user, msg, reply, st=[], bst=[], depth=0, ignore_object_e
696706 elif tag == "mult" :
697707 new = orig * value
698708 elif tag == "div" :
699- new = orig / value
709+ new = orig // value
700710 self .master .set_uservar (user , var , new )
701711 except :
702712 insert = "[ERR: Math couldn't '{}' to value '{}']" .format (tag , curv )
0 commit comments