python - Cannot match regex with re.search on Twisted Framework ircbot -


i'll start "i'm not familiar python". i'm trying change default ircbot script twisted channel, cannot re.match or re.search working.

for example, works:

prompt = ("%s" % self.nickname) prompt1 = ("%s:" % self.nickname) prompt2 = ("%s," % self.nickname)  if msg == (prompt1 + " whoareyou?") or msg == (prompt2 + " you?") or msg == (prompt1 + " whoareyou") or msg == (prompt2 + " you"): 

this 1 well

if msg == (prompt1 + " help") or msg == (prompt2 + " help"): 

however these 2 conditions not work on bot (but work on local script):

if re.search(r'%s[:,] help' % self.nickname, msg):  elif re.search(r'%s[:,] ?are ?you?' % self.nickname, msg): 

a previous version of script not using re.search can found here

i have found causing problem. twisted included logic handle nickname collision bot. adds ^ @ end of name:

# fun, override method determines how nickname changed on # collisions. default method appends underscore. def altercollidednick(self, nickname):     """     generate altered version of nickname caused collision in     effort create unused related name subsequent registration.     """     return nickname + '^' 

this causing bots nickname end nickname^, , because used %s add nickname variable part of regex, interpreted ^ modifier.

if re.search(r'%s[:,] help' % self.nickname, msg): 

to this:

if re.search(r'nickname^[:,] help', msg): 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -