Give modules event objects with "context"s, to facilitate purging all the event

hooks for a module
This commit is contained in:
jesopo 2018-08-31 12:55:52 +01:00
parent 9cd4e86750
commit 9874f79b49
67 changed files with 476 additions and 440 deletions

View file

@ -1,10 +1,13 @@
import time, traceback import itertools, time, traceback
PRIORITY_URGENT = 0 PRIORITY_URGENT = 0
PRIORITY_HIGH = 1 PRIORITY_HIGH = 1
PRIORITY_MEDIUM = 2 PRIORITY_MEDIUM = 2
PRIORITY_LOW = 3 PRIORITY_LOW = 3
DEFAULT_PRIORITY = PRIORITY_LOW
DEFAULT_DELIMITER = "."
class Event(object): class Event(object):
def __init__(self, bot, name, **kwargs): def __init__(self, bot, name, **kwargs):
self.bot = bot self.bot = bot
@ -21,7 +24,7 @@ class Event(object):
self.eaten = True self.eaten = True
class EventCallback(object): class EventCallback(object):
def __init__(self, function, bot, priority, **kwargs): def __init__(self, function, bot, priority, kwargs):
self.function = function self.function = function
self.bot = bot self.bot = bot
self.priority = priority self.priority = priority
@ -50,6 +53,28 @@ class MultipleEventHook(object):
returns.append(event_hook.call(**kwargs)) returns.append(event_hook.call(**kwargs))
return returns return returns
class EventHookContext(object):
def __init__(self, parent, context):
self._parent = parent
self.context = context
def hook(self, function, priority=DEFAULT_PRIORITY, **kwargs):
self._parent._context_hook(self.context, function, priority, kwargs)
def on(self, subevent, *extra_subevents, delimiter=DEFAULT_DELIMITER):
return self._parent._context_on(self.context, subevent,
extra_subevents, delimiter)
def call_for_result(self, default=None, **kwargs):
return self._parent.call_for_result(default, **kwargs)
def assure_call(self, **kwargs):
self._parent.assure_call(**kwargs)
def call(self, **kwargs):
return self._parent.call(**kwargs)
def call_limited(self, maximum, **kwargs):
return self._parent.call_limited(maximum, **kwargs)
def get_hooks(self):
return self._parent.get_hooks()
def get_children(self):
return self._parent.get_children()
class EventHook(object): class EventHook(object):
def __init__(self, bot, name=None, parent=None): def __init__(self, bot, name=None, parent=None):
self.bot = bot self.bot = bot
@ -57,10 +82,9 @@ class EventHook(object):
self.parent = parent self.parent = parent
self._children = {} self._children = {}
self._hooks = [] self._hooks = []
self._hook_notify = None
self._child_notify = None
self._call_notify = None
self._stored_events = [] self._stored_events = []
self._context_hooks = {}
self._current_context = None
def _make_event(self, kwargs): def _make_event(self, kwargs):
return Event(self.bot, self.name, **kwargs) return Event(self.bot, self.name, **kwargs)
@ -71,14 +95,28 @@ class EventHook(object):
while not parent == None and not parent.name == None: while not parent == None and not parent.name == None:
path.append(parent.name) path.append(parent.name)
parent = parent.parent parent = parent.parent
return ".".join(path[::-1]) return DEFAULT_DELIMITER.join(path[::-1])
def hook(self, function, priority=PRIORITY_LOW, replay=False, **kwargs): def new_context(self, context):
callback = EventCallback(function, self.bot, priority, **kwargs) return EventHookContext(self, context)
if self._hook_notify:
self._hook_notify(self, callback) def hook(self, function, priority=DEFAULT_PRIORITY, replay=False,
**kwargs):
self._hook(function, None, priority, replay, kwargs)
def _context_hook(self, context, function, priority, kwargs):
self._hook(function, context, priority, False, kwargs)
def _hook(self, function, context, priority, replay, kwargs):
callback = EventCallback(function, self.bot, priority, kwargs)
if context == None:
self._hooks.append(callback) self._hooks.append(callback)
self._hooks.sort(key=lambda x: x.priority) hooks = self._hooks
else:
if not context in self._context_hooks:
self._context_hooks[context] = []
self._context_hooks[context].append(callback)
hooks = self._context_hooks[context]
hooks.sort(key=lambda x: x.priority)
if replay and not self._stored_events == None: if replay and not self._stored_events == None:
for kwargs in self._stored_events: for kwargs in self._stored_events:
@ -88,24 +126,37 @@ class EventHook(object):
def _unhook(self, hook): def _unhook(self, hook):
self._hooks.remove(hook) self._hooks.remove(hook)
def on(self, subevent, *extra_subevents, delimiter="."): def on(self, subevent, *extra_subevents, delimiter=DEFAULT_DELIMITER):
return self._on(subevent, extra_subevents, None, delimiter)
def _context_on(self, context, subevent, extra_subevents,
delimiter=DEFAULT_DELIMITER):
return self._on(subevent, extra_subevents, context, delimiter)
def _on(self, subevent, extra_subevents, context, delimiter):
if delimiter in subevent: if delimiter in subevent:
event_chain = subevent.split(delimiter) event_chain = subevent.split(delimiter)
event_obj = self event_obj = self
for event_name in event_chain: for event_name in event_chain:
event_obj = event_obj.get_child(event_name) event_obj = event_obj.get_child(event_name)
if not context == None:
event_obj = event_obj.new_context(context)
return event_obj return event_obj
if extra_subevents: if extra_subevents:
multiple_event_hook = MultipleEventHook() multiple_event_hook = MultipleEventHook()
for extra_subevent in (subevent,)+extra_subevents: for extra_subevent in (subevent,)+extra_subevents:
multiple_event_hook._add(self.get_child(extra_subevent)) child = self.get_child(extra_subevent)
if not context == None:
child = child.new_context(context)
multiple_event_hook._add(child)
return multiple_event_hook return multiple_event_hook
return self.get_child(subevent) child = self.get_child(subevent)
if not context == None:
child = child.new_context(context)
return child
def call_for_result(self, default=None, max=None, **kwargs): def call_for_result(self, default=None, **kwargs):
results = self.call(max=max, **kwargs) results = self.call_limited(0, **kwargs)
return default if not len(results) else results[0] return default if not len(results) else results[0]
def assure_call(self, **kwargs): def assure_call(self, **kwargs):
if not self._stored_events == None: if not self._stored_events == None:
@ -123,15 +174,10 @@ class EventHook(object):
start = time.monotonic() start = time.monotonic()
event = self._make_event(kwargs) event = self._make_event(kwargs)
if self._call_notify:
self._call_notify(self, event)
called = 0 called = 0
returns = [] returns = []
for hook in self._hooks: for hook in self.get_hooks():
if maximum and called == maximum: if (maximum and called == maximum) or event.eaten:
break
if event.eaten:
break break
try: try:
returns.append(hook.call(event)) returns.append(hook.call(event))
@ -155,28 +201,30 @@ class EventHook(object):
if not child_name_lower in self._children: if not child_name_lower in self._children:
self._children[child_name_lower] = EventHook(self.bot, self._children[child_name_lower] = EventHook(self.bot,
child_name_lower, self) child_name_lower, self)
if self._child_notify:
self._child_notify(self, self._children[
child_name_lower])
return self._children[child_name_lower] return self._children[child_name_lower]
def remove_child(self, child_name): def remove_child(self, child_name):
child_name_lower = child_name.lower() child_name_lower = child_name.lower()
if child_name_lower in self._children: if child_name_lower in self._children:
del self._children[child_name_lower] del self._children[child_name_lower]
def get_children(self):
return self._children.keys()
def check_purge(self): def check_purge(self):
if len(self._hooks) == 0 and len(self._children if len(self._hooks) == 0 and len(self._children
) == 0 and not self.parent == None: ) == 0 and not self.parent == None:
self.parent.remove_child(self.name) self.parent.remove_child(self.name)
self.parent.check_purge() self.parent.check_purge()
def remove_context(self, context):
del self._context_hooks[context]
def has_context(self, context):
return context in self._context_hooks
def purge_context(self, context):
if self.has_context(context):
self.remove_context(context)
for child in self.get_children():
child.purge_context(context)
def get_hooks(self): def get_hooks(self):
return self._hooks return self._hooks + list(itertools.chain.from_iterable(
def get_children(self): self._context_hooks.values()))
return self._children.keys()
def set_hook_notify(self, handler):
self._hook_notify = handler
def set_child_notify(self, handler):
self._child_notify = handler
def set_call_notify(self, handler):
self._call_notify = handler

View file

@ -1,4 +1,4 @@
import os, select, sys, threading, time, traceback import os, select, sys, threading, time, traceback, uuid
import EventManager, IRCLineHandler, IRCLogging, IRCServer import EventManager, IRCLineHandler, IRCLogging, IRCServer
import ModuleManager, Timer import ModuleManager, Timer
@ -13,21 +13,21 @@ class Bot(object):
self.servers = {} self.servers = {}
self.running = True self.running = True
self.poll = select.epoll() self.poll = select.epoll()
self.modules = ModuleManager.ModuleManager(self) self._events = EventManager.EventHook(self)
self.events = EventManager.EventHook(self) self.modules = ModuleManager.ModuleManager(self, self._events)
self.log = IRCLogging.Log(self) self.log = IRCLogging.Log(self)
self.line_handler = IRCLineHandler.LineHandler(self) self.line_handler = IRCLineHandler.LineHandler(self, self._events)
self.timers = [] self.timers = []
self.events.on("timer").on("reconnect").hook(self.reconnect) self._events.on("timer").on("reconnect").hook(self.reconnect)
self.events.on("boot").on("done").hook(self.setup_timers) self._events.on("boot").on("done").hook(self.setup_timers)
def add_server(self, id, hostname, port, password, ipv4, tls, def add_server(self, id, hostname, port, password, ipv4, tls,
nickname, username, realname, connect=False): nickname, username, realname, connect=False):
new_server = IRCServer.Server(id, hostname, port, password, new_server = IRCServer.Server(self, self._events, id, hostname,
ipv4, tls, nickname, username, realname, self) port, password, ipv4, tls, nickname, username, realname)
if not new_server.get_setting("connect", True): if not new_server.get_setting("connect", True):
return return
self.events.on("new").on("server").call(server=new_server) self._events.on("new").on("server").call(server=new_server)
if connect and new_server.get_setting("connect", True): if connect and new_server.get_setting("connect", True):
self.connect(new_server) self.connect(new_server)
return new_server return new_server
@ -55,7 +55,9 @@ class Bot(object):
self.del_setting("timer-%s" % timer.id) self.del_setting("timer-%s" % timer.id)
def add_timer(self, event_name, delay, next_due=None, id=None, persist=True, def add_timer(self, event_name, delay, next_due=None, id=None, persist=True,
**kwargs): **kwargs):
timer = Timer.Timer(self, event_name, delay, next_due, **kwargs) id = id or uuid.uuid4().hex
timer = Timer.Timer(id, self, self._events, event_name, delay,
next_due, **kwargs)
if id: if id:
timer.id = id timer.id = id
elif persist: elif persist:

View file

@ -8,47 +8,38 @@ RE_CHANTYPES = re.compile(r"\bCHANTYPES=(\W+)(?:\b|$)")
RE_MODES = re.compile(r"[-+]\w+") RE_MODES = re.compile(r"[-+]\w+")
class LineHandler(object): class LineHandler(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("raw").on("PING").hook(self.ping) self.events = events
events.on("raw").on("PING").hook(self.ping)
bot.events.on("raw").on("001").hook(self.handle_001, events.on("raw").on("001").hook(self.handle_001, default_event=True)
default_event=True) events.on("raw").on("005").hook(self.handle_005)
bot.events.on("raw").on("005").hook(self.handle_005) events.on("raw").on("311").hook(self.handle_311, default_event=True)
bot.events.on("raw").on("311").hook(self.handle_311, events.on("raw").on("332").hook(self.handle_332)
default_event=True) events.on("raw").on("333").hook(self.handle_333)
bot.events.on("raw").on("332").hook(self.handle_332) events.on("raw").on("353").hook(self.handle_353, default_event=True)
bot.events.on("raw").on("333").hook(self.handle_333) events.on("raw").on("366").hook(self.handle_366, default_event=True)
bot.events.on("raw").on("353").hook(self.handle_353, events.on("raw").on("421").hook(self.handle_421, default_event=True)
default_event=True) events.on("raw").on("352").hook(self.handle_352, default_event=True)
bot.events.on("raw").on("366").hook(self.handle_366, events.on("raw").on("324").hook(self.handle_324, default_event=True)
default_event=True) events.on("raw").on("329").hook(self.handle_329, default_event=True)
bot.events.on("raw").on("421").hook(self.handle_421, events.on("raw").on("433").hook(self.handle_433, default_event=True)
default_event=True) events.on("raw").on("477").hook(self.handle_477, default_event=True)
bot.events.on("raw").on("352").hook(self.handle_352,
default_event=True)
bot.events.on("raw").on("324").hook(self.handle_324,
default_event=True)
bot.events.on("raw").on("329").hook(self.handle_329,
default_event=True)
bot.events.on("raw").on("433").hook(self.handle_433,
default_event=True)
bot.events.on("raw").on("477").hook(self.handle_477,
default_event=True)
bot.events.on("raw").on("JOIN").hook(self.join) events.on("raw").on("JOIN").hook(self.join)
bot.events.on("raw").on("PART").hook(self.part) events.on("raw").on("PART").hook(self.part)
bot.events.on("raw").on("QUIT").hook(self.quit) events.on("raw").on("QUIT").hook(self.quit)
bot.events.on("raw").on("NICK").hook(self.nick) events.on("raw").on("NICK").hook(self.nick)
bot.events.on("raw").on("MODE").hook(self.mode) events.on("raw").on("MODE").hook(self.mode)
bot.events.on("raw").on("KICK").hook(self.kick) events.on("raw").on("KICK").hook(self.kick)
bot.events.on("raw").on("INVITE").hook(self.invite) events.on("raw").on("INVITE").hook(self.invite)
bot.events.on("raw").on("TOPIC").hook(self.topic) events.on("raw").on("TOPIC").hook(self.topic)
bot.events.on("raw").on("PRIVMSG").hook(self.privmsg) events.on("raw").on("PRIVMSG").hook(self.privmsg)
bot.events.on("raw").on("NOTICE").hook(self.notice) events.on("raw").on("NOTICE").hook(self.notice)
bot.events.on("raw").on("CAP").hook(self.cap) events.on("raw").on("CAP").hook(self.cap)
bot.events.on("raw").on("authenticate").hook(self.authenticate) events.on("raw").on("authenticate").hook(self.authenticate)
def handle(self, server, line): def handle(self, server, line):
original_line = line original_line = line
@ -66,7 +57,7 @@ class LineHandler(object):
line = line[:-1] line = line[:-1]
args = line.split(" ") args = line.split(" ")
hooks = self.bot.events.on("raw").on(command).get_hooks() hooks = self.events.on("raw").on(command).get_hooks()
default_event = False default_event = False
for hook in hooks: for hook in hooks:
if hook.kwargs.get("default_event", False): if hook.kwargs.get("default_event", False):
@ -74,15 +65,15 @@ class LineHandler(object):
break break
#server, prefix, command, args, arbitrary #server, prefix, command, args, arbitrary
self.bot.events.on("raw").on(command).call(server=server, self.events.on("raw").on(command).call(server=server,
prefix=prefix, args=args, arbitrary=arbitrary) prefix=prefix, args=args, arbitrary=arbitrary)
if default_event or not hooks: if default_event or not hooks:
if command.isdigit(): if command.isdigit():
self.bot.events.on("received").on("numeric").on(command self.events.on("received").on("numeric").on(command
).call(line=original_line, server=server, ).call(line=original_line, server=server,
line_split=original_line.split(" "), number=command) line_split=original_line.split(" "), number=command)
else: else:
self.bot.events.on("received").on(command).call( self.events.on("received").on(command).call(
line=original_line, line_split=original_line.split(" "), line=original_line, line_split=original_line.split(" "),
command=command, server=server) command=command, server=server)
@ -116,7 +107,7 @@ class LineHandler(object):
match = re.search(RE_CHANTYPES, isupport_line) match = re.search(RE_CHANTYPES, isupport_line)
if match: if match:
event["server"].channel_types = list(match.group(1)) event["server"].channel_types = list(match.group(1))
self.bot.events.on("received").on("numeric").on("005").call( self.events.on("received").on("numeric").on("005").call(
isupport=isupport_line, server=event["server"]) isupport=isupport_line, server=event["server"])
# whois respose (nickname, username, realname, hostname) # whois respose (nickname, username, realname, hostname)
@ -135,7 +126,7 @@ class LineHandler(object):
channel = event["server"].get_channel(event["args"][1]) channel = event["server"].get_channel(event["args"][1])
channel.set_topic(event["arbitrary"]) channel.set_topic(event["arbitrary"])
self.bot.events.on("received").on("numeric").on("332" self.events.on("received").on("numeric").on("332"
).call(channel=channel, server=event["server"], ).call(channel=channel, server=event["server"],
topic=event["arbitrary"]) topic=event["arbitrary"])
@ -147,7 +138,7 @@ class LineHandler(object):
channel = event["server"].get_channel(event["args"][0]) channel = event["server"].get_channel(event["args"][0])
channel.set_topic(event["arbitrary"]) channel.set_topic(event["arbitrary"])
self.bot.events.on("received").on("topic").call(channel=channel, self.events.on("received").on("topic").call(channel=channel,
server=event["server"], topic=event["arbitrary"], user=user) server=event["server"], topic=event["arbitrary"], user=user)
# on-join channel topic set by/at # on-join channel topic set by/at
@ -162,7 +153,7 @@ class LineHandler(object):
channel.set_topic_setter(nickname, username, hostname) channel.set_topic_setter(nickname, username, hostname)
channel.set_topic_time(topic_time) channel.set_topic_time(topic_time)
self.bot.events.on("received").on("numeric").on("333" self.events.on("received").on("numeric").on("333"
).call(channel=channel, setter=nickname, set_at=topic_time, ).call(channel=channel, setter=nickname, set_at=topic_time,
server=event["server"]) server=event["server"])
@ -202,12 +193,12 @@ class LineHandler(object):
user.hostname = hostname user.hostname = hostname
channel.add_user(user) channel.add_user(user)
user.join_channel(channel) user.join_channel(channel)
self.bot.events.on("received").on("join").call(channel=channel, self.events.on("received").on("join").call(channel=channel,
user=user, server=event["server"]) user=user, server=event["server"])
else: else:
if channel.name in event["server"].attempted_join: if channel.name in event["server"].attempted_join:
del event["server"].attempted_join[channel.name] del event["server"].attempted_join[channel.name]
self.bot.events.on("self").on("join").call(channel=channel, self.events.on("self").on("join").call(channel=channel,
server=event["server"]) server=event["server"])
channel.send_mode() channel.send_mode()
@ -220,7 +211,7 @@ class LineHandler(object):
if not event["server"].is_own_nickname(nickname): if not event["server"].is_own_nickname(nickname):
user = event["server"].get_user(nickname) user = event["server"].get_user(nickname)
self.bot.events.on("received").on("part").call(channel=channel, self.events.on("received").on("part").call(channel=channel,
reason=reason, user=user, server=event["server"]) reason=reason, user=user, server=event["server"])
channel.remove_user(user) channel.remove_user(user)
user.part_channel(channel) user.part_channel(channel)
@ -228,7 +219,7 @@ class LineHandler(object):
event["server"].remove_user(user) event["server"].remove_user(user)
else: else:
event["server"].remove_channel(channel) event["server"].remove_channel(channel)
self.bot.events.on("self").on("part").call(channel=channel, self.events.on("self").on("part").call(channel=channel,
reason=reason, server=event["server"]) reason=reason, server=event["server"])
# unknown command sent by us, oops! # unknown command sent by us, oops!
@ -244,7 +235,7 @@ class LineHandler(object):
if not event["server"].is_own_nickname(nickname): if not event["server"].is_own_nickname(nickname):
user = event["server"].get_user(nickname) user = event["server"].get_user(nickname)
event["server"].remove_user(user) event["server"].remove_user(user)
self.bot.events.on("received").on("quit").call(reason=reason, self.events.on("received").on("quit").call(reason=reason,
user=user, server=event["server"]) user=user, server=event["server"])
else: else:
event["server"].disconnect() event["server"].disconnect()
@ -252,13 +243,13 @@ class LineHandler(object):
# the server is telling us about its capabilities! # the server is telling us about its capabilities!
def cap(self, event): def cap(self, event):
capabilities = (event["arbitrary"] or "").split(" ") capabilities = (event["arbitrary"] or "").split(" ")
self.bot.events.on("received").on("cap").call( self.events.on("received").on("cap").call(
subcommand=event["args"][1], capabilities=capabilities, subcommand=event["args"][1], capabilities=capabilities,
server=event["server"]) server=event["server"])
# the server is asking for authentication # the server is asking for authentication
def authenticate(self, event): def authenticate(self, event):
self.bot.events.on("received").on("authenticate").call( self.events.on("received").on("authenticate").call(
message=event["args"][0], server=event["server"]) message=event["args"][0], server=event["server"])
# someone has changed their nickname # someone has changed their nickname
@ -271,13 +262,13 @@ class LineHandler(object):
old_nickname = user.nickname old_nickname = user.nickname
user.set_nickname(new_nickname) user.set_nickname(new_nickname)
event["server"].change_user_nickname(old_nickname, new_nickname) event["server"].change_user_nickname(old_nickname, new_nickname)
self.bot.events.on("received").on("nick").call( self.events.on("received").on("nick").call(
new_nickname=new_nickname, old_nickname=old_nickname, new_nickname=new_nickname, old_nickname=old_nickname,
user=user, server=event["server"]) user=user, server=event["server"])
else: else:
old_nickname = event["server"].nickname old_nickname = event["server"].nickname
event["server"].set_own_nickname(new_nickname) event["server"].set_own_nickname(new_nickname)
self.bot.events.on("self").on("nick").call( self.events.on("self").on("nick").call(
server=event["server"], new_nickname=new_nickname, server=event["server"], new_nickname=new_nickname,
old_nickname=old_nickname) old_nickname=old_nickname)
@ -303,7 +294,7 @@ class LineHandler(object):
channel.change_mode(remove, mode, args.pop(0)) channel.change_mode(remove, mode, args.pop(0))
else: else:
args.pop(0) args.pop(0)
self.bot.events.on("received").on("mode").call(modes=modes, self.events.on("received").on("mode").call(modes=modes,
mode_args=args, channel=channel, server=event["server"]) mode_args=args, channel=channel, server=event["server"])
elif event["server"].is_own_nickname(target): elif event["server"].is_own_nickname(target):
modes = RE_MODES.findall(event["arbitrary"] or args[1]) modes = RE_MODES.findall(event["arbitrary"] or args[1])
@ -311,7 +302,7 @@ class LineHandler(object):
remove = chunk[0] == "-" remove = chunk[0] == "-"
for mode in chunk[1:]: for mode in chunk[1:]:
event["server"].change_own_mode(remove, mode) event["server"].change_own_mode(remove, mode)
self.bot.events.on("self").on("mode").call(modes=modes, self.events.on("self").on("mode").call(modes=modes,
server=event["server"]) server=event["server"])
# I've been invited somewhere # I've been invited somewhere
@ -320,7 +311,7 @@ class LineHandler(object):
event["prefix"]) event["prefix"])
target_channel = event["arbitrary"] target_channel = event["arbitrary"]
user = event["server"].get_user(nickname) user = event["server"].get_user(nickname)
self.bot.events.on("received").on("invite").call( self.events.on("received").on("invite").call(
user=user, target_channel=target_channel, user=user, target_channel=target_channel,
server=event["server"]) server=event["server"])
@ -337,12 +328,12 @@ class LineHandler(object):
message = message.replace("\01ACTION ", "", 1)[:-1] message = message.replace("\01ACTION ", "", 1)[:-1]
if target[0] in event["server"].channel_types: if target[0] in event["server"].channel_types:
channel = event["server"].get_channel(event["args"][0]) channel = event["server"].get_channel(event["args"][0])
self.bot.events.on("received").on("message").on("channel").call( self.events.on("received").on("message").on("channel").call(
user=user, message=message, message_split=message_split, user=user, message=message, message_split=message_split,
channel=channel, action=action, server=event["server"]) channel=channel, action=action, server=event["server"])
channel.buffer.add_line(user.nickname, message, action) channel.buffer.add_line(user.nickname, message, action)
elif event["server"].is_own_nickname(target): elif event["server"].is_own_nickname(target):
self.bot.events.on("received").on("message").on("private").call( self.events.on("received").on("message").on("private").call(
user=user, message=message, message_split=message_split, user=user, message=message, message_split=message_split,
action=action, server=event["server"]) action=action, server=event["server"])
user.buffer.add_line(user.nickname, message, action) user.buffer.add_line(user.nickname, message, action)
@ -355,18 +346,18 @@ class LineHandler(object):
message_split = message.split(" ") message_split = message.split(" ")
target = event["args"][0] target = event["args"][0]
if nickname == event["server"].name or target == "*": if nickname == event["server"].name or target == "*":
self.bot.events.on("received.server-notice").call( self.events.on("received.server-notice").call(
message=message, message_split=message_split, message=message, message_split=message_split,
server=event["server"]) server=event["server"])
else: else:
user = event["server"].get_user(nickname) user = event["server"].get_user(nickname)
if target[0] in event["server"].channel_types: if target[0] in event["server"].channel_types:
channel = event["server"].get_channel(target) channel = event["server"].get_channel(target)
self.bot.events.on("received.notice.channel").call( self.events.on("received.notice.channel").call(
message=message, message_split=message_split, message=message, message_split=message_split,
user=user, server=event["server"], channel=channel) user=user, server=event["server"], channel=channel)
elif event["server"].is_own_nickname(target): elif event["server"].is_own_nickname(target):
self.bot.events.on("received.notice.private").call( self.events.on("received.notice.private").call(
message=message, message_split=message_split, message=message, message_split=message_split,
user=user, server=event["server"]) user=user, server=event["server"])
@ -413,9 +404,9 @@ class LineHandler(object):
if not event["server"].is_own_nickname(target): if not event["server"].is_own_nickname(target):
target_user = event["server"].get_user(target) target_user = event["server"].get_user(target)
self.bot.events.on("received").on("kick").call(channel=channel, self.events.on("received").on("kick").call(channel=channel,
reason=reason, target_user=target_user, user=user, reason=reason, target_user=target_user, user=user,
server=event["server"]) server=event["server"])
else: else:
self.bot.events.on("self").on("kick").call(channel=channel, self.events.on("self").on("kick").call(channel=channel,
reason=reason, user=user, server=event["server"]) reason=reason, user=user, server=event["server"])

View file

@ -11,10 +11,11 @@ if hasattr(ssl, "PROTOCOL_TLS"):
OUR_TLS_PROTOCOL = ssl.PROTOCOL_TLS OUR_TLS_PROTOCOL = ssl.PROTOCOL_TLS
class Server(object): class Server(object):
def __init__(self, id, hostname, port, password, ipv4, tls, def __init__(self, bot, events, id, hostname, port, password, ipv4,
nickname, username, realname, bot): tls, nickname, username, realname):
self.connected = False self.connected = False
self.bot = bot self.bot = bot
self.events = events
self.id = id self.id = id
self.target_hostname = hostname self.target_hostname = hostname
self.port = port self.port = port
@ -65,7 +66,7 @@ class Server(object):
context.options |= ssl.OP_NO_TLSv1 context.options |= ssl.OP_NO_TLSv1
self.socket = context.wrap_socket(self.socket) self.socket = context.wrap_socket(self.socket)
self.cached_fileno = self.socket.fileno() self.cached_fileno = self.socket.fileno()
self.bot.events.on("timer").on("rejoin").hook(self.try_rejoin) self.events.on("timer").on("rejoin").hook(self.try_rejoin)
def __repr__(self): def __repr__(self):
return "IRCServer.Server(%s)" % self.__str__() return "IRCServer.Server(%s)" % self.__str__()
@ -78,7 +79,7 @@ class Server(object):
def connect(self): def connect(self):
self.socket.connect((self.target_hostname, self.port)) self.socket.connect((self.target_hostname, self.port))
self.bot.events.on("preprocess.connect").call(server=self) self.events.on("preprocess.connect").call(server=self)
if self.password: if self.password:
self.send_pass(self.password) self.send_pass(self.password)
@ -137,7 +138,7 @@ class Server(object):
if not self.has_user(nickname): if not self.has_user(nickname):
user_id = self.get_user_id(nickname) user_id = self.get_user_id(nickname)
new_user = IRCUser.User(nickname, user_id, self, self.bot) new_user = IRCUser.User(nickname, user_id, self, self.bot)
self.bot.events.on("new").on("user").call( self.events.on("new").on("user").call(
user=new_user, server=self) user=new_user, server=self)
self.users[new_user.nickname_lower] = new_user self.users[new_user.nickname_lower] = new_user
self.new_users.add(new_user) self.new_users.add(new_user)
@ -162,7 +163,7 @@ class Server(object):
channel_id = self.get_channel_id(channel_name) channel_id = self.get_channel_id(channel_name)
new_channel = IRCChannel.Channel(channel_name, channel_id, new_channel = IRCChannel.Channel(channel_name, channel_id,
self, self.bot) self, self.bot)
self.bot.events.on("new").on("channel").call( self.events.on("new").on("channel").call(
channel=new_channel, server=self) channel=new_channel, server=self)
self.channels[new_channel.name] = new_channel self.channels[new_channel.name] = new_channel
return self.channels[channel_name.lower()] return self.channels[channel_name.lower()]
@ -311,13 +312,13 @@ class Server(object):
if self.has_channel(target): if self.has_channel(target):
channel = self.get_channel(target) channel = self.get_channel(target)
channel.buffer.add_line(None, message, action, True) channel.buffer.add_line(None, message, action, True)
self.bot.events.on("self").on("message").on("channel").call( self.events.on("self").on("message").on("channel").call(
message=full_message, message_split=full_message_split, message=full_message, message_split=full_message_split,
channel=channel, action=action, server=self) channel=channel, action=action, server=self)
else: else:
user = self.get_user(target) user = self.get_user(target)
user.buffer.add_line(None, message, action, True) user.buffer.add_line(None, message, action, True)
self.bot.events.on("self").on("message").on("private").call( self.events.on("self").on("message").on("private").call(
message=full_message, message_split=full_message_split, message=full_message, message_split=full_message_split,
user=user, action=action, server=self) user=user, action=action, server=self)

View file

@ -1,8 +1,9 @@
import gc, glob, imp, inspect, os, sys import gc, glob, imp, inspect, os, sys, uuid
class ModuleManager(object): class ModuleManager(object):
def __init__(self, bot, directory="modules"): def __init__(self, bot, events, directory="modules"):
self.bot = bot self.bot = bot
self.events = events
self.directory = directory self.directory = directory
self.modules = {} self.modules = {}
self.waiting_requirement = {} self.waiting_requirement = {}
@ -39,17 +40,22 @@ class ModuleManager(object):
return None return None
else: else:
break break
import_name = "bitbot_%s" % name module = imp.load_source(name, filename)
module = imp.load_source(import_name, filename)
if not hasattr(module, "Module"): if not hasattr(module, "Module"):
raise ImportError("module '%s' doesn't have a Module class.") raise ImportError("module '%s' doesn't have a Module class.")
if not inspect.isclass(module.Module): if not inspect.isclass(module.Module):
raise ImportError("module '%s' has a Module attribute but it is not a class.") raise ImportError("module '%s' has a Module attribute but it is not a class.")
module_object = module.Module(self.bot)
event_context = uuid.uuid4()
module_object = module.Module(self.bot, self.events.new_context(
event_context))
if not hasattr(module_object, "_name"): if not hasattr(module_object, "_name"):
module_object._name = name.title() module_object._name = name.title()
module_object._event_context = event_context
module_object._is_unloaded = False module_object._is_unloaded = False
module_object._import_name = import_name module_object._import_name = name
assert not module_object._name in self.modules, ( assert not module_object._name in self.modules, (
"module name '%s' attempted to be used twice.") "module name '%s' attempted to be used twice.")
return module_object return module_object
@ -62,7 +68,7 @@ class ModuleManager(object):
sys.stderr.write("module '%s' not loaded: Could not resolve import.\n" % filename) sys.stderr.write("module '%s' not loaded: Could not resolve import.\n" % filename)
return return
if module: if module:
self.modules[module._name] = module self.modules[module._import_name] = module
if name in self.waiting_requirement: if name in self.waiting_requirement:
for filename in self.waiting_requirement: for filename in self.waiting_requirement:
self.load_module(filename) self.load_module(filename)
@ -74,23 +80,3 @@ class ModuleManager(object):
for filename in self.list_modules(): for filename in self.list_modules():
if whitelist == None or filename in whitelist: if whitelist == None or filename in whitelist:
self.load_module(filename) self.load_module(filename)
def unload_module(self, module):
# this is such a bad idea
module._is_unloaded = True
self.unhook_check(self.bot.events)
if hasattr(module, "_cleanup"):
module._cleanup()
del sys.modules[module._import_name]
del self.modules[module._name]
del module
gc.collect()
def unhook_check(self, event):
for hook in event.get_hooks():
if hasattr(hook.function, "__self__") and hasattr(
hook.function.__self__, "_is_unloaded"
) and hook.function.__self__._is_unloaded:
event._unhook(hook)
for child in event.get_children():
self.unhook_check(event.get_child(child))

View file

@ -1,9 +1,11 @@
import time, uuid import time, uuid
class Timer(object): class Timer(object):
def __init__(self, bot, event_name, delay, next_due=None, **kwargs): def __init__(self, id, bot, events, event_name, delay,
self.id = uuid.uuid4().hex next_due=None, **kwargs):
self.id = id
self.bot = bot self.bot = bot
self.events = events
self.event_name = event_name self.event_name = event_name
self.delay = delay self.delay = delay
if next_due: if next_due:
@ -26,7 +28,7 @@ class Timer(object):
def call(self): def call(self):
self._done = True self._done = True
self.call_count +=1 self.call_count +=1
self.bot.events.on("timer").on(self.event_name).call( self.events.on("timer").on(self.event_name).call(
timer=self, **self.kwargs) timer=self, **self.kwargs)
def redo(self): def redo(self):

View file

@ -1,9 +1,8 @@
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received").on("invite").hook( events.on("received").on("invite").hook(self.on_invite)
self.on_invite)
def on_invite(self, event): def on_invite(self, event):
if event["server"].get_setting("accept-invites", True): if event["server"].get_setting("accept-invites", True):

View file

@ -1,16 +1,16 @@
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("changenickname" events.on("received").on("command").on("changenickname"
).hook(self.change_nickname, permission="changenickname", ).hook(self.change_nickname, permission="changenickname",
min_args=1, help="Change my nickname", usage="<nickname>") min_args=1, help="Change my nickname", usage="<nickname>")
bot.events.on("received").on("command").on("raw" events.on("received").on("command").on("raw"
).hook(self.raw, permission="raw", min_args=1, ).hook(self.raw, permission="raw", min_args=1,
help="Send a raw IRC line through the bot", help="Send a raw IRC line through the bot",
usage="<raw line>") usage="<raw line>")
bot.events.on("received").on("command").on("part" events.on("received").on("command").on("part"
).hook(self.part, permission="part", min_args=1, ).hook(self.part, permission="part", min_args=1,
help="Part from a channel", help="Part from a channel",
usage="<#channel>") usage="<#channel>")

View file

@ -1,16 +1,16 @@
import Utils import Utils
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("postboot").on("configure").on( events.on("postboot").on("configure").on(
"channelset").assure_call(setting="automode", "channelset").assure_call(setting="automode",
help="Disable/Enable automode", help="Disable/Enable automode",
validate=Utils.bool_or_none) validate=Utils.bool_or_none)
bot.events.on("channel").on("mode").hook(self.on_mode) events.on("channel").on("mode").hook(self.on_mode)
bot.events.on("received").on("join").hook(self.on_join) events.on("received").on("join").hook(self.on_join)
def on_mode(self, event): def on_mode(self, event):
if event["channel"].get_setting("automode", False): if event["channel"].get_setting("automode", False):

View file

@ -2,9 +2,9 @@ import Utils
class Module(object): class Module(object):
_name = "BTC" _name = "BTC"
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("btc").hook( events.on("received").on("command").on("btc").hook(
self.btc, help="Get the exchange rate of bitcoins", self.btc, help="Get the exchange rate of bitcoins",
usage="[currency]") usage="[currency]")

View file

@ -7,10 +7,11 @@ URL_BITLYSHORTEN = "https://api-ssl.bitly.com/v3/shorten"
REGEX_URL = re.compile("https?://", re.I) REGEX_URL = re.compile("https?://", re.I)
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("get").on("shortlink").hook(self.shortlink) self.events = events
bot.events.on("received").on("command").on("shorten" events.on("get").on("shortlink").hook(self.shortlink)
events.on("received").on("command").on("shorten"
).hook(self.shorten, min_args=1, help="Shorten a URL.", ).hook(self.shorten, min_args=1, help="Shorten a URL.",
usage="<url>") usage="<url>")
@ -25,7 +26,7 @@ class Module(object):
return data["data"]["url"] return data["data"]["url"]
def shorten(self, event): def shorten(self, event):
link = self.bot.events.on("get").on("shortlink" link = self.events.on("get").on("shortlink"
).call_for_result(url=event["args"]) ).call_for_result(url=event["args"])
if link: if link:
event["stdout"].write("Short URL: %s" % link) event["stdout"].write("Short URL: %s" % link)

View file

@ -7,12 +7,12 @@ REGEX_BOOKID = re.compile("id=([\w\-]+)")
class Module(object): class Module(object):
_name = "ISBN" _name = "ISBN"
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("isbn").hook( events.on("received").on("command").on("isbn").hook(
self.isbn, help="Get book information from a provided ISBN", self.isbn, help="Get book information from a provided ISBN",
min_args=1, usage="<isbn>") min_args=1, usage="<isbn>")
bot.events.on("received").on("command").on("book").hook( events.on("received").on("command").on("book").hook(
self.book, help="Get book information from a provided title", self.book, help="Get book information from a provided title",
min_args=1, usage="<book title>") min_args=1, usage="<book title>")

View file

@ -2,57 +2,57 @@ import Utils
class Module(object): class Module(object):
_name = "Channel Op" _name = "Channel Op"
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("kick", "k" events.on("received").on("command").on("kick", "k"
).hook(self.kick, channel_only=True, require_mode="o", ).hook(self.kick, channel_only=True, require_mode="o",
min_args=1, help="Kick a user from the channel", min_args=1, help="Kick a user from the channel",
usage="<nickname> [reason]") usage="<nickname> [reason]")
bot.events.on("received").on("command").on("ban" events.on("received").on("command").on("ban"
).hook(self.ban, channel_only=True, require_mode="o", ).hook(self.ban, channel_only=True, require_mode="o",
min_args=1, help="Ban a user/hostmask from the channel", min_args=1, help="Ban a user/hostmask from the channel",
usage="<nickname/hostmask>") usage="<nickname/hostmask>")
bot.events.on("received").on("command").on("unban" events.on("received").on("command").on("unban"
).hook(self.unban, channel_only=True, require_mode="o", ).hook(self.unban, channel_only=True, require_mode="o",
min_args=1, help="Unban a user/hostmask from the channel", min_args=1, help="Unban a user/hostmask from the channel",
usage="<nickname/hostmask>") usage="<nickname/hostmask>")
bot.events.on("received").on("command").on("kickban", "kb" events.on("received").on("command").on("kickban", "kb"
).hook(self.kickban, channel_only=True, require_mode="o", ).hook(self.kickban, channel_only=True, require_mode="o",
min_args=1, help="Kickban a user from the channel", min_args=1, help="Kickban a user from the channel",
usage="<nickanme> [reason]") usage="<nickanme> [reason]")
bot.events.on("received").on("command").on("op" events.on("received").on("command").on("op"
).hook(self.op, channel_only=True, require_mode="o", ).hook(self.op, channel_only=True, require_mode="o",
help="Give +o to a user", usage="[nickname]") help="Give +o to a user", usage="[nickname]")
bot.events.on("received").on("command").on("deop" events.on("received").on("command").on("deop"
).hook(self.deop, channel_only=True, require_mode="o", ).hook(self.deop, channel_only=True, require_mode="o",
help="Take +o from a user", usage="[nickname]") help="Take +o from a user", usage="[nickname]")
bot.events.on("received").on("command").on("voice" events.on("received").on("command").on("voice"
).hook(self.voice, channel_only=True, require_mode="o", ).hook(self.voice, channel_only=True, require_mode="o",
help="Give +v to a user", usage="[nickname]") help="Give +v to a user", usage="[nickname]")
bot.events.on("received").on("command").on("devoice" events.on("received").on("command").on("devoice"
).hook(self.devoice, channel_only=True, require_mode="o", ).hook(self.devoice, channel_only=True, require_mode="o",
help="Take +v from a user", usage="[nickname]") help="Take +v from a user", usage="[nickname]")
bot.events.on("received").on("message").on("channel").hook( events.on("received").on("message").on("channel").hook(
self.highlight_spam) self.highlight_spam)
bot.events.on("postboot").on("configure").on( events.on("postboot").on("configure").on(
"channelset").assure_call(setting="highlight-spam-threshold", "channelset").assure_call(setting="highlight-spam-threshold",
help="Set the number of nicknames in a message that " help="Set the number of nicknames in a message that "
"qualifies as spam", validate=Utils.int_or_none) "qualifies as spam", validate=Utils.int_or_none)
bot.events.on("postboot").on("configure").on( events.on("postboot").on("configure").on(
"channelset").assure_call(setting="highlight-spam-protection", "channelset").assure_call(setting="highlight-spam-protection",
help="Enable/Disable highlight spam protection", help="Enable/Disable highlight spam protection",
validate=Utils.bool_or_none) validate=Utils.bool_or_none)
bot.events.on("postboot").on("configure").on( events.on("postboot").on("configure").on(
"channelset").assure_call(setting="highlight-spam-ban", "channelset").assure_call(setting="highlight-spam-ban",
help="Enable/Disable banning highlight spammers " help="Enable/Disable banning highlight spammers "
"instead of just kicking", validate=Utils.bool_or_none) "instead of just kicking", validate=Utils.bool_or_none)
bot.events.on("postboot").on("configure").on( events.on("postboot").on("configure").on(
"channelset").assure_call(setting="ban-format", "channelset").assure_call(setting="ban-format",
help="Set ban format ($n = nick, $u = username, $h = hostname)") help="Set ban format ($n = nick, $u = username, $h = hostname)")

View file

@ -1,11 +1,10 @@
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received.numeric.001").hook( events.on("received.numeric.001").hook(self.on_connect)
self.on_connect) events.on("self.join").hook(self.on_join)
bot.events.on("self.join").hook(self.on_join) events.on("self.kick").hook(self.on_kick)
bot.events.on("self.kick").hook(self.on_kick)
def on_connect(self, event): def on_connect(self, event):
channels = event["server"].get_setting("autojoin", []) channels = event["server"].get_setting("autojoin", [])

View file

@ -1,10 +1,9 @@
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("preprocess").on("command").hook( events.on("preprocess").on("command").hook(self.preprocess_command)
self.preprocess_command)
def preprocess_command(self, event): def preprocess_command(self, event):
if event["is_channel"] and event["hook"].kwargs.get( if event["is_channel"] and event["hook"].kwargs.get(

View file

@ -26,26 +26,26 @@ THIRD_COLUMN = list(range(1, 37))[2::3]
REGEX_STREET = re.compile("street([1-9]|1[0-2])$") REGEX_STREET = re.compile("street([1-9]|1[0-2])$")
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received.command.coins").hook(self.coins, events.on("received.command.coins").hook(self.coins,
help="Show how many coins you have") help="Show how many coins you have")
bot.events.on("received").on("command").on("resetcoins").hook( events.on("received").on("command").on("resetcoins").hook(
self.reset_coins, permission="resetcoins", self.reset_coins, permission="resetcoins",
min_args=1, help= min_args=1, help=
"Reset a specified user's coins to %s" % str(DECIMAL_ZERO), "Reset a specified user's coins to %s" % str(DECIMAL_ZERO),
usage="<target>") usage="<target>")
bot.events.on("received.command.richest").hook( events.on("received.command.richest").hook(
self.richest, help="Show the top 10 richest users") self.richest, help="Show the top 10 richest users")
bot.events.on("received.command.redeemcoins").hook( events.on("received.command.redeemcoins").hook(
self.redeem_coins, help="Redeem free coins") self.redeem_coins, help="Redeem free coins")
bot.events.on("received.command.flip").hook(self.flip, events.on("received.command.flip").hook(self.flip,
help="Bet coins on a coin flip", usage= help="Bet coins on a coin flip", usage=
"heads|tails <coin amount>", min_args=2, protect_registered=True) "heads|tails <coin amount>", min_args=2, protect_registered=True)
bot.events.on("received.command.sendcoins").hook( events.on("received.command.sendcoins").hook(
self.send, min_args=2, help="Send coins to a user", self.send, min_args=2, help="Send coins to a user",
usage="<nickname> <amount>", authenticated=True) usage="<nickname> <amount>", authenticated=True)
bot.events.on("received.command.roulette").hook( events.on("received.command.roulette").hook(
self.roulette, min_args=2, help="Spin the roulette wheel", self.roulette, min_args=2, help="Spin the roulette wheel",
usage="<type> <amount>", protect_registered=True) usage="<type> <amount>", protect_registered=True)
@ -53,7 +53,7 @@ class Module(object):
until_next_hour = 60-now.second until_next_hour = 60-now.second
until_next_hour += ((60-(now.minute+1))*60) until_next_hour += ((60-(now.minute+1))*60)
bot.events.on("timer").on("coin-interest").hook(self.interest) events.on("timer").on("coin-interest").hook(self.interest)
bot.add_timer("coin-interest", INTEREST_INTERVAL, persist=False, bot.add_timer("coin-interest", INTEREST_INTERVAL, persist=False,
next_due=time.time()+until_next_hour) next_due=time.time()+until_next_hour)

View file

@ -45,27 +45,28 @@ class StdErr(Out):
self.module_name, Utils.FONT_RESET) self.module_name, Utils.FONT_RESET)
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot 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) self.channel_message)
bot.events.on("received").on("message").on("private").hook( events.on("received").on("message").on("private").hook(
self.private_message) 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>") 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, help="Show usage help for commands", min_args=1,
usage="<command>") 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) 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", "channelset").assure_call(setting="command-prefix",
help="Set the command prefix used in this channel") help="Set the command prefix used in this channel")
bot.events.on("new").on("user", "channel").hook(self.new) events.on("new").on("user", "channel").hook(self.new)
bot.events.on("send").on("stdout").hook(self.send_stdout) events.on("send").on("stdout").hook(self.send_stdout)
bot.events.on("send").on("stderr").hook(self.send_stderr) events.on("send").on("stderr").hook(self.send_stderr)
def new(self, event): def new(self, event):
if "user" in event: if "user" in event:
@ -76,10 +77,10 @@ class Module(object):
target.last_stderr = None target.last_stderr = None
def has_command(self, command): 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() "command").get_children()
def get_hook(self, command): 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] ).get_hooks()[0]
def is_highlight(self, server, s): def is_highlight(self, server, s):
@ -108,7 +109,7 @@ class Module(object):
stdout, stderr = StdOut(module_name, target), StdErr(module_name, stdout, stderr = StdOut(module_name, target), StdErr(module_name,
target) 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"], ).call(hook=hook, user=event["user"], server=event["server"],
target=target, is_channel=is_channel) target=target, is_channel=is_channel)
for returned in returns: for returned in returns:
@ -129,7 +130,7 @@ class Module(object):
args = " ".join(args_split) args = " ".join(args_split)
server = event["server"] server = event["server"]
user = event["user"] 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, ).call_limited(1, user=user, server=server,
target=target, buffer=buffer, args=args, target=target, buffer=buffer, args=args,
args_split=args_split, stdout=stdout, stderr=stderr, args_split=args_split, stdout=stdout, stderr=stderr,
@ -162,9 +163,9 @@ class Module(object):
def help(self, event): def help(self, event):
if event["args"]: if event["args"]:
command = event["args_split"][0].lower() 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(): "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: if hooks and "help" in hooks[0].kwargs:
event["stdout"].write("%s: %s" % (command, hooks[0].kwargs["help"])) event["stdout"].write("%s: %s" % (command, hooks[0].kwargs["help"]))
else: else:
@ -173,8 +174,8 @@ class Module(object):
event["stderr"].write("Unknown command '%s'" % command) event["stderr"].write("Unknown command '%s'" % command)
else: else:
help_available = [] help_available = []
for child in self.bot.events.on("received").on("command").get_children(): for child in self.events.on("received").on("command").get_children():
hooks = self.bot.events.on("received").on("command").on(child).get_hooks() hooks = self.events.on("received").on("command").on(child).get_hooks()
if hooks and "help" in hooks[0].kwargs: if hooks and "help" in hooks[0].kwargs:
help_available.append(child) help_available.append(child)
help_available = sorted(help_available) help_available = sorted(help_available)
@ -182,9 +183,9 @@ class Module(object):
def usage(self, event): def usage(self, event):
command = event["args_split"][0].lower() 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(): "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: if hooks and "usage" in hooks[0].kwargs:
event["stdout"].write("Usage: %s %s" % (command, hooks[0].kwargs["usage"])) event["stdout"].write("Usage: %s %s" % (command, hooks[0].kwargs["usage"]))
else: else:

View file

@ -1,10 +1,10 @@
import datetime import datetime
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received").on("message").on("private").hook(
self.private_message)
self.bot = bot self.bot = bot
events.on("received").on("message").on("private").hook(
self.private_message)
def private_message(self, event): def private_message(self, event):
if event["message"][0] == "\x01" and event["message"][-1] == "\x01": if event["message"][0] == "\x01" and event["message"][-1] == "\x01":

View file

@ -5,9 +5,9 @@ import Utils
URL_WORDNIK = "http://api.wordnik.com:80/v4/word.json/%s/definitions" URL_WORDNIK = "http://api.wordnik.com:80/v4/word.json/%s/definitions"
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("define").hook( events.on("received").on("command").on("define").hook(
self.define, help="Define a provided term", self.define, help="Define a provided term",
usage="<phrase>") usage="<phrase>")

View file

@ -2,8 +2,8 @@ import socket
class Module(object): class Module(object):
_name = "DNS" _name = "DNS"
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received").on("command").on("dns").hook( events.on("received").on("command").on("dns").hook(
self.dns, min_args=1, self.dns, min_args=1,
help="Get all addresses for a given hostname (IPv4/IPv6)", help="Get all addresses for a given hostname (IPv4/IPv6)",
usage="<hostname>") usage="<hostname>")

View file

@ -7,23 +7,24 @@ DUCK_LAST_SEEN = datetime.datetime.now()
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.log = IRCLogging.Log self.log = IRCLogging.Log
self.bot = bot self.bot = bot
self.events = events
self.active_duck = 0 self.active_duck = 0
bot.events.on("received.command.bef").hook(self.duck_bef, events.on("received.command.bef").hook(self.duck_bef,
help="Befriend a duck!") help="Befriend a duck!")
bot.events.on("received.command.bang").hook(self.duck_bang, events.on("received.command.bang").hook(self.duck_bang,
help="Shoot a duck! Meanie.") help="Shoot a duck! Meanie.")
bot.events.on("received.command.decoy").hook(self.set_decoy, events.on("received.command.decoy").hook(self.set_decoy,
help="Be a sneaky fellow and make a decoy duck.") help="Be a sneaky fellow and make a decoy duck.")
# bot.events.on("received.command.friends").hook(self.duck_friends, # events.on("received.command.friends").hook(self.duck_friends,
# help="See who the friendliest people to ducks are!") # help="See who the friendliest people to ducks are!")
# bot.events.on("received.command.killers").hook(self.duck_killers, # events.on("received.command.killers").hook(self.duck_killers,
# help="See who shoots the most amount of ducks.") # help="See who shoots the most amount of ducks.")
# bot.events.on("received.command.ducks").hook(self.duck_list, # events.on("received.command.ducks").hook(self.duck_list,
# help="Shows a list of the most popular duck superstars.") # help="Shows a list of the most popular duck superstars.")
now = datetime.datetime.now() now = datetime.datetime.now()
@ -35,22 +36,22 @@ class Module(object):
tricky = next_duck_time - now.second tricky = next_duck_time - now.second
tricky += ((next_duck_time - (now.minute + 1)) * 2) tricky += ((next_duck_time - (now.minute + 1)) * 2)
bot.events.on("postboot").on("configure").on( events.on("postboot").on("configure").on(
"channelset").assure_call(setting="ducks-enabled", "channelset").assure_call(setting="ducks-enabled",
help="Toggles ducks! (1 or 0)") help="Toggles ducks! (1 or 0)")
bot.events.on("postboot").on("configure").on( events.on("postboot").on("configure").on(
"channelset").assure_call(setting="min-duck-time", "channelset").assure_call(setting="min-duck-time",
help="Minimum seconds before a duck is summoned") help="Minimum seconds before a duck is summoned")
bot.events.on("postboot").on("configure").on( events.on("postboot").on("configure").on(
"channelset").assure_call(setting="max-duck-time", "channelset").assure_call(setting="max-duck-time",
help="Max seconds before a duck is summoned") help="Max seconds before a duck is summoned")
bot.events.on("timer").on("duck-appear").hook(self.show_duck) events.on("timer").on("duck-appear").hook(self.show_duck)
bot.add_timer("duck-appear", next_duck_time, persist=False) bot.add_timer("duck-appear", next_duck_time, persist=False)
bot.events.on("received.numeric.366").hook(self.bootstrap) events.on("received.numeric.366").hook(self.bootstrap)
def bootstrap(self, event): def bootstrap(self, event):
for server in self.bot.servers.values(): for server in self.bot.servers.values():
@ -198,7 +199,7 @@ class Module(object):
def set_decoy(self, event): def set_decoy(self, event):
next_decoy_time = self.decoy_time() next_decoy_time = self.decoy_time()
self.bot.events.on("timer").on("duck-decoy").hook(self.duck_decoy) self.events.on("timer").on("duck-decoy").hook(self.duck_decoy)
self.bot.add_timer("duck-decoy", next_decoy_time, persist=False) self.bot.add_timer("duck-decoy", next_decoy_time, persist=False)
# def coins(self, event): # def coins(self, event):

View file

@ -4,8 +4,8 @@ URL_GEOIP = "http://ip-api.com/json/%s"
class Module(object): class Module(object):
_name = "GeoIP" _name = "GeoIP"
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received").on("command").on("geoip").hook( events.on("received").on("command").on("geoip").hook(
self.geoip, min_args=1, self.geoip, min_args=1,
help="Get geoip data on a given IPv4/IPv6 address", help="Get geoip data on a given IPv4/IPv6 address",
usage="<IP>") usage="<IP>")

View file

@ -6,9 +6,9 @@ import Utils
URL_GOOGLESEARCH = "https://www.googleapis.com/customsearch/v1" URL_GOOGLESEARCH = "https://www.googleapis.com/customsearch/v1"
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("google", events.on("received").on("command").on("google",
"g").hook(self.google, help="Google feeling lucky", "g").hook(self.google, help="Google feeling lucky",
usage="[search term]") usage="[search term]")

View file

@ -1,9 +1,9 @@
import hashlib import hashlib
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("hash" events.on("received").on("command").on("hash"
).hook(self.hash, min_args=2, help="Hash a string", ).hook(self.hash, min_args=2, help="Hash a string",
usage="<algo> <string>") usage="<algo> <string>")

View file

@ -4,8 +4,8 @@ URL_HAVEIBEENPWNEDAPI = "https://haveibeenpwned.com/api/v2/breachedaccount/%s"
URL_HAVEIBEENPWNED = "https://haveibeenpwned.com/" URL_HAVEIBEENPWNED = "https://haveibeenpwned.com/"
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received").on("command").on("beenpwned").hook( events.on("received").on("command").on("beenpwned").hook(
self.beenpwned, min_args=1, self.beenpwned, min_args=1,
help="Find out if a username, email or similar has appeared " help="Find out if a username, email or similar has appeared "
"in any hacked databases", usage="<username/email>") "in any hacked databases", usage="<username/email>")

View file

@ -2,10 +2,10 @@
class Module(object): class Module(object):
_name = "IDs" _name = "IDs"
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received.command.myid").hook(self.my_id, events.on("received.command.myid").hook(self.my_id,
help="Show your user ID") help="Show your user ID")
bot.events.on("received.command.channelid").hook( events.on("received.command.channelid").hook(
self.channel_id, channel_only=True, self.channel_id, channel_only=True,
help="Show the current channel's ID") help="Show the current channel's ID")

View file

@ -8,9 +8,9 @@ URL_IMDBTITLE = "http://imdb.com/title/%s"
class Module(object): class Module(object):
_name = "IMDb" _name = "IMDb"
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("imdb").hook( events.on("received").on("command").on("imdb").hook(
self.imdb, min_args=1, self.imdb, min_args=1,
help="Search for a given title on IMDb", help="Search for a given title on IMDb",
usage="<movie/tv title>") usage="<movie/tv title>")

View file

@ -5,12 +5,12 @@ SECONDS_MAX = Utils.SECONDS_WEEKS*8
SECONDS_MAX_DESCRIPTION = "8 weeks" SECONDS_MAX_DESCRIPTION = "8 weeks"
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("in").hook( events.on("received").on("command").on("in").hook(
self.in_command, min_args=2, self.in_command, min_args=2,
help="Set a reminder", usage="<time> <message>") help="Set a reminder", usage="<time> <message>")
bot.events.on("timer").on("in").hook(self.timer_due) events.on("timer").on("in").hook(self.timer_due)
def in_command(self, event): def in_command(self, event):
seconds = Utils.from_pretty_time(event["args_split"][0]) seconds = Utils.from_pretty_time(event["args_split"][0])

View file

@ -1,8 +1,8 @@
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received").on("numeric").on("001").hook(self.do_join) events.on("received").on("numeric").on("001").hook(self.do_join)
def do_join(self, event): def do_join(self, event):
event["server"].send_join("#bitbot") event["server"].send_join("#bitbot")

View file

@ -5,20 +5,21 @@ REGEX_KARMA = re.compile("(.*)(\+{2,}|\-{2,})$")
KARMA_DELAY_SECONDS = 3 KARMA_DELAY_SECONDS = 3
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("new").on("user").hook(self.new_user) self.events = events
bot.events.on("received").on("message").on("channel").hook( events.on("new").on("user").hook(self.new_user)
events.on("received").on("message").on("channel").hook(
self.channel_message) self.channel_message)
bot.events.on("received").on("command").on("karma").hook( events.on("received").on("command").on("karma").hook(
self.karma, help="Get your or someone else's karma", self.karma, help="Get your or someone else's karma",
usage="[target]") usage="[target]")
bot.events.on("received").on("command").on("resetkarma").hook( events.on("received").on("command").on("resetkarma").hook(
self.reset_karma, permission="resetkarma", self.reset_karma, permission="resetkarma",
min_args=1, help="Reset a specified karma to 0", min_args=1, help="Reset a specified karma to 0",
usage="<target>") usage="<target>")
bot.events.on("postboot").on("configure").on( events.on("postboot").on("configure").on(
"channelset").assure_call(setting="karma-verbose", "channelset").assure_call(setting="karma-verbose",
help="Disable/Enable automatically responding to karma changes", help="Disable/Enable automatically responding to karma changes",
validate=Utils.bool_or_none) validate=Utils.bool_or_none)
@ -46,13 +47,13 @@ class Module(object):
else: else:
event["server"].del_setting(setting) event["server"].del_setting(setting)
if verbose: if verbose:
self.bot.events.on("send").on("stdout").call( self.events.on("send").on("stdout").call(
module_name="Karma", target=event["channel"], module_name="Karma", target=event["channel"],
message="%s now has %d karma" % (target, karma)) message="%s now has %d karma" % (target, karma))
event["user"].last_karma = time.time() event["user"].last_karma = time.time()
elif verbose: elif verbose:
if target: if target:
self.bot.events.on("send").on("stderr").call(module_name="Karma", self.events.on("send").on("stderr").call(module_name="Karma",
target=event["channel"], message="You cannot change your own karma") target=event["channel"], message="You cannot change your own karma")
elif verbose: elif verbose:
event["stderr"].write("Try again in a couple of seconds") event["stderr"].write("Try again in a couple of seconds")

View file

@ -5,14 +5,14 @@ import Utils
URL_SCROBBLER = "http://ws.audioscrobbler.com/2.0/" URL_SCROBBLER = "http://ws.audioscrobbler.com/2.0/"
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("postboot").on("configure").on( events.on("postboot").on("configure").on(
"set").assure_call(setting="lastfm", "set").assure_call(setting="lastfm",
help="Set username on last.fm") help="Set username on last.fm")
bot.events.on("received").on("command").on("np", events.on("received").on("command").on("np",
"listening", "nowplaying").hook(self.np, "listening", "nowplaying").hook(self.np,
help="Get the last listened to track from a user", help="Get the last listened to track from a user",
usage="[username]") usage="[username]")

View file

@ -22,13 +22,13 @@ def del_setting(user, setting):
class Module(object): class Module(object):
_name = "Aliases" _name = "Aliases"
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("new").on("user").hook(self.new_user) events.on("new").on("user").hook(self.new_user)
bot.events.on("received").on("nick").hook(self.nickname_change) events.on("received").on("nick").hook(self.nickname_change)
bot.events.on("received").on("command").on("alias").hook( events.on("received").on("command").on("alias").hook(
self.alias) self.alias)
#bot.events.on("received").on("command").on("mainalias").hook( #events.on("received").on("command").on("mainalias").hook(
# self.main_alias) # self.main_alias)
def new_user(self, event): def new_user(self, event):

View file

@ -2,10 +2,10 @@ import base64
import EventManager import EventManager
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received").on("numeric").on("001" events.on("received").on("numeric").on("001"
).hook(self.on_connect, priority=EventManager.PRIORITY_URGENT) ).hook(self.on_connect, priority=EventManager.PRIORITY_URGENT)
bot.events.on("received").on("command").on("setnickserv" events.on("received").on("command").on("setnickserv"
).hook(self.set_nickserv, min_args=1, permission="setnickserv", ).hook(self.set_nickserv, min_args=1, permission="setnickserv",
help="Set bot's nickserv password", usage="<password>", help="Set bot's nickserv password", usage="<password>",
private_only=True) private_only=True)

View file

@ -20,29 +20,29 @@ class Module(object):
PASSENGER_ACTIVITIES = ["U", "P", "R"] PASSENGER_ACTIVITIES = ["U", "P", "R"]
COLOURS = [Utils.COLOR_LIGHTBLUE, Utils.COLOR_GREEN, Utils.COLOR_RED, Utils.COLOR_CYAN, Utils.COLOR_LIGHTGREY, Utils.COLOR_ORANGE] COLOURS = [Utils.COLOR_LIGHTBLUE, Utils.COLOR_GREEN, Utils.COLOR_RED, Utils.COLOR_CYAN, Utils.COLOR_LIGHTGREY, Utils.COLOR_ORANGE]
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
self._client = None self._client = None
bot.events.on("received").on("command").on("nrtrains" events.on("received").on("command").on("nrtrains"
).hook(self.trains, min_args=1, ).hook(self.trains, min_args=1,
help="Get train/bus services for a station (Powered by NRE)", help="Get train/bus services for a station (Powered by NRE)",
usage="<crs_id>") usage="<crs_id>")
bot.events.on("received").on("command").on("nrservice" events.on("received").on("command").on("nrservice"
).hook(self.service, min_args=1, ).hook(self.service, min_args=1,
help="Get train service information for a UID, headcode or RID (Powered by NRE)", help="Get train service information for a UID, headcode or RID (Powered by NRE)",
usage="<service_id>") usage="<service_id>")
bot.events.on("received").on("command").on("nrhead" events.on("received").on("command").on("nrhead"
).hook(self.head, min_args=1, ).hook(self.head, min_args=1,
help="Get information for a given headcode/UID/RID (Powered by NRE)", help="Get information for a given headcode/UID/RID (Powered by NRE)",
usage="<headcode>") usage="<headcode>")
bot.events.on("received").on("command").on("nrcode" events.on("received").on("command").on("nrcode"
).hook(self.service_code, min_args=1, ).hook(self.service_code, min_args=1,
help="Get the text for a given delay/cancellation code (Powered by NRE)", help="Get the text for a given delay/cancellation code (Powered by NRE)",
usage="<code>") usage="<code>")
bot.events.on("telegram").on("command").on("nrtrains").hook(self.trains) events.on("telegram").on("command").on("nrtrains").hook(self.trains)
bot.events.on("telegram").on("command").on("nrcode").hook(self.service_code) events.on("telegram").on("command").on("nrcode").hook(self.service_code)
bot.events.on("telegram").on("command").on("nrhead").hook(self.head) events.on("telegram").on("command").on("nrhead").hook(self.head)
bot.events.on("telegram").on("command").on("nrservice").hook(self.service) events.on("telegram").on("command").on("nrservice").hook(self.service)
@property @property
def client(self): def client(self):

View file

@ -1,8 +1,8 @@
import EventManager import EventManager
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received").on("numeric").on("001").hook( events.on("received").on("numeric").on("001").hook(
self.on_connect, priority=EventManager.PRIORITY_URGENT) self.on_connect, priority=EventManager.PRIORITY_URGENT)
def on_connect(self, event): def on_connect(self, event):

View file

@ -5,26 +5,26 @@ REQUIRES_IDENTIFY = ("You need to be identified to use that command "
"(/msg %s register | /msg %s identify)") "(/msg %s register | /msg %s identify)")
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("new").on("user").hook(self.new_user) events.on("new").on("user").hook(self.new_user)
bot.events.on("preprocess").on("command").hook( events.on("preprocess").on("command").hook(
self.preprocess_command) self.preprocess_command)
bot.events.on("received").on("part").hook(self.on_part) events.on("received").on("part").hook(self.on_part)
bot.events.on("received").on("command").on("identify" events.on("received").on("command").on("identify"
).hook(self.identify, private_only=True, min_args=1, ).hook(self.identify, private_only=True, min_args=1,
usage="<password>", help="Identify yourself") usage="<password>", help="Identify yourself")
bot.events.on("received").on("command").on("register" events.on("received").on("command").on("register"
).hook(self.register, private_only=True, min_args=1, ).hook(self.register, private_only=True, min_args=1,
usage="<password>", help="Register your nickname") usage="<password>", help="Register your nickname")
bot.events.on("received.command.logout").hook(self.logout, events.on("received.command.logout").hook(self.logout,
private_only=True, help="Sign out from the bot") private_only=True, help="Sign out from the bot")
bot.events.on("received.command.mypermissions").hook( events.on("received.command.mypermissions").hook(
self.my_permissions, authenticated=True) self.my_permissions, authenticated=True)
bot.events.on("received.command.givepermission").hook( events.on("received.command.givepermission").hook(
self.give_permission, min_args=2, permission="givepermission") self.give_permission, min_args=2, permission="givepermission")
bot.events.on("received.command.removepermission").hook( events.on("received.command.removepermission").hook(
self.remove_permission, min_args=2, permission="removepermission") self.remove_permission, min_args=2, permission="removepermission")
def new_user(self, event): def new_user(self, event):

View file

@ -1,9 +1,8 @@
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received.command.ping").hook( events.on("received.command.ping").hook(self.pong, help="Ping pong!")
self.pong, help="Ping pong!")
def pong(self, event): def pong(self, event):
event["stdout"].write("Pong!") event["stdout"].write("Pong!")

View file

@ -2,37 +2,37 @@ import datetime
import EventManager import EventManager
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("message").on("channel").hook( events.on("received").on("message").on("channel").hook(
self.channel_message, priority=EventManager.PRIORITY_HIGH) self.channel_message, priority=EventManager.PRIORITY_HIGH)
bot.events.on("self").on("message").on("channel").hook( events.on("self").on("message").on("channel").hook(
self.self_channel_message) self.self_channel_message)
bot.events.on("received").on("notice").on("channel").hook( events.on("received").on("notice").on("channel").hook(
self.channel_notice, priority=EventManager.PRIORITY_HIGH) self.channel_notice, priority=EventManager.PRIORITY_HIGH)
bot.events.on("received").on("notice").on("private").hook( events.on("received").on("notice").on("private").hook(
self.private_notice, priority=EventManager.PRIORITY_HIGH) self.private_notice, priority=EventManager.PRIORITY_HIGH)
bot.events.on("received").on("server-notice").hook( events.on("received").on("server-notice").hook(
self.server_notice, priority=EventManager.PRIORITY_HIGH) self.server_notice, priority=EventManager.PRIORITY_HIGH)
bot.events.on("received").on("join").hook(self.join) events.on("received").on("join").hook(self.join)
bot.events.on("self").on("join").hook(self.self_join) events.on("self").on("join").hook(self.self_join)
bot.events.on("received").on("part").hook(self.part) events.on("received").on("part").hook(self.part)
bot.events.on("self").on("part").hook(self.self_part) events.on("self").on("part").hook(self.self_part)
bot.events.on("received").on("nick").hook(self.on_nick) events.on("received").on("nick").hook(self.on_nick)
bot.events.on("self").on("nick").hook(self.on_nick) events.on("self").on("nick").hook(self.on_nick)
bot.events.on("received").on("quit").hook(self.on_quit) events.on("received").on("quit").hook(self.on_quit)
bot.events.on("received").on("kick").hook(self.kick) events.on("received").on("kick").hook(self.kick)
bot.events.on("self").on("kick").hook(self.self_kick) events.on("self").on("kick").hook(self.self_kick)
bot.events.on("received").on("topic").hook(self.on_topic) events.on("received").on("topic").hook(self.on_topic)
bot.events.on("received").on("numeric").on("333").hook(self.on_333) events.on("received").on("numeric").on("333").hook(self.on_333)
def print_line(self, event, line, channel=None): def print_line(self, event, line, channel=None):
timestamp = datetime.datetime.now().isoformat() timestamp = datetime.datetime.now().isoformat()

View file

@ -55,8 +55,8 @@ QUOTES = {
} }
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("get.quit-quote").hook(self.quote) events.on("get.quit-quote").hook(self.quote)
def quote(self, event): def quote(self, event):
quote = random.choice(list(QUOTES.items())) quote = random.choice(list(QUOTES.items()))

View file

@ -1,21 +1,21 @@
import random, time import random, time
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("quoteadd", events.on("received").on("command").on("quoteadd",
"qadd").hook(self.quote_add, min_args=1, "qadd").hook(self.quote_add, min_args=1,
help="Added a quote to a category", help="Added a quote to a category",
usage="<category> = <quote>") usage="<category> = <quote>")
bot.events.on("received").on("command").on("quoteget", events.on("received").on("command").on("quoteget",
"qget").hook(self.quote_get, min_args=1, "qget").hook(self.quote_get, min_args=1,
help="Find a quote within a category", help="Find a quote within a category",
usage="<category> = <search>") usage="<category> = <search>")
bot.events.on("received").on("command").on("quotedel", events.on("received").on("command").on("quotedel",
"qdel").hook(self.quote_del, min_args=1, "qdel").hook(self.quote_del, min_args=1,
help="Delete a quote from a category", help="Delete a quote from a category",
usage="<category> = <quote>") usage="<category> = <quote>")
bot.events.on("received").on("command").on("quote", events.on("received").on("command").on("quote",
"q").hook(self.quote, min_args=1, "q").hook(self.quote, min_args=1,
help="Get a random quote from a category", help="Get a random quote from a category",
usage="<category>") usage="<category>")

View file

@ -2,11 +2,11 @@ import random, uuid
class Module(object): class Module(object):
_name = "Random" _name = "Random"
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received").on("command").on("random", events.on("received").on("command").on("random",
"rand").hook(self.random, help="Get a random number", "rand").hook(self.random, help="Get a random number",
usage="[start] [end]") usage="[start] [end]")
bot.events.on("received").on("command").on("guid" events.on("received").on("command").on("guid"
).hook(self.guid, help="Get a random guid") ).hook(self.guid, help="Get a random guid")
def random(self, event): def random(self, event):

View file

@ -1,12 +1,12 @@
import base64 import base64
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("preprocess.connect").hook(self.preprocess_connect) events.on("preprocess.connect").hook(self.preprocess_connect)
bot.events.on("received.cap").hook(self.on_cap) events.on("received.cap").hook(self.on_cap)
bot.events.on("received.authenticate").hook(self.on_authenticate) events.on("received.authenticate").hook(self.on_authenticate)
bot.events.on("received.numeric").on( events.on("received.numeric").on(
"902", "903", "904", "905", "906", "907", "908").hook(self.on_90x) "902", "903", "904", "905", "906", "907", "908").hook(self.on_90x)
def preprocess_connect(self, event): def preprocess_connect(self, event):

View file

@ -5,16 +5,17 @@ REGEX_SPLIT = re.compile("(?<!\\\\)/")
REGEX_SED = re.compile("^s/") REGEX_SED = re.compile("^s/")
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot 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) self.channel_message)
bot.events.on("postboot").on("configure").on( events.on("postboot").on("configure").on(
"channelset").assure_call(setting="sed", "channelset").assure_call(setting="sed",
help="Disable/Enable sed in a channel", help="Disable/Enable sed in a channel",
validate=Utils.bool_or_none) validate=Utils.bool_or_none)
bot.events.on("postboot").on("configure").on( events.on("postboot").on("configure").on(
"channelset").assure_call(setting="sed-sender-only", "channelset").assure_call(setting="sed-sender-only",
help="Disable/Enable sed only looking at the messages " help="Disable/Enable sed only looking at the messages "
"sent by the user", validate=Utils.bool_or_none) "sent by the user", validate=Utils.bool_or_none)
@ -49,7 +50,7 @@ class Module(object):
pattern = re.compile(sed_split[1], regex_flags) pattern = re.compile(sed_split[1], regex_flags)
except: except:
traceback.print_exc() traceback.print_exc()
self.bot.events.on("send").on("stderr").call(target=event[ self.events.on("send").on("stderr").call(target=event[
"channel"], module_name="Sed", server=event["server"], "channel"], module_name="Sed", server=event["server"],
message="Invalid regex in pattern") message="Invalid regex in pattern")
return return
@ -66,6 +67,6 @@ class Module(object):
prefix = "* %s" % line.sender prefix = "* %s" % line.sender
else: else:
prefix = "<%s>" % line.sender prefix = "<%s>" % line.sender
self.bot.events.on("send").on("stdout").call(target=event[ self.events.on("send").on("stdout").call(target=event[
"channel"], module_name="Sed", server=event["server"], "channel"], module_name="Sed", server=event["server"],
message="%s %s" % (prefix, new_message)) message="%s %s" % (prefix, new_message))

View file

@ -2,10 +2,10 @@ import time
import Utils import Utils
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received").on("message").on("channel" events.on("received").on("message").on("channel"
).hook(self.channel_message) ).hook(self.channel_message)
bot.events.on("received").on("command").on("seen").hook( events.on("received").on("command").on("seen").hook(
self.seen, min_args=1, self.seen, min_args=1,
help="Find out when a user was last seen", help="Find out when a user was last seen",
usage="<username>") usage="<username>")

View file

@ -1,31 +1,32 @@
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
self.settings = {} self.settings = {}
self.channel_settings = {} self.channel_settings = {}
bot.events.on("postboot").on("configure").on("set").hook(
events.on("postboot").on("configure").on("set").hook(
self.postboot_set, replay=True) self.postboot_set, replay=True)
bot.events.on("postboot").on("configure").on("channelset" events.on("postboot").on("configure").on("channelset"
).hook(self.postboot_channelset, replay=True) ).hook(self.postboot_channelset, replay=True)
bot.events.on("received").on("command").on("set").hook( events.on("received").on("command").on("set").hook(
self.set, help="Set a specified user setting", self.set, help="Set a specified user setting",
usage="<setting> <value>") usage="<setting> <value>")
bot.events.on("received").on("command").on("get").hook( events.on("received").on("command").on("get").hook(
self.get, help="Get a specified user setting", self.get, help="Get a specified user setting",
usage="<setting>", min_args=1) usage="<setting>", min_args=1)
bot.events.on("received").on("command").on("channelset" events.on("received").on("command").on("channelset"
).hook(self.channel_set, channel_only=True, ).hook(self.channel_set, channel_only=True,
help="Set a specified setting for the current channel", help="Set a specified setting for the current channel",
usage="<setting> <value>", require_mode="o") usage="<setting> <value>", require_mode="o")
bot.events.on("received").on("command").on("channelsetoverride" events.on("received").on("command").on("channelsetoverride"
).hook(self.channel_set, channel_only=True, ).hook(self.channel_set, channel_only=True,
help="Set a specified setting for the current channel", help="Set a specified setting for the current channel",
usage="<setting> <value>", permission="channelsetoverride") usage="<setting> <value>", permission="channelsetoverride")
bot.events.on("received").on("command").on("channelget" events.on("received").on("command").on("channelget"
).hook(self.channel_get, channel_only=True, ).hook(self.channel_get, channel_only=True,
help="Get a specified setting for the current channel", help="Get a specified setting for the current channel",
usage="<setting>", min_args=1, require_mode="o") usage="<setting>", min_args=1, require_mode="o")

View file

@ -1,19 +1,21 @@
import signal import signal
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
self.events = events
signal.signal(signal.SIGINT, self.SIGINT) signal.signal(signal.SIGINT, self.SIGINT)
signal.signal(signal.SIGUSR1, self.SIGUSR1) signal.signal(signal.SIGUSR1, self.SIGUSR1)
def SIGINT(self, signum, frame): def SIGINT(self, signum, frame):
print() print()
self.bot.events.on("signal").on("interrupt").call(signum=signum, frame=frame) self.events.on("signal").on("interrupt").call(signum=signum,
frame=frame)
for server in self.bot.servers.values(): for server in self.bot.servers.values():
reason = "Leaving" reason = "Leaving"
if server.get_setting("quit-quote", True): if server.get_setting("quit-quote", True):
reason = self.bot.events.on("get.quit-quote" reason = self.events.on("get.quit-quote"
).call_for_result(default="Leaving") ).call_for_result(default="Leaving")
server.send_quit(reason) server.send_quit(reason)
self.bot.register_write(server) self.bot.register_write(server)

View file

@ -9,9 +9,9 @@ REGEX_SOUNDCLOUD = "https?://soundcloud.com/([^/]+)/([^/]+)"
class Module(object): class Module(object):
_name = "SoundCloud" _name = "SoundCloud"
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("soundcloud", "sc" events.on("received").on("command").on("soundcloud", "sc"
).hook(self.soundcloud, help="Search SoundCloud") ).hook(self.soundcloud, help="Search SoundCloud")
def soundcloud(self, event): def soundcloud(self, event):

View file

@ -4,8 +4,8 @@ import Utils
URL_SPOTIFY = "https://api.spotify.com/v1/search" URL_SPOTIFY = "https://api.spotify.com/v1/search"
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received").on("command").on("spotify").hook( events.on("received").on("command").on("spotify").hook(
self.spotify, help="Search for a track on spotify", self.spotify, help="Search for a track on spotify",
min_args=1) min_args=1)

View file

@ -2,12 +2,12 @@ import time
import Utils import Utils
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.boot_time = time.time() self.boot_time = time.time()
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("uptime" events.on("received").on("command").on("uptime"
).hook(self.uptime, help="Show my uptime") ).hook(self.uptime, help="Show my uptime")
bot.events.on("received").on("command").on("stats" events.on("received").on("command").on("stats"
).hook(self.stats, help="Show my network/channel/user stats") ).hook(self.stats, help="Show my network/channel/user stats")
def uptime(self, event): def uptime(self, event):

View file

@ -2,8 +2,8 @@ import random
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received.command.strax").hook( events.on("received.command.strax").hook(
self.strax, help="Suggests a glorious method of battle for the glory of the Sontaran Empire, through IRC!") self.strax, help="Suggests a glorious method of battle for the glory of the Sontaran Empire, through IRC!")
def strax(self, event): def strax(self, event):

View file

@ -8,11 +8,12 @@ from threading import Thread
class Module(Thread): class Module(Thread):
_name = "telegram" _name = "telegram"
def __init__(self, dolphin): def __init__(self, bot, events):
key = dolphin.config.get("telegram-api-key") key = bot.config.get("telegram-api-key")
if not key: return if not key: return
self.dolphin = dolphin self.bot = bot
self.events = events
self.updater = Updater(key) self.updater = Updater(key)
self.dispatcher = self.updater.dispatcher self.dispatcher = self.updater.dispatcher
@ -23,7 +24,7 @@ class Module(Thread):
self.dispatcher.add_handler(command_handler) self.dispatcher.add_handler(command_handler)
self.updater.start_polling() self.updater.start_polling()
dolphin.events.on("signal").on("interrupt").hook(self.sigint) events.on("signal").on("interrupt").hook(self.sigint)
def start(self, bot, update): def start(self, bot, update):
bot.send_message(chat_id=update.message.chat_id, text="`Dolphin, but Telegram`", parse_mode="Markdown") bot.send_message(chat_id=update.message.chat_id, text="`Dolphin, but Telegram`", parse_mode="Markdown")
@ -45,7 +46,7 @@ class Module(Thread):
"stderr": IOWrapper(bot, message.chat_id, message.message_id), "stderr": IOWrapper(bot, message.chat_id, message.message_id),
"external": True, "external": True,
} }
self.dolphin.events.on("telegram").on("command").on(command).call(**data) self.events.on("telegram").on("command").on(command).call(**data)
def sigint(self, event): def sigint(self, event):
self.updater.stop() self.updater.stop()

View file

@ -20,30 +20,30 @@ PLATFORM_TYPES = ["Northbound", "Southbound", "Eastbound", "Westbound", "Inner R
class Module(object): class Module(object):
_name = "TFL" _name = "TFL"
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
self.result_map = {} self.result_map = {}
bot.events.on("received").on("command").on("tflbus" events.on("received").on("command").on("tflbus"
).hook(self.bus, min_args=1, ).hook(self.bus, min_args=1,
help="Get bus due times for a TfL bus stop", help="Get bus due times for a TfL bus stop",
usage="<stop_id>") usage="<stop_id>")
bot.events.on("received").on("command").on("tflline" events.on("received").on("command").on("tflline"
).hook(self.line, ).hook(self.line,
help="Get line status for TfL underground lines", help="Get line status for TfL underground lines",
usage="<line_name>") usage="<line_name>")
bot.events.on("received").on("command").on("tflsearch" events.on("received").on("command").on("tflsearch"
).hook(self.search, min_args=1, ).hook(self.search, min_args=1,
help="Get a list of TfL stop IDs for a given name", help="Get a list of TfL stop IDs for a given name",
usage="<name>") usage="<name>")
bot.events.on("received").on("command").on("tflvehicle" events.on("received").on("command").on("tflvehicle"
).hook(self.vehicle, min_args=1, ).hook(self.vehicle, min_args=1,
help="Get information for a given vehicle", help="Get information for a given vehicle",
usage="<ID>") usage="<ID>")
bot.events.on("received").on("command").on("tflstop" events.on("received").on("command").on("tflstop"
).hook(self.stop, min_args=1, ).hook(self.stop, min_args=1,
help="Get information for a given stop", help="Get information for a given stop",
usage="<stop_id>") usage="<stop_id>")
bot.events.on("received").on("command").on("tflservice" events.on("received").on("command").on("tflservice"
).hook(self.service, min_args=1, ).hook(self.service, min_args=1,
help="Get service information and arrival estimates", help="Get service information and arrival estimates",
usage="<service index>") usage="<service index>")

View file

@ -5,9 +5,9 @@ import Utils
URL_THESAURUS = "http://words.bighugelabs.com/api/2/%s/%s/json" URL_THESAURUS = "http://words.bighugelabs.com/api/2/%s/%s/json"
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("synonym", events.on("received").on("command").on("synonym",
"antonym").hook(self.thesaurus, min_args=1, "antonym").hook(self.thesaurus, min_args=1,
help="Get synonyms/antonyms for a provided phrase", help="Get synonyms/antonyms for a provided phrase",
usage="<word> [type]") usage="<word> [type]")

View file

@ -4,8 +4,8 @@ import Utils
REGEX_URL = re.compile("https?://\S+", re.I) REGEX_URL = re.compile("https?://\S+", re.I)
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received").on("command").on("title", "t").hook( events.on("received").on("command").on("title", "t").hook(
self.title, help="Get the title of the provided or most " self.title, help="Get the title of the provided or most "
"recent URL.", usage="[URL]") "recent URL.", usage="[URL]")

View file

@ -1,11 +1,11 @@
import EventManager import EventManager
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received").on("message").on("channel" events.on("received").on("message").on("channel"
).hook(self.channel_message, ).hook(self.channel_message,
priority=EventManager.PRIORITY_MEDIUM) priority=EventManager.PRIORITY_MEDIUM)
bot.events.on("received").on("command").on("to").hook( events.on("received").on("command").on("to").hook(
self.to, min_args=2, help=("Relay a message to a " self.to, min_args=2, help=("Relay a message to a "
"user the next time they talk in a channel"), "user the next time they talk in a channel"),
channel_only=True, usage="<username> <message>") channel_only=True, usage="<username> <message>")

View file

@ -1,15 +1,15 @@
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("todo").hook( events.on("received").on("command").on("todo").hook(
self.todo, help="Find out what's in your todo list", self.todo, help="Find out what's in your todo list",
usage="[item number]") usage="[item number]")
bot.events.on("received").on("command").on("todoadd").hook( events.on("received").on("command").on("todoadd").hook(
self.todo_add, min_args=1, help="Add something to your todo list", self.todo_add, min_args=1, help="Add something to your todo list",
usage="<description>") usage="<description>")
bot.events.on("received").on("command").on("tododel").hook( events.on("received").on("command").on("tododel").hook(
self.todo_del, min_args=1, help="Remove something from your " self.todo_del, min_args=1, help="Remove something from your "
"todo list", usage="<item number>") "todo list", usage="<item number>")

View file

@ -6,14 +6,14 @@ URL_TRAKT = "https://api-v2launch.trakt.tv/users/%s/watching"
URL_TRAKTSLUG = "https://trakt.tv/%s/%s" URL_TRAKTSLUG = "https://trakt.tv/%s/%s"
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("nowwatching", events.on("received").on("command").on("nowwatching",
"nw").hook(self.now_watching, "nw").hook(self.now_watching,
help="Get what you or another user is now watching " help="Get what you or another user is now watching "
"on trakt.tv", usage="[username]") "on trakt.tv", usage="[username]")
bot.events.on("postboot").on("configure").on("set" events.on("postboot").on("configure").on("set"
).assure_call(setting="trakt", help="Set username on trakt.tv") ).assure_call(setting="trakt", help="Set username on trakt.tv")
def now_watching(self, event): def now_watching(self, event):

View file

@ -6,8 +6,8 @@ URL_LANGUAGES = "https://cloud.google.com/translate/docs/languages"
REGEX_LANGUAGES = re.compile("(\w+)?:(\w+)? ") REGEX_LANGUAGES = re.compile("(\w+)?:(\w+)? ")
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received").on("command").on("translate", "tr").hook( events.on("received").on("command").on("translate", "tr").hook(
self.translate, help="Translate the provided phrase or the " self.translate, help="Translate the provided phrase or the "
"last line seen.", usage="[phrase]") "last line seen.", usage="[phrase]")

View file

@ -11,9 +11,9 @@ REGEX_TWITTERURL = re.compile(
"https?://(?:www\.)?twitter.com/[^/]+/status/(\d+)", re.I) "https?://(?:www\.)?twitter.com/[^/]+/status/(\d+)", re.I)
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("twitter", "tw" events.on("received").on("command").on("twitter", "tw"
).hook(self.twitter, help="Find a tweet", ).hook(self.twitter, help="Find a tweet",
usage="[@username/URL/ID]") usage="[@username/URL/ID]")

View file

@ -4,9 +4,9 @@ UPCITEMDB_URL = "https://api.upcitemdb.com/prod/trial/lookup"
class Module(object): class Module(object):
_name = "UPC" _name = "UPC"
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on( events.on("received").on("command").on(
"upc", "ean", "gtin").hook( "upc", "ean", "gtin").hook(
self.upc, min_args=1, usage="<UPC|EAN>", self.upc, min_args=1, usage="<UPC|EAN>",
help="Look up a product by UPC or EAN") help="Look up a product by UPC or EAN")

View file

@ -5,8 +5,8 @@ URL_URBANDICTIONARY = "http://api.urbandictionary.com/v0/define"
REGEX_DEFNUMBER = re.compile("-n(\d+) \S+") REGEX_DEFNUMBER = re.compile("-n(\d+) \S+")
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received").on("command").on("urbandictionary", "ud" events.on("received").on("command").on("urbandictionary", "ud"
).hook(self.ud, min_args=1, ).hook(self.ud, min_args=1,
help="Get the definition of a provided term", help="Get the definition of a provided term",
usage="<term>") usage="<term>")

View file

@ -5,9 +5,9 @@ import Utils
URL_WEATHER = "http://api.openweathermap.org/data/2.5/weather" URL_WEATHER = "http://api.openweathermap.org/data/2.5/weather"
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("weather").hook( events.on("received").on("command").on("weather").hook(
self.weather, min_args=1, self.weather, min_args=1,
help="Get current weather data for a provided location", help="Get current weather data for a provided location",
usage="<location>") usage="<location>")

View file

@ -3,9 +3,9 @@ import Utils
URL_WIKIPEDIA = "https://en.wikipedia.org/w/api.php" URL_WIKIPEDIA = "https://en.wikipedia.org/w/api.php"
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("wiki", "wi" events.on("received").on("command").on("wiki", "wi"
).hook(self.wikipedia, min_args=1) ).hook(self.wikipedia, min_args=1)
def wikipedia(self, event): def wikipedia(self, event):

View file

@ -8,12 +8,12 @@ REGEX_CHARHEX = re.compile("\\\\:(\S{4})")
class Module(object): class Module(object):
_name = "Wolfram|Alpha" _name = "Wolfram|Alpha"
def __init__(self, bot): def __init__(self, bot, events):
bot.events.on("received").on("command").on("wolframalpha", "wa" self.bot = bot
events.on("received").on("command").on("wolframalpha", "wa"
).hook(self.wa, min_args=1, help= ).hook(self.wa, min_args=1, help=
"Evauate a given string on Wolfram|Alpha", "Evauate a given string on Wolfram|Alpha",
usage="<query>") usage="<query>")
self.bot = bot
def wa(self, event): def wa(self, event):
soup = Utils.get_url(URL_WA, get_params={"input": event["args"], soup = Utils.get_url(URL_WA, get_params={"input": event["args"],

View file

@ -2,21 +2,21 @@ import time
import Utils import Utils
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("message").on("channel" events.on("received").on("message").on("channel"
).hook(self.channel_message) ).hook(self.channel_message)
bot.events.on("self").on("message").on("channel" events.on("self").on("message").on("channel"
).hook(self.self_channel_message) ).hook(self.self_channel_message)
bot.events.on("received").on("command").on("words" events.on("received").on("command").on("words"
).hook(self.words, channel_only=True, ).hook(self.words, channel_only=True,
usage="<nickname>", help= usage="<nickname>", help=
"See how many words you or the given nickname have used") "See how many words you or the given nickname have used")
bot.events.on("received").on("command").on("trackword" events.on("received").on("command").on("trackword"
).hook(self.track_word, min_args=1, ).hook(self.track_word, min_args=1,
help="Start tracking a word", usage="<word>", help="Start tracking a word", usage="<word>",
permission="track-word") permission="track-word")
bot.events.on("received").on("command").on("wordusers" events.on("received").on("command").on("wordusers"
).hook(self.word_users, min_args=1, ).hook(self.word_users, min_args=1,
help="Show who has used a tracked word the most", help="Show who has used a tracked word the most",
usage="<word>") usage="<word>")

View file

@ -17,15 +17,16 @@ ARROW_UP = "▲"
ARROW_DOWN = "" ARROW_DOWN = ""
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot, events):
self.bot = bot self.bot = bot
bot.events.on("received").on("command").on("yt", "youtube" self.events = events
events.on("received").on("command").on("yt", "youtube"
).hook(self.yt, ).hook(self.yt,
help="Find a video on youtube", usage="[query]") help="Find a video on youtube", usage="[query]")
bot.events.on("received").on("message").on("channel").hook( events.on("received").on("message").on("channel").hook(
self.channel_message) self.channel_message)
bot.events.on("postboot").on("configure").on( events.on("postboot").on("configure").on(
"channelset").assure_call(setting="auto-youtube", "channelset").assure_call(setting="auto-youtube",
help="Disable/Enable automatically getting info from youtube URLs", help="Disable/Enable automatically getting info from youtube URLs",
validate=Utils.bool_or_none) validate=Utils.bool_or_none)
@ -102,6 +103,6 @@ class Module(object):
youtube_id = match.group(1) youtube_id = match.group(1)
video_details = self.video_details(youtube_id) video_details = self.video_details(youtube_id)
if video_details: if video_details:
self.bot.events.on("send").on("stdout").call(target=event[ self.events.on("send").on("stdout").call(target=event[
"channel"], message=video_details, module_name="Youtube", "channel"], message=video_details, module_name="Youtube",
server=event["server"]) server=event["server"])

View file

@ -37,7 +37,7 @@ for server_detail in server_details:
if not server == None: if not server == None:
servers.append(server) servers.append(server)
if len(servers): if len(servers):
bot.events.on("boot").on("done").call() bot._events.on("boot").on("done").call()
for server in servers: for server in servers:
if not bot.connect(server): if not bot.connect(server):
sys.stderr.write("failed to connect to '%s', exiting\r\n" % ( sys.stderr.write("failed to connect to '%s', exiting\r\n" % (