[RUtils] Add !rand command
This commit is contained in:
parent
9afe8f68ae
commit
5060f367fd
@ -50,6 +50,7 @@ Required arguments are enclosed in { and }, optional arguments are enclosed in \
|
||||
<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>`</i>{string}</td> <td>check if regex matches, if it does print groups</td> <td>Anyone</td> </tr>
|
||||
<tr> <td>!rand [min] {max}</td> <td>Says a random number between(incl.) min and max</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>
|
||||
|
31
rutils.py
31
rutils.py
@ -3,7 +3,7 @@
|
||||
rutils.py - Phenny Utility Module
|
||||
Copyright 2012, Sfan5
|
||||
"""
|
||||
import base64, binascii, re
|
||||
import base64, binascii, re, random
|
||||
|
||||
def rs(s):
|
||||
return repr(s)[1:-1]
|
||||
@ -233,5 +233,34 @@ def regex(phenny, input):
|
||||
regex.commands = ['re','regex']
|
||||
regex.priority = 'low'
|
||||
|
||||
def rand(phenny, input):
|
||||
"""Returns a random number"""
|
||||
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
|
||||
arg = input.group(2)
|
||||
if " " in arg:
|
||||
try:
|
||||
a = int(arg.split(" ")[0])
|
||||
except ValueError:
|
||||
return phenny.reply("Could not parse argument 1")
|
||||
try:
|
||||
b = int(arg.split(" ")[1]) + 1
|
||||
except ValueError:
|
||||
return phenny.reply("Could not parse argument 2")
|
||||
phenny.say(random.randrange(a, b))
|
||||
else:
|
||||
try:
|
||||
a = int(arg.split(" ")[0]) + 1
|
||||
except ValueError:
|
||||
return phenny.reply("Could not parse argument 1")
|
||||
phenny.say(random.randrange(a))
|
||||
|
||||
rand.commands = ['rand', 'random']
|
||||
rand.priority = 'low'
|
||||
|
||||
if __name__ == '__main__':
|
||||
print __doc__.strip()
|
||||
|
Loading…
x
Reference in New Issue
Block a user