2018-07-02 13:45:25 +00:00
|
|
|
import random, uuid
|
2016-03-29 13:32:01 +00:00
|
|
|
|
|
|
|
class Module(object):
|
2018-07-02 13:45:25 +00:00
|
|
|
_name = "Random"
|
2018-09-02 18:54:45 +00:00
|
|
|
def __init__(self, bot, events, exports):
|
2018-09-19 12:25:12 +00:00
|
|
|
events.on("received.command").on("random", "rand").hook(self.random,
|
|
|
|
help="Get a random number", usage="[start] [end]")
|
|
|
|
events.on("received.command.guid").hook(self.guid,
|
|
|
|
help="Get a random guid")
|
2016-03-29 13:32:01 +00:00
|
|
|
|
|
|
|
def random(self, event):
|
|
|
|
start, end = "1", "100"
|
|
|
|
if len(event["args_split"]) > 1:
|
|
|
|
start, end = event["args_split"][:2]
|
|
|
|
elif len(event["args_split"]) == 1:
|
|
|
|
end = event["args_split"][0]
|
|
|
|
if start.isdigit() and end.isdigit():
|
|
|
|
start, end = int(start), int(end)
|
|
|
|
if end > start:
|
|
|
|
number = random.randint(start, end)
|
|
|
|
event["stdout"].write("(%d-%d) %d" % (start, end,
|
|
|
|
number))
|
|
|
|
else:
|
|
|
|
event["stderr"].write(
|
|
|
|
"End must be greater than start")
|
|
|
|
else:
|
|
|
|
event["stderr"].write(
|
|
|
|
"Both start and end must be valid integers")
|
2018-07-02 13:45:25 +00:00
|
|
|
|
|
|
|
def guid(self, event):
|
|
|
|
event["stdout"].write(str(uuid.uuid4()))
|