aboutsummaryrefslogtreecommitdiff
path: root/modules/commands.py
diff options
context:
space:
mode:
Diffstat (limited to 'modules/commands.py')
-rw-r--r--modules/commands.py41
1 files changed, 21 insertions, 20 deletions
diff --git a/modules/commands.py b/modules/commands.py
index fbce393d..5084f690 100644
--- a/modules/commands.py
+++ b/modules/commands.py
@@ -45,27 +45,28 @@ class StdErr(Out):
self.module_name, Utils.FONT_RESET)
class Module(object):
- def __init__(self, bot):
+ def __init__(self, bot, events):
self.bot = bot
- bot.events.on("received").on("message").on("channel").hook(
+ self.events = events
+ events.on("received").on("message").on("channel").hook(
self.channel_message)
- bot.events.on("received").on("message").on("private").hook(
+ events.on("received").on("message").on("private").hook(
self.private_message)
- bot.events.on("received").on("command").on("help").hook(self.help,
+ events.on("received").on("command").on("help").hook(self.help,
help="Show help for commands", usage="<command>")
- bot.events.on("received").on("command").on("usage").hook(self.usage,
+ events.on("received").on("command").on("usage").hook(self.usage,
help="Show usage help for commands", min_args=1,
usage="<command>")
- bot.events.on("received").on("command").on("more").hook(self.more,
+ events.on("received").on("command").on("more").hook(self.more,
help="Get more output from the last command", skip_out=True)
- bot.events.on("postboot").on("configure").on(
+ events.on("postboot").on("configure").on(
"channelset").assure_call(setting="command-prefix",
help="Set the command prefix used in this channel")
- bot.events.on("new").on("user", "channel").hook(self.new)
- bot.events.on("send").on("stdout").hook(self.send_stdout)
- bot.events.on("send").on("stderr").hook(self.send_stderr)
+ events.on("new").on("user", "channel").hook(self.new)
+ events.on("send").on("stdout").hook(self.send_stdout)
+ events.on("send").on("stderr").hook(self.send_stderr)
def new(self, event):
if "user" in event:
@@ -76,10 +77,10 @@ class Module(object):
target.last_stderr = None
def has_command(self, command):
- return command.lower() in self.bot.events.on("received").on(
+ return command.lower() in self.events.on("received").on(
"command").get_children()
def get_hook(self, command):
- return self.bot.events.on("received").on("command").on(command
+ return self.events.on("received").on("command").on(command
).get_hooks()[0]
def is_highlight(self, server, s):
@@ -108,7 +109,7 @@ class Module(object):
stdout, stderr = StdOut(module_name, target), StdErr(module_name,
target)
- returns = self.bot.events.on("preprocess").on("command"
+ returns = self.events.on("preprocess").on("command"
).call(hook=hook, user=event["user"], server=event["server"],
target=target, is_channel=is_channel)
for returned in returns:
@@ -129,7 +130,7 @@ class Module(object):
args = " ".join(args_split)
server = event["server"]
user = event["user"]
- self.bot.events.on("received").on("command").on(command
+ self.events.on("received").on("command").on(command
).call_limited(1, user=user, server=server,
target=target, buffer=buffer, args=args,
args_split=args_split, stdout=stdout, stderr=stderr,
@@ -162,9 +163,9 @@ class Module(object):
def help(self, event):
if event["args"]:
command = event["args_split"][0].lower()
- if command in self.bot.events.on("received").on(
+ if command in self.events.on("received").on(
"command").get_children():
- hooks = self.bot.events.on("received").on("command").on(command).get_hooks()
+ hooks = self.events.on("received").on("command").on(command).get_hooks()
if hooks and "help" in hooks[0].kwargs:
event["stdout"].write("%s: %s" % (command, hooks[0].kwargs["help"]))
else:
@@ -173,8 +174,8 @@ class Module(object):
event["stderr"].write("Unknown command '%s'" % command)
else:
help_available = []
- for child in self.bot.events.on("received").on("command").get_children():
- hooks = self.bot.events.on("received").on("command").on(child).get_hooks()
+ for child in self.events.on("received").on("command").get_children():
+ hooks = self.events.on("received").on("command").on(child).get_hooks()
if hooks and "help" in hooks[0].kwargs:
help_available.append(child)
help_available = sorted(help_available)
@@ -182,9 +183,9 @@ class Module(object):
def usage(self, event):
command = event["args_split"][0].lower()
- if command in self.bot.events.on("received").on(
+ if command in self.events.on("received").on(
"command").get_children():
- hooks = self.bot.events.on("received").on("command").on(command).get_hooks()
+ hooks = self.events.on("received").on("command").on(command).get_hooks()
if hooks and "usage" in hooks[0].kwargs:
event["stdout"].write("Usage: %s %s" % (command, hooks[0].kwargs["usage"]))
else: