2018-07-02 13:45:25 +00:00
|
|
|
import random, uuid
|
2018-10-03 12:22:37 +00:00
|
|
|
from src import ModuleManager, utils
|
2016-03-29 13:32:01 +00:00
|
|
|
|
2019-02-12 15:23:02 +00:00
|
|
|
COIN_SIDES = ["heads", "tails"]
|
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2018-07-02 13:45:25 +00:00
|
|
|
_name = "Random"
|
2016-03-29 13:32:01 +00:00
|
|
|
|
2018-10-10 09:42:41 +00:00
|
|
|
@utils.hook("received.command.rand", alias_of="random")
|
|
|
|
@utils.hook("received.command.random")
|
2016-03-29 13:32:01 +00:00
|
|
|
def random(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Get a random number
|
|
|
|
:usage: [start] [end]
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2016-03-29 13:32:01 +00:00
|
|
|
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
|
|
|
|
2019-02-12 15:23:02 +00:00
|
|
|
@utils.hook("received.command.cointoss")
|
|
|
|
def coin_toss(self, event):
|
|
|
|
chosen_side = random.SystemRandom().choice(COIN_SIDES)
|
|
|
|
event["stdout"].write("%s tosses a coin and gets %s" %
|
|
|
|
(event["user"].nickname, chosen_side))
|
|
|
|
|
2019-05-07 10:48:16 +00:00
|
|
|
@utils.hook("received.command.uuid4")
|
2019-01-14 21:37:14 +00:00
|
|
|
def uuid(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2019-05-07 10:48:16 +00:00
|
|
|
:help: Get a random uuid4
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-07-02 13:45:25 +00:00
|
|
|
event["stdout"].write(str(uuid.uuid4()))
|