[RUtils] Add regex testing command

master
Sfan5 2013-06-01 19:17:52 +02:00
parent 5f7b0ceb99
commit efcc4241e9
2 changed files with 28 additions and 1 deletions

View File

@ -49,6 +49,7 @@ Required arguments are enclosed in { and }, optional arguments are enclosed in \
<tr> <td>!unhex {string}</td> <td>Un-"Hexlify" a string</td> <td>Anyone</td> </tr>
<tr> <td>!uuencode {string}</td> <td>uuencode a string</td> <td>Anyone</td> </tr>
<tr> <td>!uudecode {string}</td> <td>uudecode a string</td> <td>Anyone</td> </tr>
<tr> <td>!re {regex}<i>\x02</i>{string}</td> <td>check if regex matches, if it does print groups</td> <td>Anyone</td> </tr>
<tr> <td><b>search.py</b></td> <td></td> <td></td> </tr>
<tr> <td>!g {string}</td> <td>Output first Google result for string</td> <td>Anyone</td> </tr>
<tr> <td>!gc {string}</td> <td>Output Google result count for string</td> <td>Anyone</td> </tr>

View File

@ -3,7 +3,7 @@
rutils.py - Phenny Utility Module
Copyright 2012, Sfan5
"""
import base64, binascii
import base64, binascii, re
def rs(s):
return repr(s)[1:-1]
@ -207,5 +207,31 @@ def uudecode(phenny, input):
uudecode.commands = ['ud','uudecode']
uudecode.priority = 'low'
def regex(phenny, input):
"""regex"""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
if not input.group(2):
return
q = input.group(2).encode('utf-8')
rgx = q[:q.find("\x02")]
msg = q[q.find("\x02"):]
if rgx == "" or msg == "":
return phenny.reply("Give me a regex and a message seperated by \x02")
try:
r = re.compile(rgx)
except BaseException as e:
return phenny.reply("Failed to compile regex: " + e.message)
m = r.match(msg)
if m == None:
return phenny.say("false")
else:
return phenny.say("true groups=[" + ', '.join((repr(e) for e in m.groups())) + "]")
regex.commands = ['re','regex']
regex.priority = 'low'
if __name__ == '__main__':
print __doc__.strip()