[RUtils] Add regex testing command
This commit is contained in:
parent
5f7b0ceb99
commit
efcc4241e9
@ -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>
|
||||
|
28
rutils.py
28
rutils.py
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user