added random.py, added code to commands.py to remove all empty strings from args_split.

This commit is contained in:
jesopo 2016-03-29 14:32:01 +01:00
parent cd0311d269
commit bf0e271546
No known key found for this signature in database
GPG key ID: 0BBDEB2AEFCFFCB3
2 changed files with 27 additions and 1 deletions

View file

@ -83,7 +83,8 @@ class Module(object):
event["stderr"].write(returned).send()
return
min_args = hook.kwargs.get("min_args")
args_split = event["message_split"][1:]
# get rid of all the empty strings
args_split = list(filter(None, event["message_split"][1:]))
if min_args and len(args_split) < min_args:
ChannelStdErr("Error", event["channel"]
).write("Not enough arguments ("

25
modules/random.py Normal file
View file

@ -0,0 +1,25 @@
import random
class Module(object):
def __init__(self, bot):
bot.events.on("received").on("command").on("random",
"rand").hook(self.random)
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")