Give modules event objects with "context"s, to facilitate purging all the event
hooks for a module
This commit is contained in:
parent
90ce92dc39
commit
b7cf524e98
67 changed files with 476 additions and 440 deletions
120
EventManager.py
120
EventManager.py
|
@ -1,10 +1,13 @@
|
|||
import time, traceback
|
||||
import itertools, time, traceback
|
||||
|
||||
PRIORITY_URGENT = 0
|
||||
PRIORITY_HIGH = 1
|
||||
PRIORITY_MEDIUM = 2
|
||||
PRIORITY_LOW = 3
|
||||
|
||||
DEFAULT_PRIORITY = PRIORITY_LOW
|
||||
DEFAULT_DELIMITER = "."
|
||||
|
||||
class Event(object):
|
||||
def __init__(self, bot, name, **kwargs):
|
||||
self.bot = bot
|
||||
|
@ -21,7 +24,7 @@ class Event(object):
|
|||
self.eaten = True
|
||||
|
||||
class EventCallback(object):
|
||||
def __init__(self, function, bot, priority, **kwargs):
|
||||
def __init__(self, function, bot, priority, kwargs):
|
||||
self.function = function
|
||||
self.bot = bot
|
||||
self.priority = priority
|
||||
|
@ -50,6 +53,28 @@ class MultipleEventHook(object):
|
|||
returns.append(event_hook.call(**kwargs))
|
||||
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):
|
||||
def __init__(self, bot, name=None, parent=None):
|
||||
self.bot = bot
|
||||
|
@ -57,10 +82,9 @@ class EventHook(object):
|
|||
self.parent = parent
|
||||
self._children = {}
|
||||
self._hooks = []
|
||||
self._hook_notify = None
|
||||
self._child_notify = None
|
||||
self._call_notify = None
|
||||
self._stored_events = []
|
||||
self._context_hooks = {}
|
||||
self._current_context = None
|
||||
|
||||
def _make_event(self, kwargs):
|
||||
return Event(self.bot, self.name, **kwargs)
|
||||
|
@ -71,14 +95,28 @@ class EventHook(object):
|
|||
while not parent == None and not parent.name == None:
|
||||
path.append(parent.name)
|
||||
parent = parent.parent
|
||||
return ".".join(path[::-1])
|
||||
return DEFAULT_DELIMITER.join(path[::-1])
|
||||
|
||||
def hook(self, function, priority=PRIORITY_LOW, replay=False, **kwargs):
|
||||
callback = EventCallback(function, self.bot, priority, **kwargs)
|
||||
if self._hook_notify:
|
||||
self._hook_notify(self, callback)
|
||||
def new_context(self, context):
|
||||
return EventHookContext(self, context)
|
||||
|
||||
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.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:
|
||||
for kwargs in self._stored_events:
|
||||
|
@ -88,24 +126,37 @@ class EventHook(object):
|
|||
def _unhook(self, 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:
|
||||
event_chain = subevent.split(delimiter)
|
||||
event_obj = self
|
||||
for event_name in event_chain:
|
||||
event_obj = event_obj.get_child(event_name)
|
||||
if not context == None:
|
||||
event_obj = event_obj.new_context(context)
|
||||
return event_obj
|
||||
|
||||
if extra_subevents:
|
||||
multiple_event_hook = MultipleEventHook()
|
||||
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 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):
|
||||
results = self.call(max=max, **kwargs)
|
||||
def call_for_result(self, default=None, **kwargs):
|
||||
results = self.call_limited(0, **kwargs)
|
||||
return default if not len(results) else results[0]
|
||||
def assure_call(self, **kwargs):
|
||||
if not self._stored_events == None:
|
||||
|
@ -123,15 +174,10 @@ class EventHook(object):
|
|||
start = time.monotonic()
|
||||
|
||||
event = self._make_event(kwargs)
|
||||
if self._call_notify:
|
||||
self._call_notify(self, event)
|
||||
|
||||
called = 0
|
||||
returns = []
|
||||
for hook in self._hooks:
|
||||
if maximum and called == maximum:
|
||||
break
|
||||
if event.eaten:
|
||||
for hook in self.get_hooks():
|
||||
if (maximum and called == maximum) or event.eaten:
|
||||
break
|
||||
try:
|
||||
returns.append(hook.call(event))
|
||||
|
@ -155,28 +201,30 @@ class EventHook(object):
|
|||
if not child_name_lower in self._children:
|
||||
self._children[child_name_lower] = EventHook(self.bot,
|
||||
child_name_lower, self)
|
||||
if self._child_notify:
|
||||
self._child_notify(self, self._children[
|
||||
child_name_lower])
|
||||
return self._children[child_name_lower]
|
||||
|
||||
def remove_child(self, child_name):
|
||||
child_name_lower = child_name.lower()
|
||||
if child_name_lower in self._children:
|
||||
del self._children[child_name_lower]
|
||||
def get_children(self):
|
||||
return self._children.keys()
|
||||
|
||||
def check_purge(self):
|
||||
if len(self._hooks) == 0 and len(self._children
|
||||
) == 0 and not self.parent == None:
|
||||
self.parent.remove_child(self.name)
|
||||
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):
|
||||
return self._hooks
|
||||
def get_children(self):
|
||||
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
|
||||
return self._hooks + list(itertools.chain.from_iterable(
|
||||
self._context_hooks.values()))
|
||||
|
|
22
IRCBot.py
22
IRCBot.py
|
@ -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 ModuleManager, Timer
|
||||
|
@ -13,21 +13,21 @@ class Bot(object):
|
|||
self.servers = {}
|
||||
self.running = True
|
||||
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.line_handler = IRCLineHandler.LineHandler(self)
|
||||
self.line_handler = IRCLineHandler.LineHandler(self, self._events)
|
||||
self.timers = []
|
||||
self.events.on("timer").on("reconnect").hook(self.reconnect)
|
||||
self.events.on("boot").on("done").hook(self.setup_timers)
|
||||
self._events.on("timer").on("reconnect").hook(self.reconnect)
|
||||
self._events.on("boot").on("done").hook(self.setup_timers)
|
||||
|
||||
def add_server(self, id, hostname, port, password, ipv4, tls,
|
||||
nickname, username, realname, connect=False):
|
||||
new_server = IRCServer.Server(id, hostname, port, password,
|
||||
ipv4, tls, nickname, username, realname, self)
|
||||
new_server = IRCServer.Server(self, self._events, id, hostname,
|
||||
port, password, ipv4, tls, nickname, username, realname)
|
||||
if not new_server.get_setting("connect", True):
|
||||
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):
|
||||
self.connect(new_server)
|
||||
return new_server
|
||||
|
@ -55,7 +55,9 @@ class Bot(object):
|
|||
self.del_setting("timer-%s" % timer.id)
|
||||
def add_timer(self, event_name, delay, next_due=None, id=None, persist=True,
|
||||
**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:
|
||||
timer.id = id
|
||||
elif persist:
|
||||
|
|
|
@ -8,47 +8,38 @@ RE_CHANTYPES = re.compile(r"\bCHANTYPES=(\W+)(?:\b|$)")
|
|||
RE_MODES = re.compile(r"[-+]\w+")
|
||||
|
||||
class LineHandler(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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,
|
||||
default_event=True)
|
||||
bot.events.on("raw").on("005").hook(self.handle_005)
|
||||
bot.events.on("raw").on("311").hook(self.handle_311,
|
||||
default_event=True)
|
||||
bot.events.on("raw").on("332").hook(self.handle_332)
|
||||
bot.events.on("raw").on("333").hook(self.handle_333)
|
||||
bot.events.on("raw").on("353").hook(self.handle_353,
|
||||
default_event=True)
|
||||
bot.events.on("raw").on("366").hook(self.handle_366,
|
||||
default_event=True)
|
||||
bot.events.on("raw").on("421").hook(self.handle_421,
|
||||
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)
|
||||
events.on("raw").on("001").hook(self.handle_001, default_event=True)
|
||||
events.on("raw").on("005").hook(self.handle_005)
|
||||
events.on("raw").on("311").hook(self.handle_311, default_event=True)
|
||||
events.on("raw").on("332").hook(self.handle_332)
|
||||
events.on("raw").on("333").hook(self.handle_333)
|
||||
events.on("raw").on("353").hook(self.handle_353, default_event=True)
|
||||
events.on("raw").on("366").hook(self.handle_366, default_event=True)
|
||||
events.on("raw").on("421").hook(self.handle_421, default_event=True)
|
||||
events.on("raw").on("352").hook(self.handle_352, default_event=True)
|
||||
events.on("raw").on("324").hook(self.handle_324, default_event=True)
|
||||
events.on("raw").on("329").hook(self.handle_329, default_event=True)
|
||||
events.on("raw").on("433").hook(self.handle_433, default_event=True)
|
||||
events.on("raw").on("477").hook(self.handle_477, default_event=True)
|
||||
|
||||
bot.events.on("raw").on("JOIN").hook(self.join)
|
||||
bot.events.on("raw").on("PART").hook(self.part)
|
||||
bot.events.on("raw").on("QUIT").hook(self.quit)
|
||||
bot.events.on("raw").on("NICK").hook(self.nick)
|
||||
bot.events.on("raw").on("MODE").hook(self.mode)
|
||||
bot.events.on("raw").on("KICK").hook(self.kick)
|
||||
bot.events.on("raw").on("INVITE").hook(self.invite)
|
||||
bot.events.on("raw").on("TOPIC").hook(self.topic)
|
||||
bot.events.on("raw").on("PRIVMSG").hook(self.privmsg)
|
||||
bot.events.on("raw").on("NOTICE").hook(self.notice)
|
||||
events.on("raw").on("JOIN").hook(self.join)
|
||||
events.on("raw").on("PART").hook(self.part)
|
||||
events.on("raw").on("QUIT").hook(self.quit)
|
||||
events.on("raw").on("NICK").hook(self.nick)
|
||||
events.on("raw").on("MODE").hook(self.mode)
|
||||
events.on("raw").on("KICK").hook(self.kick)
|
||||
events.on("raw").on("INVITE").hook(self.invite)
|
||||
events.on("raw").on("TOPIC").hook(self.topic)
|
||||
events.on("raw").on("PRIVMSG").hook(self.privmsg)
|
||||
events.on("raw").on("NOTICE").hook(self.notice)
|
||||
|
||||
bot.events.on("raw").on("CAP").hook(self.cap)
|
||||
bot.events.on("raw").on("authenticate").hook(self.authenticate)
|
||||
events.on("raw").on("CAP").hook(self.cap)
|
||||
events.on("raw").on("authenticate").hook(self.authenticate)
|
||||
|
||||
def handle(self, server, line):
|
||||
original_line = line
|
||||
|
@ -66,7 +57,7 @@ class LineHandler(object):
|
|||
line = line[:-1]
|
||||
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
|
||||
for hook in hooks:
|
||||
if hook.kwargs.get("default_event", False):
|
||||
|
@ -74,15 +65,15 @@ class LineHandler(object):
|
|||
break
|
||||
|
||||
#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)
|
||||
if default_event or not hooks:
|
||||
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,
|
||||
line_split=original_line.split(" "), number=command)
|
||||
else:
|
||||
self.bot.events.on("received").on(command).call(
|
||||
self.events.on("received").on(command).call(
|
||||
line=original_line, line_split=original_line.split(" "),
|
||||
command=command, server=server)
|
||||
|
||||
|
@ -116,7 +107,7 @@ class LineHandler(object):
|
|||
match = re.search(RE_CHANTYPES, isupport_line)
|
||||
if match:
|
||||
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"])
|
||||
|
||||
# whois respose (nickname, username, realname, hostname)
|
||||
|
@ -135,7 +126,7 @@ class LineHandler(object):
|
|||
channel = event["server"].get_channel(event["args"][1])
|
||||
|
||||
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"],
|
||||
topic=event["arbitrary"])
|
||||
|
||||
|
@ -147,7 +138,7 @@ class LineHandler(object):
|
|||
channel = event["server"].get_channel(event["args"][0])
|
||||
|
||||
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)
|
||||
|
||||
# on-join channel topic set by/at
|
||||
|
@ -162,7 +153,7 @@ class LineHandler(object):
|
|||
|
||||
channel.set_topic_setter(nickname, username, hostname)
|
||||
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,
|
||||
server=event["server"])
|
||||
|
||||
|
@ -202,12 +193,12 @@ class LineHandler(object):
|
|||
user.hostname = hostname
|
||||
channel.add_user(user)
|
||||
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"])
|
||||
else:
|
||||
if channel.name in event["server"].attempted_join:
|
||||
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"])
|
||||
channel.send_mode()
|
||||
|
||||
|
@ -220,7 +211,7 @@ class LineHandler(object):
|
|||
|
||||
if not event["server"].is_own_nickname(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"])
|
||||
channel.remove_user(user)
|
||||
user.part_channel(channel)
|
||||
|
@ -228,7 +219,7 @@ class LineHandler(object):
|
|||
event["server"].remove_user(user)
|
||||
else:
|
||||
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"])
|
||||
|
||||
# unknown command sent by us, oops!
|
||||
|
@ -244,7 +235,7 @@ class LineHandler(object):
|
|||
if not event["server"].is_own_nickname(nickname):
|
||||
user = event["server"].get_user(nickname)
|
||||
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"])
|
||||
else:
|
||||
event["server"].disconnect()
|
||||
|
@ -252,13 +243,13 @@ class LineHandler(object):
|
|||
# the server is telling us about its capabilities!
|
||||
def cap(self, event):
|
||||
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,
|
||||
server=event["server"])
|
||||
|
||||
# the server is asking for authentication
|
||||
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"])
|
||||
|
||||
# someone has changed their nickname
|
||||
|
@ -271,13 +262,13 @@ class LineHandler(object):
|
|||
old_nickname = user.nickname
|
||||
user.set_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,
|
||||
user=user, server=event["server"])
|
||||
else:
|
||||
old_nickname = event["server"].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,
|
||||
old_nickname=old_nickname)
|
||||
|
||||
|
@ -303,7 +294,7 @@ class LineHandler(object):
|
|||
channel.change_mode(remove, mode, args.pop(0))
|
||||
else:
|
||||
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"])
|
||||
elif event["server"].is_own_nickname(target):
|
||||
modes = RE_MODES.findall(event["arbitrary"] or args[1])
|
||||
|
@ -311,7 +302,7 @@ class LineHandler(object):
|
|||
remove = chunk[0] == "-"
|
||||
for mode in chunk[1:]:
|
||||
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"])
|
||||
|
||||
# I've been invited somewhere
|
||||
|
@ -320,7 +311,7 @@ class LineHandler(object):
|
|||
event["prefix"])
|
||||
target_channel = event["arbitrary"]
|
||||
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,
|
||||
server=event["server"])
|
||||
|
||||
|
@ -337,12 +328,12 @@ class LineHandler(object):
|
|||
message = message.replace("\01ACTION ", "", 1)[:-1]
|
||||
if target[0] in event["server"].channel_types:
|
||||
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,
|
||||
channel=channel, action=action, server=event["server"])
|
||||
channel.buffer.add_line(user.nickname, message, action)
|
||||
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,
|
||||
action=action, server=event["server"])
|
||||
user.buffer.add_line(user.nickname, message, action)
|
||||
|
@ -355,18 +346,18 @@ class LineHandler(object):
|
|||
message_split = message.split(" ")
|
||||
target = event["args"][0]
|
||||
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,
|
||||
server=event["server"])
|
||||
else:
|
||||
user = event["server"].get_user(nickname)
|
||||
if target[0] in event["server"].channel_types:
|
||||
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,
|
||||
user=user, server=event["server"], channel=channel)
|
||||
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,
|
||||
user=user, server=event["server"])
|
||||
|
||||
|
@ -413,9 +404,9 @@ class LineHandler(object):
|
|||
|
||||
if not event["server"].is_own_nickname(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,
|
||||
server=event["server"])
|
||||
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"])
|
||||
|
|
17
IRCServer.py
17
IRCServer.py
|
@ -11,10 +11,11 @@ if hasattr(ssl, "PROTOCOL_TLS"):
|
|||
OUR_TLS_PROTOCOL = ssl.PROTOCOL_TLS
|
||||
|
||||
class Server(object):
|
||||
def __init__(self, id, hostname, port, password, ipv4, tls,
|
||||
nickname, username, realname, bot):
|
||||
def __init__(self, bot, events, id, hostname, port, password, ipv4,
|
||||
tls, nickname, username, realname):
|
||||
self.connected = False
|
||||
self.bot = bot
|
||||
self.events = events
|
||||
self.id = id
|
||||
self.target_hostname = hostname
|
||||
self.port = port
|
||||
|
@ -65,7 +66,7 @@ class Server(object):
|
|||
context.options |= ssl.OP_NO_TLSv1
|
||||
self.socket = context.wrap_socket(self.socket)
|
||||
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):
|
||||
return "IRCServer.Server(%s)" % self.__str__()
|
||||
|
@ -78,7 +79,7 @@ class Server(object):
|
|||
|
||||
def connect(self):
|
||||
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:
|
||||
self.send_pass(self.password)
|
||||
|
@ -137,7 +138,7 @@ class Server(object):
|
|||
if not self.has_user(nickname):
|
||||
user_id = self.get_user_id(nickname)
|
||||
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)
|
||||
self.users[new_user.nickname_lower] = new_user
|
||||
self.new_users.add(new_user)
|
||||
|
@ -162,7 +163,7 @@ class Server(object):
|
|||
channel_id = self.get_channel_id(channel_name)
|
||||
new_channel = IRCChannel.Channel(channel_name, channel_id,
|
||||
self, self.bot)
|
||||
self.bot.events.on("new").on("channel").call(
|
||||
self.events.on("new").on("channel").call(
|
||||
channel=new_channel, server=self)
|
||||
self.channels[new_channel.name] = new_channel
|
||||
return self.channels[channel_name.lower()]
|
||||
|
@ -311,13 +312,13 @@ class Server(object):
|
|||
if self.has_channel(target):
|
||||
channel = self.get_channel(target)
|
||||
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,
|
||||
channel=channel, action=action, server=self)
|
||||
else:
|
||||
user = self.get_user(target)
|
||||
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,
|
||||
user=user, action=action, server=self)
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import gc, glob, imp, inspect, os, sys
|
||||
import gc, glob, imp, inspect, os, sys, uuid
|
||||
|
||||
class ModuleManager(object):
|
||||
def __init__(self, bot, directory="modules"):
|
||||
def __init__(self, bot, events, directory="modules"):
|
||||
self.bot = bot
|
||||
self.events = events
|
||||
self.directory = directory
|
||||
self.modules = {}
|
||||
self.waiting_requirement = {}
|
||||
|
@ -39,17 +40,22 @@ class ModuleManager(object):
|
|||
return None
|
||||
else:
|
||||
break
|
||||
import_name = "bitbot_%s" % name
|
||||
module = imp.load_source(import_name, filename)
|
||||
module = imp.load_source(name, filename)
|
||||
|
||||
if not hasattr(module, "Module"):
|
||||
raise ImportError("module '%s' doesn't have a Module class.")
|
||||
if not inspect.isclass(module.Module):
|
||||
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"):
|
||||
module_object._name = name.title()
|
||||
module_object._event_context = event_context
|
||||
module_object._is_unloaded = False
|
||||
module_object._import_name = import_name
|
||||
module_object._import_name = name
|
||||
|
||||
assert not module_object._name in self.modules, (
|
||||
"module name '%s' attempted to be used twice.")
|
||||
return module_object
|
||||
|
@ -62,7 +68,7 @@ class ModuleManager(object):
|
|||
sys.stderr.write("module '%s' not loaded: Could not resolve import.\n" % filename)
|
||||
return
|
||||
if module:
|
||||
self.modules[module._name] = module
|
||||
self.modules[module._import_name] = module
|
||||
if name in self.waiting_requirement:
|
||||
for filename in self.waiting_requirement:
|
||||
self.load_module(filename)
|
||||
|
@ -74,23 +80,3 @@ class ModuleManager(object):
|
|||
for filename in self.list_modules():
|
||||
if whitelist == None or filename in whitelist:
|
||||
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))
|
||||
|
|
8
Timer.py
8
Timer.py
|
@ -1,9 +1,11 @@
|
|||
import time, uuid
|
||||
|
||||
class Timer(object):
|
||||
def __init__(self, bot, event_name, delay, next_due=None, **kwargs):
|
||||
self.id = uuid.uuid4().hex
|
||||
def __init__(self, id, bot, events, event_name, delay,
|
||||
next_due=None, **kwargs):
|
||||
self.id = id
|
||||
self.bot = bot
|
||||
self.events = events
|
||||
self.event_name = event_name
|
||||
self.delay = delay
|
||||
if next_due:
|
||||
|
@ -26,7 +28,7 @@ class Timer(object):
|
|||
def call(self):
|
||||
self._done = True
|
||||
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)
|
||||
|
||||
def redo(self):
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("invite").hook(
|
||||
self.on_invite)
|
||||
def __init__(self, bot, events):
|
||||
events.on("received").on("invite").hook(self.on_invite)
|
||||
|
||||
def on_invite(self, event):
|
||||
if event["server"].get_setting("accept-invites", True):
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
bot.events.on("received").on("command").on("changenickname"
|
||||
events.on("received").on("command").on("changenickname"
|
||||
).hook(self.change_nickname, permission="changenickname",
|
||||
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,
|
||||
help="Send a raw IRC line through the bot",
|
||||
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,
|
||||
help="Part from a channel",
|
||||
usage="<#channel>")
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import Utils
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
|
||||
bot.events.on("postboot").on("configure").on(
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="automode",
|
||||
help="Disable/Enable automode",
|
||||
validate=Utils.bool_or_none)
|
||||
|
||||
bot.events.on("channel").on("mode").hook(self.on_mode)
|
||||
bot.events.on("received").on("join").hook(self.on_join)
|
||||
events.on("channel").on("mode").hook(self.on_mode)
|
||||
events.on("received").on("join").hook(self.on_join)
|
||||
|
||||
def on_mode(self, event):
|
||||
if event["channel"].get_setting("automode", False):
|
||||
|
|
|
@ -2,9 +2,9 @@ import Utils
|
|||
|
||||
class Module(object):
|
||||
_name = "BTC"
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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",
|
||||
usage="[currency]")
|
||||
|
||||
|
|
|
@ -7,10 +7,11 @@ URL_BITLYSHORTEN = "https://api-ssl.bitly.com/v3/shorten"
|
|||
REGEX_URL = re.compile("https?://", re.I)
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
bot.events.on("get").on("shortlink").hook(self.shortlink)
|
||||
bot.events.on("received").on("command").on("shorten"
|
||||
self.events = events
|
||||
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.",
|
||||
usage="<url>")
|
||||
|
||||
|
@ -25,7 +26,7 @@ class Module(object):
|
|||
return data["data"]["url"]
|
||||
|
||||
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"])
|
||||
if link:
|
||||
event["stdout"].write("Short URL: %s" % link)
|
||||
|
|
|
@ -7,12 +7,12 @@ REGEX_BOOKID = re.compile("id=([\w\-]+)")
|
|||
|
||||
class Module(object):
|
||||
_name = "ISBN"
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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",
|
||||
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",
|
||||
min_args=1, usage="<book title>")
|
||||
|
||||
|
|
|
@ -2,57 +2,57 @@ import Utils
|
|||
|
||||
class Module(object):
|
||||
_name = "Channel Op"
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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",
|
||||
min_args=1, help="Kick a user from the channel",
|
||||
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",
|
||||
min_args=1, help="Ban a user/hostmask from the channel",
|
||||
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",
|
||||
min_args=1, help="Unban a user/hostmask from the channel",
|
||||
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",
|
||||
min_args=1, help="Kickban a user from the channel",
|
||||
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",
|
||||
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",
|
||||
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",
|
||||
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",
|
||||
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)
|
||||
|
||||
bot.events.on("postboot").on("configure").on(
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="highlight-spam-threshold",
|
||||
help="Set the number of nicknames in a message that "
|
||||
"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",
|
||||
help="Enable/Disable highlight spam protection",
|
||||
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",
|
||||
help="Enable/Disable banning highlight spammers "
|
||||
"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",
|
||||
help="Set ban format ($n = nick, $u = username, $h = hostname)")
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received.numeric.001").hook(
|
||||
self.on_connect)
|
||||
bot.events.on("self.join").hook(self.on_join)
|
||||
bot.events.on("self.kick").hook(self.on_kick)
|
||||
def __init__(self, bot, events):
|
||||
events.on("received.numeric.001").hook(self.on_connect)
|
||||
events.on("self.join").hook(self.on_join)
|
||||
events.on("self.kick").hook(self.on_kick)
|
||||
|
||||
def on_connect(self, event):
|
||||
channels = event["server"].get_setting("autojoin", [])
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
bot.events.on("preprocess").on("command").hook(
|
||||
self.preprocess_command)
|
||||
events.on("preprocess").on("command").hook(self.preprocess_command)
|
||||
|
||||
def preprocess_command(self, event):
|
||||
if event["is_channel"] and event["hook"].kwargs.get(
|
||||
|
|
|
@ -26,26 +26,26 @@ THIRD_COLUMN = list(range(1, 37))[2::3]
|
|||
REGEX_STREET = re.compile("street([1-9]|1[0-2])$")
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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")
|
||||
bot.events.on("received").on("command").on("resetcoins").hook(
|
||||
events.on("received").on("command").on("resetcoins").hook(
|
||||
self.reset_coins, permission="resetcoins",
|
||||
min_args=1, help=
|
||||
"Reset a specified user's coins to %s" % str(DECIMAL_ZERO),
|
||||
usage="<target>")
|
||||
bot.events.on("received.command.richest").hook(
|
||||
events.on("received.command.richest").hook(
|
||||
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")
|
||||
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=
|
||||
"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",
|
||||
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",
|
||||
usage="<type> <amount>", protect_registered=True)
|
||||
|
||||
|
@ -53,7 +53,7 @@ class Module(object):
|
|||
until_next_hour = 60-now.second
|
||||
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,
|
||||
next_due=time.time()+until_next_hour)
|
||||
|
||||
|
|
|
@ -45,27 +45,28 @@ class StdErr(Out):
|
|||
self.module_name, Utils.FONT_RESET)
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
bot.events.on("received").on("message").on("channel").hook(
|
||||
self.events = events
|
||||
events.on("received").on("message").on("channel").hook(
|
||||
self.channel_message)
|
||||
bot.events.on("received").on("message").on("private").hook(
|
||||
events.on("received").on("message").on("private").hook(
|
||||
self.private_message)
|
||||
bot.events.on("received").on("command").on("help").hook(self.help,
|
||||
events.on("received").on("command").on("help").hook(self.help,
|
||||
help="Show help for commands", usage="<command>")
|
||||
bot.events.on("received").on("command").on("usage").hook(self.usage,
|
||||
events.on("received").on("command").on("usage").hook(self.usage,
|
||||
help="Show usage help for commands", min_args=1,
|
||||
usage="<command>")
|
||||
bot.events.on("received").on("command").on("more").hook(self.more,
|
||||
events.on("received").on("command").on("more").hook(self.more,
|
||||
help="Get more output from the last command", skip_out=True)
|
||||
|
||||
bot.events.on("postboot").on("configure").on(
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="command-prefix",
|
||||
help="Set the command prefix used in this channel")
|
||||
|
||||
bot.events.on("new").on("user", "channel").hook(self.new)
|
||||
bot.events.on("send").on("stdout").hook(self.send_stdout)
|
||||
bot.events.on("send").on("stderr").hook(self.send_stderr)
|
||||
events.on("new").on("user", "channel").hook(self.new)
|
||||
events.on("send").on("stdout").hook(self.send_stdout)
|
||||
events.on("send").on("stderr").hook(self.send_stderr)
|
||||
|
||||
def new(self, event):
|
||||
if "user" in event:
|
||||
|
@ -76,10 +77,10 @@ class Module(object):
|
|||
target.last_stderr = None
|
||||
|
||||
def has_command(self, command):
|
||||
return command.lower() in self.bot.events.on("received").on(
|
||||
return command.lower() in self.events.on("received").on(
|
||||
"command").get_children()
|
||||
def get_hook(self, command):
|
||||
return self.bot.events.on("received").on("command").on(command
|
||||
return self.events.on("received").on("command").on(command
|
||||
).get_hooks()[0]
|
||||
|
||||
def is_highlight(self, server, s):
|
||||
|
@ -108,7 +109,7 @@ class Module(object):
|
|||
stdout, stderr = StdOut(module_name, target), StdErr(module_name,
|
||||
target)
|
||||
|
||||
returns = self.bot.events.on("preprocess").on("command"
|
||||
returns = self.events.on("preprocess").on("command"
|
||||
).call(hook=hook, user=event["user"], server=event["server"],
|
||||
target=target, is_channel=is_channel)
|
||||
for returned in returns:
|
||||
|
@ -129,7 +130,7 @@ class Module(object):
|
|||
args = " ".join(args_split)
|
||||
server = event["server"]
|
||||
user = event["user"]
|
||||
self.bot.events.on("received").on("command").on(command
|
||||
self.events.on("received").on("command").on(command
|
||||
).call_limited(1, user=user, server=server,
|
||||
target=target, buffer=buffer, args=args,
|
||||
args_split=args_split, stdout=stdout, stderr=stderr,
|
||||
|
@ -162,9 +163,9 @@ class Module(object):
|
|||
def help(self, event):
|
||||
if event["args"]:
|
||||
command = event["args_split"][0].lower()
|
||||
if command in self.bot.events.on("received").on(
|
||||
if command in self.events.on("received").on(
|
||||
"command").get_children():
|
||||
hooks = self.bot.events.on("received").on("command").on(command).get_hooks()
|
||||
hooks = self.events.on("received").on("command").on(command).get_hooks()
|
||||
if hooks and "help" in hooks[0].kwargs:
|
||||
event["stdout"].write("%s: %s" % (command, hooks[0].kwargs["help"]))
|
||||
else:
|
||||
|
@ -173,8 +174,8 @@ class Module(object):
|
|||
event["stderr"].write("Unknown command '%s'" % command)
|
||||
else:
|
||||
help_available = []
|
||||
for child in self.bot.events.on("received").on("command").get_children():
|
||||
hooks = self.bot.events.on("received").on("command").on(child).get_hooks()
|
||||
for child in self.events.on("received").on("command").get_children():
|
||||
hooks = self.events.on("received").on("command").on(child).get_hooks()
|
||||
if hooks and "help" in hooks[0].kwargs:
|
||||
help_available.append(child)
|
||||
help_available = sorted(help_available)
|
||||
|
@ -182,9 +183,9 @@ class Module(object):
|
|||
|
||||
def usage(self, event):
|
||||
command = event["args_split"][0].lower()
|
||||
if command in self.bot.events.on("received").on(
|
||||
if command in self.events.on("received").on(
|
||||
"command").get_children():
|
||||
hooks = self.bot.events.on("received").on("command").on(command).get_hooks()
|
||||
hooks = self.events.on("received").on("command").on(command).get_hooks()
|
||||
if hooks and "usage" in hooks[0].kwargs:
|
||||
event["stdout"].write("Usage: %s %s" % (command, hooks[0].kwargs["usage"]))
|
||||
else:
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import datetime
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("message").on("private").hook(
|
||||
self.private_message)
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
events.on("received").on("message").on("private").hook(
|
||||
self.private_message)
|
||||
|
||||
def private_message(self, event):
|
||||
if event["message"][0] == "\x01" and event["message"][-1] == "\x01":
|
||||
|
|
|
@ -5,9 +5,9 @@ import Utils
|
|||
URL_WORDNIK = "http://api.wordnik.com:80/v4/word.json/%s/definitions"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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",
|
||||
usage="<phrase>")
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ import socket
|
|||
|
||||
class Module(object):
|
||||
_name = "DNS"
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("command").on("dns").hook(
|
||||
def __init__(self, bot, events):
|
||||
events.on("received").on("command").on("dns").hook(
|
||||
self.dns, min_args=1,
|
||||
help="Get all addresses for a given hostname (IPv4/IPv6)",
|
||||
usage="<hostname>")
|
||||
|
|
|
@ -7,23 +7,24 @@ DUCK_LAST_SEEN = datetime.datetime.now()
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.log = IRCLogging.Log
|
||||
self.bot = bot
|
||||
self.events = events
|
||||
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!")
|
||||
bot.events.on("received.command.bang").hook(self.duck_bang,
|
||||
events.on("received.command.bang").hook(self.duck_bang,
|
||||
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.")
|
||||
|
||||
# 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!")
|
||||
# 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.")
|
||||
# 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.")
|
||||
|
||||
now = datetime.datetime.now()
|
||||
|
@ -35,22 +36,22 @@ class Module(object):
|
|||
tricky = next_duck_time - now.second
|
||||
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",
|
||||
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",
|
||||
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",
|
||||
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.events.on("received.numeric.366").hook(self.bootstrap)
|
||||
events.on("received.numeric.366").hook(self.bootstrap)
|
||||
|
||||
def bootstrap(self, event):
|
||||
for server in self.bot.servers.values():
|
||||
|
@ -198,7 +199,7 @@ class Module(object):
|
|||
|
||||
def set_decoy(self, event):
|
||||
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)
|
||||
|
||||
# def coins(self, event):
|
||||
|
|
|
@ -4,8 +4,8 @@ URL_GEOIP = "http://ip-api.com/json/%s"
|
|||
|
||||
class Module(object):
|
||||
_name = "GeoIP"
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("command").on("geoip").hook(
|
||||
def __init__(self, bot, events):
|
||||
events.on("received").on("command").on("geoip").hook(
|
||||
self.geoip, min_args=1,
|
||||
help="Get geoip data on a given IPv4/IPv6 address",
|
||||
usage="<IP>")
|
||||
|
|
|
@ -6,9 +6,9 @@ import Utils
|
|||
URL_GOOGLESEARCH = "https://www.googleapis.com/customsearch/v1"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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",
|
||||
usage="[search term]")
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import hashlib
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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",
|
||||
usage="<algo> <string>")
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ URL_HAVEIBEENPWNEDAPI = "https://haveibeenpwned.com/api/v2/breachedaccount/%s"
|
|||
URL_HAVEIBEENPWNED = "https://haveibeenpwned.com/"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("command").on("beenpwned").hook(
|
||||
def __init__(self, bot, events):
|
||||
events.on("received").on("command").on("beenpwned").hook(
|
||||
self.beenpwned, min_args=1,
|
||||
help="Find out if a username, email or similar has appeared "
|
||||
"in any hacked databases", usage="<username/email>")
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
class Module(object):
|
||||
_name = "IDs"
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received.command.myid").hook(self.my_id,
|
||||
def __init__(self, bot, events):
|
||||
events.on("received.command.myid").hook(self.my_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,
|
||||
help="Show the current channel's ID")
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ URL_IMDBTITLE = "http://imdb.com/title/%s"
|
|||
|
||||
class Module(object):
|
||||
_name = "IMDb"
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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,
|
||||
help="Search for a given title on IMDb",
|
||||
usage="<movie/tv title>")
|
||||
|
|
|
@ -5,12 +5,12 @@ SECONDS_MAX = Utils.SECONDS_WEEKS*8
|
|||
SECONDS_MAX_DESCRIPTION = "8 weeks"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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,
|
||||
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):
|
||||
seconds = Utils.from_pretty_time(event["args_split"][0])
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("numeric").on("001").hook(self.do_join)
|
||||
def __init__(self, bot, events):
|
||||
events.on("received").on("numeric").on("001").hook(self.do_join)
|
||||
|
||||
def do_join(self, event):
|
||||
event["server"].send_join("#bitbot")
|
||||
|
|
|
@ -5,20 +5,21 @@ REGEX_KARMA = re.compile("(.*)(\+{2,}|\-{2,})$")
|
|||
KARMA_DELAY_SECONDS = 3
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
bot.events.on("new").on("user").hook(self.new_user)
|
||||
bot.events.on("received").on("message").on("channel").hook(
|
||||
self.events = events
|
||||
events.on("new").on("user").hook(self.new_user)
|
||||
events.on("received").on("message").on("channel").hook(
|
||||
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",
|
||||
usage="[target]")
|
||||
bot.events.on("received").on("command").on("resetkarma").hook(
|
||||
events.on("received").on("command").on("resetkarma").hook(
|
||||
self.reset_karma, permission="resetkarma",
|
||||
min_args=1, help="Reset a specified karma to 0",
|
||||
usage="<target>")
|
||||
|
||||
bot.events.on("postboot").on("configure").on(
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="karma-verbose",
|
||||
help="Disable/Enable automatically responding to karma changes",
|
||||
validate=Utils.bool_or_none)
|
||||
|
@ -46,13 +47,13 @@ class Module(object):
|
|||
else:
|
||||
event["server"].del_setting(setting)
|
||||
if verbose:
|
||||
self.bot.events.on("send").on("stdout").call(
|
||||
self.events.on("send").on("stdout").call(
|
||||
module_name="Karma", target=event["channel"],
|
||||
message="%s now has %d karma" % (target, karma))
|
||||
event["user"].last_karma = time.time()
|
||||
elif verbose:
|
||||
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")
|
||||
elif verbose:
|
||||
event["stderr"].write("Try again in a couple of seconds")
|
||||
|
|
|
@ -5,14 +5,14 @@ import Utils
|
|||
URL_SCROBBLER = "http://ws.audioscrobbler.com/2.0/"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
|
||||
bot.events.on("postboot").on("configure").on(
|
||||
events.on("postboot").on("configure").on(
|
||||
"set").assure_call(setting="lastfm",
|
||||
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,
|
||||
help="Get the last listened to track from a user",
|
||||
usage="[username]")
|
||||
|
|
|
@ -22,13 +22,13 @@ def del_setting(user, setting):
|
|||
|
||||
class Module(object):
|
||||
_name = "Aliases"
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
bot.events.on("new").on("user").hook(self.new_user)
|
||||
bot.events.on("received").on("nick").hook(self.nickname_change)
|
||||
bot.events.on("received").on("command").on("alias").hook(
|
||||
events.on("new").on("user").hook(self.new_user)
|
||||
events.on("received").on("nick").hook(self.nickname_change)
|
||||
events.on("received").on("command").on("alias").hook(
|
||||
self.alias)
|
||||
#bot.events.on("received").on("command").on("mainalias").hook(
|
||||
#events.on("received").on("command").on("mainalias").hook(
|
||||
# self.main_alias)
|
||||
|
||||
def new_user(self, event):
|
||||
|
|
|
@ -2,10 +2,10 @@ import base64
|
|||
import EventManager
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("numeric").on("001"
|
||||
def __init__(self, bot, events):
|
||||
events.on("received").on("numeric").on("001"
|
||||
).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",
|
||||
help="Set bot's nickserv password", usage="<password>",
|
||||
private_only=True)
|
||||
|
|
|
@ -20,29 +20,29 @@ class Module(object):
|
|||
PASSENGER_ACTIVITIES = ["U", "P", "R"]
|
||||
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._client = None
|
||||
bot.events.on("received").on("command").on("nrtrains"
|
||||
events.on("received").on("command").on("nrtrains"
|
||||
).hook(self.trains, min_args=1,
|
||||
help="Get train/bus services for a station (Powered by NRE)",
|
||||
usage="<crs_id>")
|
||||
bot.events.on("received").on("command").on("nrservice"
|
||||
events.on("received").on("command").on("nrservice"
|
||||
).hook(self.service, min_args=1,
|
||||
help="Get train service information for a UID, headcode or RID (Powered by NRE)",
|
||||
usage="<service_id>")
|
||||
bot.events.on("received").on("command").on("nrhead"
|
||||
events.on("received").on("command").on("nrhead"
|
||||
).hook(self.head, min_args=1,
|
||||
help="Get information for a given headcode/UID/RID (Powered by NRE)",
|
||||
usage="<headcode>")
|
||||
bot.events.on("received").on("command").on("nrcode"
|
||||
events.on("received").on("command").on("nrcode"
|
||||
).hook(self.service_code, min_args=1,
|
||||
help="Get the text for a given delay/cancellation code (Powered by NRE)",
|
||||
usage="<code>")
|
||||
bot.events.on("telegram").on("command").on("nrtrains").hook(self.trains)
|
||||
bot.events.on("telegram").on("command").on("nrcode").hook(self.service_code)
|
||||
bot.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("nrtrains").hook(self.trains)
|
||||
events.on("telegram").on("command").on("nrcode").hook(self.service_code)
|
||||
events.on("telegram").on("command").on("nrhead").hook(self.head)
|
||||
events.on("telegram").on("command").on("nrservice").hook(self.service)
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import EventManager
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("numeric").on("001").hook(
|
||||
def __init__(self, bot, events):
|
||||
events.on("received").on("numeric").on("001").hook(
|
||||
self.on_connect, priority=EventManager.PRIORITY_URGENT)
|
||||
|
||||
def on_connect(self, event):
|
||||
|
|
|
@ -5,26 +5,26 @@ REQUIRES_IDENTIFY = ("You need to be identified to use that command "
|
|||
"(/msg %s register | /msg %s identify)")
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
bot.events.on("new").on("user").hook(self.new_user)
|
||||
bot.events.on("preprocess").on("command").hook(
|
||||
events.on("new").on("user").hook(self.new_user)
|
||||
events.on("preprocess").on("command").hook(
|
||||
self.preprocess_command)
|
||||
bot.events.on("received").on("part").hook(self.on_part)
|
||||
bot.events.on("received").on("command").on("identify"
|
||||
events.on("received").on("part").hook(self.on_part)
|
||||
events.on("received").on("command").on("identify"
|
||||
).hook(self.identify, private_only=True, min_args=1,
|
||||
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,
|
||||
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")
|
||||
|
||||
bot.events.on("received.command.mypermissions").hook(
|
||||
events.on("received.command.mypermissions").hook(
|
||||
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")
|
||||
bot.events.on("received.command.removepermission").hook(
|
||||
events.on("received.command.removepermission").hook(
|
||||
self.remove_permission, min_args=2, permission="removepermission")
|
||||
|
||||
def new_user(self, event):
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received.command.ping").hook(
|
||||
self.pong, help="Ping pong!")
|
||||
def __init__(self, bot, events):
|
||||
events.on("received.command.ping").hook(self.pong, help="Ping pong!")
|
||||
|
||||
def pong(self, event):
|
||||
event["stdout"].write("Pong!")
|
||||
|
|
|
@ -2,37 +2,37 @@ import datetime
|
|||
import EventManager
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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)
|
||||
bot.events.on("self").on("message").on("channel").hook(
|
||||
events.on("self").on("message").on("channel").hook(
|
||||
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)
|
||||
bot.events.on("received").on("notice").on("private").hook(
|
||||
events.on("received").on("notice").on("private").hook(
|
||||
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)
|
||||
|
||||
bot.events.on("received").on("join").hook(self.join)
|
||||
bot.events.on("self").on("join").hook(self.self_join)
|
||||
events.on("received").on("join").hook(self.join)
|
||||
events.on("self").on("join").hook(self.self_join)
|
||||
|
||||
bot.events.on("received").on("part").hook(self.part)
|
||||
bot.events.on("self").on("part").hook(self.self_part)
|
||||
events.on("received").on("part").hook(self.part)
|
||||
events.on("self").on("part").hook(self.self_part)
|
||||
|
||||
bot.events.on("received").on("nick").hook(self.on_nick)
|
||||
bot.events.on("self").on("nick").hook(self.on_nick)
|
||||
events.on("received").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)
|
||||
bot.events.on("self").on("kick").hook(self.self_kick)
|
||||
events.on("received").on("kick").hook(self.kick)
|
||||
events.on("self").on("kick").hook(self.self_kick)
|
||||
|
||||
bot.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("topic").hook(self.on_topic)
|
||||
events.on("received").on("numeric").on("333").hook(self.on_333)
|
||||
|
||||
def print_line(self, event, line, channel=None):
|
||||
timestamp = datetime.datetime.now().isoformat()
|
||||
|
|
|
@ -55,8 +55,8 @@ QUOTES = {
|
|||
}
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("get.quit-quote").hook(self.quote)
|
||||
def __init__(self, bot, events):
|
||||
events.on("get.quit-quote").hook(self.quote)
|
||||
|
||||
def quote(self, event):
|
||||
quote = random.choice(list(QUOTES.items()))
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
import random, time
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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,
|
||||
help="Added a quote to a category",
|
||||
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,
|
||||
help="Find a quote within a category",
|
||||
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,
|
||||
help="Delete a quote from a category",
|
||||
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,
|
||||
help="Get a random quote from a category",
|
||||
usage="<category>")
|
||||
|
|
|
@ -2,11 +2,11 @@ import random, uuid
|
|||
|
||||
class Module(object):
|
||||
_name = "Random"
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("command").on("random",
|
||||
def __init__(self, bot, events):
|
||||
events.on("received").on("command").on("random",
|
||||
"rand").hook(self.random, help="Get a random number",
|
||||
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")
|
||||
|
||||
def random(self, event):
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import base64
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
bot.events.on("preprocess.connect").hook(self.preprocess_connect)
|
||||
bot.events.on("received.cap").hook(self.on_cap)
|
||||
bot.events.on("received.authenticate").hook(self.on_authenticate)
|
||||
bot.events.on("received.numeric").on(
|
||||
events.on("preprocess.connect").hook(self.preprocess_connect)
|
||||
events.on("received.cap").hook(self.on_cap)
|
||||
events.on("received.authenticate").hook(self.on_authenticate)
|
||||
events.on("received.numeric").on(
|
||||
"902", "903", "904", "905", "906", "907", "908").hook(self.on_90x)
|
||||
|
||||
def preprocess_connect(self, event):
|
||||
|
|
|
@ -5,16 +5,17 @@ REGEX_SPLIT = re.compile("(?<!\\\\)/")
|
|||
REGEX_SED = re.compile("^s/")
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
bot.events.on("received").on("message").on("channel").hook(
|
||||
self.events = events
|
||||
events.on("received").on("message").on("channel").hook(
|
||||
self.channel_message)
|
||||
|
||||
bot.events.on("postboot").on("configure").on(
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="sed",
|
||||
help="Disable/Enable sed in a channel",
|
||||
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",
|
||||
help="Disable/Enable sed only looking at the messages "
|
||||
"sent by the user", validate=Utils.bool_or_none)
|
||||
|
@ -49,7 +50,7 @@ class Module(object):
|
|||
pattern = re.compile(sed_split[1], regex_flags)
|
||||
except:
|
||||
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"],
|
||||
message="Invalid regex in pattern")
|
||||
return
|
||||
|
@ -66,6 +67,6 @@ class Module(object):
|
|||
prefix = "* %s" % line.sender
|
||||
else:
|
||||
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"],
|
||||
message="%s %s" % (prefix, new_message))
|
||||
|
|
|
@ -2,10 +2,10 @@ import time
|
|||
import Utils
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("message").on("channel"
|
||||
def __init__(self, bot, events):
|
||||
events.on("received").on("message").on("channel"
|
||||
).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,
|
||||
help="Find out when a user was last seen",
|
||||
usage="<username>")
|
||||
|
|
|
@ -1,31 +1,32 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
self.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)
|
||||
bot.events.on("postboot").on("configure").on("channelset"
|
||||
events.on("postboot").on("configure").on("channelset"
|
||||
).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",
|
||||
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",
|
||||
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,
|
||||
help="Set a specified setting for the current channel",
|
||||
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,
|
||||
help="Set a specified setting for the current channel",
|
||||
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,
|
||||
help="Get a specified setting for the current channel",
|
||||
usage="<setting>", min_args=1, require_mode="o")
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
import signal
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
self.events = events
|
||||
signal.signal(signal.SIGINT, self.SIGINT)
|
||||
signal.signal(signal.SIGUSR1, self.SIGUSR1)
|
||||
|
||||
def SIGINT(self, signum, frame):
|
||||
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():
|
||||
reason = "Leaving"
|
||||
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")
|
||||
server.send_quit(reason)
|
||||
self.bot.register_write(server)
|
||||
|
|
|
@ -9,9 +9,9 @@ REGEX_SOUNDCLOUD = "https?://soundcloud.com/([^/]+)/([^/]+)"
|
|||
|
||||
class Module(object):
|
||||
_name = "SoundCloud"
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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")
|
||||
|
||||
def soundcloud(self, event):
|
||||
|
|
|
@ -4,8 +4,8 @@ import Utils
|
|||
URL_SPOTIFY = "https://api.spotify.com/v1/search"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("command").on("spotify").hook(
|
||||
def __init__(self, bot, events):
|
||||
events.on("received").on("command").on("spotify").hook(
|
||||
self.spotify, help="Search for a track on spotify",
|
||||
min_args=1)
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@ import time
|
|||
import Utils
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.boot_time = time.time()
|
||||
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")
|
||||
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")
|
||||
|
||||
def uptime(self, event):
|
||||
|
|
|
@ -2,8 +2,8 @@ import random
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received.command.strax").hook(
|
||||
def __init__(self, bot, events):
|
||||
events.on("received.command.strax").hook(
|
||||
self.strax, help="Suggests a glorious method of battle for the glory of the Sontaran Empire, through IRC!")
|
||||
|
||||
def strax(self, event):
|
||||
|
|
|
@ -8,11 +8,12 @@ from threading import Thread
|
|||
class Module(Thread):
|
||||
_name = "telegram"
|
||||
|
||||
def __init__(self, dolphin):
|
||||
key = dolphin.config.get("telegram-api-key")
|
||||
def __init__(self, bot, events):
|
||||
key = bot.config.get("telegram-api-key")
|
||||
if not key: return
|
||||
|
||||
self.dolphin = dolphin
|
||||
self.bot = bot
|
||||
self.events = events
|
||||
|
||||
self.updater = Updater(key)
|
||||
self.dispatcher = self.updater.dispatcher
|
||||
|
@ -23,7 +24,7 @@ class Module(Thread):
|
|||
self.dispatcher.add_handler(command_handler)
|
||||
|
||||
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):
|
||||
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),
|
||||
"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):
|
||||
self.updater.stop()
|
||||
|
|
|
@ -20,30 +20,30 @@ PLATFORM_TYPES = ["Northbound", "Southbound", "Eastbound", "Westbound", "Inner R
|
|||
|
||||
class Module(object):
|
||||
_name = "TFL"
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
self.result_map = {}
|
||||
bot.events.on("received").on("command").on("tflbus"
|
||||
events.on("received").on("command").on("tflbus"
|
||||
).hook(self.bus, min_args=1,
|
||||
help="Get bus due times for a TfL bus stop",
|
||||
usage="<stop_id>")
|
||||
bot.events.on("received").on("command").on("tflline"
|
||||
events.on("received").on("command").on("tflline"
|
||||
).hook(self.line,
|
||||
help="Get line status for TfL underground lines",
|
||||
usage="<line_name>")
|
||||
bot.events.on("received").on("command").on("tflsearch"
|
||||
events.on("received").on("command").on("tflsearch"
|
||||
).hook(self.search, min_args=1,
|
||||
help="Get a list of TfL stop IDs for a given name",
|
||||
usage="<name>")
|
||||
bot.events.on("received").on("command").on("tflvehicle"
|
||||
events.on("received").on("command").on("tflvehicle"
|
||||
).hook(self.vehicle, min_args=1,
|
||||
help="Get information for a given vehicle",
|
||||
usage="<ID>")
|
||||
bot.events.on("received").on("command").on("tflstop"
|
||||
events.on("received").on("command").on("tflstop"
|
||||
).hook(self.stop, min_args=1,
|
||||
help="Get information for a given stop",
|
||||
usage="<stop_id>")
|
||||
bot.events.on("received").on("command").on("tflservice"
|
||||
events.on("received").on("command").on("tflservice"
|
||||
).hook(self.service, min_args=1,
|
||||
help="Get service information and arrival estimates",
|
||||
usage="<service index>")
|
||||
|
|
|
@ -5,9 +5,9 @@ import Utils
|
|||
URL_THESAURUS = "http://words.bighugelabs.com/api/2/%s/%s/json"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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,
|
||||
help="Get synonyms/antonyms for a provided phrase",
|
||||
usage="<word> [type]")
|
||||
|
|
|
@ -4,8 +4,8 @@ import Utils
|
|||
REGEX_URL = re.compile("https?://\S+", re.I)
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("command").on("title", "t").hook(
|
||||
def __init__(self, bot, events):
|
||||
events.on("received").on("command").on("title", "t").hook(
|
||||
self.title, help="Get the title of the provided or most "
|
||||
"recent URL.", usage="[URL]")
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import EventManager
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("message").on("channel"
|
||||
def __init__(self, bot, events):
|
||||
events.on("received").on("message").on("channel"
|
||||
).hook(self.channel_message,
|
||||
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 "
|
||||
"user the next time they talk in a channel"),
|
||||
channel_only=True, usage="<username> <message>")
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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",
|
||||
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",
|
||||
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 "
|
||||
"todo list", usage="<item number>")
|
||||
|
||||
|
|
|
@ -6,14 +6,14 @@ URL_TRAKT = "https://api-v2launch.trakt.tv/users/%s/watching"
|
|||
URL_TRAKTSLUG = "https://trakt.tv/%s/%s"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
bot.events.on("received").on("command").on("nowwatching",
|
||||
events.on("received").on("command").on("nowwatching",
|
||||
"nw").hook(self.now_watching,
|
||||
help="Get what you or another user is now watching "
|
||||
"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")
|
||||
|
||||
def now_watching(self, event):
|
||||
|
|
|
@ -6,8 +6,8 @@ URL_LANGUAGES = "https://cloud.google.com/translate/docs/languages"
|
|||
REGEX_LANGUAGES = re.compile("(\w+)?:(\w+)? ")
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("command").on("translate", "tr").hook(
|
||||
def __init__(self, bot, events):
|
||||
events.on("received").on("command").on("translate", "tr").hook(
|
||||
self.translate, help="Translate the provided phrase or the "
|
||||
"last line seen.", usage="[phrase]")
|
||||
|
||||
|
|
|
@ -11,9 +11,9 @@ REGEX_TWITTERURL = re.compile(
|
|||
"https?://(?:www\.)?twitter.com/[^/]+/status/(\d+)", re.I)
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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",
|
||||
usage="[@username/URL/ID]")
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@ UPCITEMDB_URL = "https://api.upcitemdb.com/prod/trial/lookup"
|
|||
|
||||
class Module(object):
|
||||
_name = "UPC"
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
bot.events.on("received").on("command").on(
|
||||
events.on("received").on("command").on(
|
||||
"upc", "ean", "gtin").hook(
|
||||
self.upc, min_args=1, usage="<UPC|EAN>",
|
||||
help="Look up a product by UPC or EAN")
|
||||
|
|
|
@ -5,8 +5,8 @@ URL_URBANDICTIONARY = "http://api.urbandictionary.com/v0/define"
|
|||
REGEX_DEFNUMBER = re.compile("-n(\d+) \S+")
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("command").on("urbandictionary", "ud"
|
||||
def __init__(self, bot, events):
|
||||
events.on("received").on("command").on("urbandictionary", "ud"
|
||||
).hook(self.ud, min_args=1,
|
||||
help="Get the definition of a provided term",
|
||||
usage="<term>")
|
||||
|
|
|
@ -5,9 +5,9 @@ import Utils
|
|||
URL_WEATHER = "http://api.openweathermap.org/data/2.5/weather"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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,
|
||||
help="Get current weather data for a provided location",
|
||||
usage="<location>")
|
||||
|
|
|
@ -3,9 +3,9 @@ import Utils
|
|||
URL_WIKIPEDIA = "https://en.wikipedia.org/w/api.php"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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)
|
||||
|
||||
def wikipedia(self, event):
|
||||
|
|
|
@ -8,12 +8,12 @@ REGEX_CHARHEX = re.compile("\\\\:(\S{4})")
|
|||
|
||||
class Module(object):
|
||||
_name = "Wolfram|Alpha"
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("command").on("wolframalpha", "wa"
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("wolframalpha", "wa"
|
||||
).hook(self.wa, min_args=1, help=
|
||||
"Evauate a given string on Wolfram|Alpha",
|
||||
usage="<query>")
|
||||
self.bot = bot
|
||||
|
||||
def wa(self, event):
|
||||
soup = Utils.get_url(URL_WA, get_params={"input": event["args"],
|
||||
|
|
|
@ -2,21 +2,21 @@ import time
|
|||
import Utils
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
self.bot = bot
|
||||
bot.events.on("received").on("message").on("channel"
|
||||
events.on("received").on("message").on("channel"
|
||||
).hook(self.channel_message)
|
||||
bot.events.on("self").on("message").on("channel"
|
||||
events.on("self").on("message").on("channel"
|
||||
).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,
|
||||
usage="<nickname>", help=
|
||||
"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,
|
||||
help="Start tracking a word", usage="<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,
|
||||
help="Show who has used a tracked word the most",
|
||||
usage="<word>")
|
||||
|
|
|
@ -17,15 +17,16 @@ ARROW_UP = "▲"
|
|||
ARROW_DOWN = "▼"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, events):
|
||||
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,
|
||||
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)
|
||||
|
||||
bot.events.on("postboot").on("configure").on(
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="auto-youtube",
|
||||
help="Disable/Enable automatically getting info from youtube URLs",
|
||||
validate=Utils.bool_or_none)
|
||||
|
@ -102,6 +103,6 @@ class Module(object):
|
|||
youtube_id = match.group(1)
|
||||
video_details = self.video_details(youtube_id)
|
||||
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",
|
||||
server=event["server"])
|
||||
|
|
2
start.py
2
start.py
|
@ -37,7 +37,7 @@ for server_detail in server_details:
|
|||
if not server == None:
|
||||
servers.append(server)
|
||||
if len(servers):
|
||||
bot.events.on("boot").on("done").call()
|
||||
bot._events.on("boot").on("done").call()
|
||||
for server in servers:
|
||||
if not bot.connect(server):
|
||||
sys.stderr.write("failed to connect to '%s', exiting\r\n" % (
|
||||
|
|
Loading…
Reference in a new issue