2013-01-19 18:37:14 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""
|
|
|
|
rutils.py - Phenny Utility Module
|
2014-06-22 12:32:15 +02:00
|
|
|
Copyright 2012, sfan5
|
2015-02-17 21:21:07 +01:00
|
|
|
Licensed under GNU General Public License v2.0
|
2013-01-19 18:37:14 +01:00
|
|
|
"""
|
2017-02-12 15:54:01 +01:00
|
|
|
import base64
|
|
|
|
import random
|
2013-01-19 18:37:14 +01:00
|
|
|
|
2013-06-01 18:44:40 +02:00
|
|
|
def rs(s):
|
|
|
|
return repr(s)[1:-1]
|
|
|
|
|
2014-06-22 12:32:15 +02:00
|
|
|
def rev(phenny, input):
|
2013-01-19 18:37:14 +01:00
|
|
|
"""reverse string"""
|
|
|
|
if not input.group(2):
|
|
|
|
return phenny.reply("Nothing to reverse.")
|
2014-07-20 16:13:59 +02:00
|
|
|
q = input.group(2)
|
2013-01-19 18:37:14 +01:00
|
|
|
s = ""
|
|
|
|
for i in range(1,len(q)):
|
|
|
|
s += q[-i]
|
|
|
|
s += q[0]
|
2013-06-01 18:44:40 +02:00
|
|
|
return phenny.say(rs(s))
|
2013-01-19 18:37:14 +01:00
|
|
|
|
2013-04-06 13:26:56 +02:00
|
|
|
rev.commands = ['rev','reverse']
|
2013-01-19 18:37:14 +01:00
|
|
|
rev.priority = 'low'
|
|
|
|
|
2014-06-28 16:08:20 +02:00
|
|
|
def make_thing(cmds, func):
|
|
|
|
def m(phenny, input):
|
|
|
|
if not input.group(2): return
|
2013-01-19 18:37:14 +01:00
|
|
|
q = input.group(2).encode('utf-8')
|
|
|
|
try:
|
2014-07-20 16:13:59 +02:00
|
|
|
phenny.say(rs(func(q).decode('utf-8')))
|
2013-01-19 18:37:14 +01:00
|
|
|
except BaseException as e:
|
2014-06-28 16:08:20 +02:00
|
|
|
phenny.reply("Failed to handle data")
|
|
|
|
m.commands = cmds
|
|
|
|
m.priority = "low"
|
|
|
|
return m
|
|
|
|
|
|
|
|
b64e = make_thing(['b64e','base64encode'], base64.b64encode)
|
|
|
|
b64d = make_thing(['b64d','base64decode'], base64.b64decode)
|
2013-01-19 18:37:14 +01:00
|
|
|
|
2014-06-22 12:32:15 +02:00
|
|
|
def rand(phenny, input):
|
2013-07-09 16:30:36 +02:00
|
|
|
"""Returns a random number"""
|
|
|
|
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")
|
2013-08-14 12:59:48 +02:00
|
|
|
if b < a:
|
|
|
|
tmp = a
|
|
|
|
a = b
|
|
|
|
b = tmp
|
|
|
|
del tmp
|
2013-07-15 08:57:10 +02:00
|
|
|
phenny.say(str(random.randrange(a, b)))
|
2013-07-09 16:30:36 +02:00
|
|
|
else:
|
|
|
|
try:
|
|
|
|
a = int(arg.split(" ")[0]) + 1
|
|
|
|
except ValueError:
|
|
|
|
return phenny.reply("Could not parse argument 1")
|
2013-07-15 08:57:10 +02:00
|
|
|
phenny.say(str(random.randrange(a)))
|
2013-07-09 16:30:36 +02:00
|
|
|
|
|
|
|
rand.commands = ['rand', 'random']
|
|
|
|
rand.priority = 'low'
|
|
|
|
|
2014-06-22 12:32:15 +02:00
|
|
|
if __name__ == '__main__':
|
2014-07-20 16:13:59 +02:00
|
|
|
print(__doc__.strip())
|