Refactor everything to use delimited events

This commit is contained in:
jesopo 2018-09-19 13:25:12 +01:00
parent b86ca6088f
commit fcbb7c960c
51 changed files with 160 additions and 200 deletions

View file

@ -21,8 +21,8 @@ class Bot(object):
self.log = Logging.Log(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.reconnect").hook(self.reconnect)
self._events.on("boot.done").hook(self.setup_timers)
def add_server(self, id, alias, hostname, port, password, ipv4, tls,
nickname, username, realname, connect=False):
@ -31,7 +31,7 @@ class Bot(object):
realname)
if not new_server.get_setting("connect", True):
return
self._events.on("new").on("server").call(server=new_server)
self._events.on("new.server").call(server=new_server)
if connect and new_server.get_setting("connect", True):
self.connect(new_server)
return new_server

View file

@ -70,7 +70,7 @@ class Server(object):
if self.tls:
self.tls_wrap()
self.cached_fileno = self.socket.fileno()
self.events.on("timer").on("rejoin").hook(self.try_rejoin)
self.events.on("timer.rejoin").hook(self.try_rejoin)
def __repr__(self):
return "IRCServer.Server(%s)" % self.__str__()
@ -164,8 +164,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.events.on("new").on("user").call(
user=new_user, server=self)
self.events.on("new.user").call(user=new_user, server=self)
self.users[new_user.nickname_lower] = new_user
self.new_users.add(new_user)
return self.users[Utils.irc_lower(self, nickname)]
@ -189,8 +188,8 @@ class Server(object):
channel_id = self.get_channel_id(channel_name)
new_channel = IRCChannel.Channel(channel_name, channel_id,
self, self.bot)
self.events.on("new").on("channel").call(
channel=new_channel, server=self)
self.events.on("new.channel").call(channel=new_channel,
server=self)
self.channels[new_channel.name] = new_channel
return self.channels[Utils.irc_lower(self, channel_name)]
def get_channel_id(self, channel_name):
@ -364,13 +363,13 @@ class Server(object):
if self.has_channel(target):
channel = self.get_channel(target)
channel.buffer.add_line(None, message, action, True)
self.events.on("self").on("message").on("channel").call(
self.events.on("self.message.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.events.on("self").on("message").on("private").call(
self.events.on("self.message.private").call(
message=full_message, message_split=full_message_split,
user=user, action=action, server=self)

View file

@ -2,7 +2,7 @@ import Utils
class Module(object):
def __init__(self, bot, events, exports):
events.on("received").on("invite").hook(self.on_invite)
events.on("received.invite").hook(self.on_invite)
exports.add("serverset", {"setting": "accept-invites",
"help": "Set whether I accept invites on this server",
"validate": Utils.bool_or_none})

View file

@ -4,9 +4,8 @@ class Module(object):
_name = "BTC"
def __init__(self, bot, events, exports):
self.bot = bot
events.on("received").on("command").on("btc").hook(
self.btc, help="Get the exchange rate of bitcoins",
usage="[currency]")
events.on("received.command.btc").hook(self.btc,
help="Get the exchange rate of bitcoins", usage="[currency]")
def btc(self, event):
currency = (event["args"] or "USD").upper()

View file

@ -9,11 +9,11 @@ class Module(object):
_name = "ISBN"
def __init__(self, bot, events, exports):
self.bot = bot
events.on("received").on("command").on("isbn").hook(
self.isbn, help="Get book information from a provided ISBN",
events.on("received.command.isbn").hook(self.isbn,
help="Get book information from a provided ISBN",
min_args=1, usage="<isbn>")
events.on("received").on("command").on("book").hook(
self.book, help="Get book information from a provided title",
events.on("received.command.book").hook(self.book,
help="Get book information from a provided title",
min_args=1, usage="<book title>")
def get_book(self, query, event):

View file

@ -2,7 +2,7 @@
class Module(object):
def __init__(self, bot, events, exports):
events.on("received").on("numeric").on("001").hook(self.do_join)
events.on("received.numeric.001").hook(self.do_join)
exports.add("serverset", {"setting": "bot-channel",
"help": "Set main channel"})

View file

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

View file

@ -61,7 +61,7 @@ class Module(object):
until_next_hour = 60-now.second
until_next_hour += ((60-(now.minute+1))*60)
events.on("timer").on("coin-interest").hook(self.interest)
events.on("timer.coin-interest").hook(self.interest)
bot.add_timer("coin-interest", INTEREST_INTERVAL, persist=False,
next_due=time.time()+until_next_hour)

View file

@ -67,8 +67,8 @@ class Module(object):
permission="unignore")
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)
events.on("send.stdout").hook(self.send_stdout)
events.on("send.stderr").hook(self.send_stderr)
exports.add("channelset", {"setting": "command-prefix",
"help": "Set the command prefix used in this channel"})
@ -89,7 +89,7 @@ class Module(object):
return command.lower() in self.events.on("received").on(
"command").get_children()
def get_hook(self, command):
return self.events.on("received").on("command").on(command
return self.events.on("received.command").on(command
).get_hooks()[0]
def is_highlight(self, server, s):
@ -122,7 +122,7 @@ class Module(object):
stdout, stderr = StdOut(module_name, target), StdErr(module_name,
target)
returns = self.events.on("preprocess").on("command"
returns = self.events.on("preprocess.command"
).call(hook=hook, user=event["user"], server=event["server"],
target=target, is_channel=is_channel, tags=event["tags"])
for returned in returns:
@ -143,7 +143,7 @@ class Module(object):
args = " ".join(args_split)
server = event["server"]
user = event["user"]
self.events.on("received").on("command").on(command
self.events.on("received.command").on(command
).call_limited(1, user=user, server=server,
target=target, buffer=buffer, args=args,
args_split=args_split, stdout=stdout, stderr=stderr,
@ -179,7 +179,7 @@ class Module(object):
command = event["args_split"][0].lower()
if command in self.events.on("received").on(
"command").get_children():
hooks = self.events.on("received").on("command").on(command).get_hooks()
hooks = self.events.on("received.command").on(command).get_hooks()
if hooks and "help" in hooks[0].kwargs:
event["stdout"].write("%s: %s" % (command, hooks[0].kwargs["help"]))
else:
@ -188,8 +188,8 @@ class Module(object):
event["stderr"].write("Unknown command '%s'" % command)
else:
help_available = []
for child in self.events.on("received").on("command").get_children():
hooks = self.events.on("received").on("command").on(child).get_hooks()
for child in self.events.on("received.command").get_children():
hooks = self.events.on("received.command").on(child).get_hooks()
if hooks and "help" in hooks[0].kwargs:
help_available.append(child)
help_available = sorted(help_available)
@ -204,7 +204,7 @@ class Module(object):
command = event["args_split"][0].lower()
if command in self.events.on("received").on(
"command").get_children():
hooks = self.events.on("received").on("command").on(command).get_hooks()
hooks = self.events.on("received.command").on(command).get_hooks()
if hooks and "usage" in hooks[0].kwargs:
event["stdout"].write("Usage: %s%s %s" % (command_prefix,
command, hooks[0].kwargs["usage"]))

View file

@ -4,8 +4,7 @@ import Utils
class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
events.on("received").on("message").on("private").hook(
self.private_message)
events.on("received.message.private").hook(self.private_message)
exports.add("serverset", {"setting": "ctcp-responses",
"help": "Set whether I respond to CTCPs on this server",
"validate": Utils.bool_or_none})

View file

@ -10,7 +10,7 @@ class Module(object):
until_next_hour = 60-now.second
until_next_hour += ((60-(now.minute+1))*60)
events.on("timer").on("database-backup").hook(self.backup)
events.on("timer.database-backup").hook(self.backup)
bot.add_timer("database-backup", BACKUP_INTERVAL, persist=False,
next_due=time.time()+until_next_hour)

View file

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

View file

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

View file

@ -5,10 +5,8 @@ URL_GEOIP = "http://ip-api.com/json/%s"
class Module(object):
_name = "GeoIP"
def __init__(self, bot, events, exports):
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>")
events.on("received.command.geoip").hook(self.geoip, min_args=1,
help="Get geoip data on a given IPv4/IPv6 address", usage="<IP>")
def geoip(self, event):
page = Utils.get_url(URL_GEOIP % event["args_split"][0],

View file

@ -8,9 +8,8 @@ URL_GOOGLESEARCH = "https://www.googleapis.com/customsearch/v1"
class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
events.on("received").on("command").on("google",
"g").hook(self.google, help="Google feeling lucky",
usage="[search term]")
events.on("received.command").on("google", "g").hook(self.google,
help="Google feeling lucky", usage="[search term]")
def google(self, event):
phrase = event["args"] or event["buffer"].get()

View file

@ -3,9 +3,8 @@ import hashlib
class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
events.on("received").on("command").on("hash"
).hook(self.hash, min_args=2, help="Hash a string",
usage="<algo> <string>")
events.on("received.command.hash").hook(self.hash, min_args=2,
help="Hash a string", usage="<algo> <string>")
def hash(self, event):
algorithm = event["args_split"][0].lower()

View file

@ -5,10 +5,9 @@ URL_HAVEIBEENPWNED = "https://haveibeenpwned.com/"
class Module(object):
def __init__(self, bot, events, exports):
events.on("received").on("command").on("beenpwned").hook(
self.beenpwned, min_args=1,
events.on("received.command.beenpwned").hook(self.beenpwned,
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>", min_args=1)
def beenpwned(self, event):
page = Utils.get_url(URL_HAVEIBEENPWNEDAPI % event["args"], json=True,

View file

@ -10,10 +10,8 @@ class Module(object):
_name = "IMDb"
def __init__(self, bot, events, exports):
self.bot = bot
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>")
events.on("received.command.imdb").hook(self.imdb, min_args=1,
help="Search for a given title on IMDb", usage="<movie/tv title>")
def imdb(self, event):
page = Utils.get_url(URL_OMDB, get_params={

View file

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

View file

@ -8,13 +8,13 @@ class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
self.events = events
events.on("new").on("user").hook(self.new_user)
events.on("received").on("message").on("channel").hook(
events.on("new.user").hook(self.new_user)
events.on("received.message.channel").hook(
self.channel_message, priority=EventManager.PRIORITY_MONITOR)
events.on("received").on("command").on("karma").hook(
events.on("received.command.karma").hook(
self.karma, help="Get your or someone else's karma",
usage="[target]")
events.on("received").on("command").on("resetkarma").hook(
events.on("received.command.resetkarma").hook(
self.reset_karma, permission="resetkarma",
min_args=1, help="Reset a specified karma to 0",
usage="<target>")
@ -46,7 +46,7 @@ class Module(object):
else:
event["server"].del_setting(setting)
if verbose:
self.events.on("send").on("stdout").call(
self.events.on("send.stdout").call(
module_name="Karma", target=event["channel"],
message="%s now has %d karma" % (target, karma))
event["user"].last_karma = time.time()

View file

@ -11,9 +11,8 @@ class Module(object):
exports.add("set", {"setting": "lastfm",
"help": "Set username on last.fm"})
events.on("received").on("command").on("np",
"listening", "nowplaying").hook(self.np,
help="Get the last listened to track from a user",
events.on("received.command").on("np", "listening", "nowplaying"
).hook(self.np, help="Get the last listened to track from a user",
usage="[username]")
def np(self, event):

View file

@ -24,12 +24,10 @@ class Module(object):
_name = "Aliases"
def __init__(self, bot, events, exports):
self.bot = bot
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)
#events.on("received").on("command").on("mainalias").hook(
# self.main_alias)
events.on("new.user").hook(self.new_user)
events.on("received.nick").hook(self.nickname_change)
events.on("received.command.alias").hook(self.alias)
#events.on("received.command.mainalias").hook(self.main_alias)
def new_user(self, event):
method_type = types.MethodType

View file

@ -3,7 +3,7 @@ import EventManager
class Module(object):
def __init__(self, bot, events, exports):
events.on("received").on("numeric").on("001").hook(self.on_connect,
events.on("received.numeric.001").hook(self.on_connect,
priority=EventManager.PRIORITY_URGENT)
exports.add("serverset", {"setting": "nickserv-password",

View file

@ -23,26 +23,26 @@ class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
self._client = None
events.on("received").on("command").on("nrtrains"
events.on("received.command.nrtrains"
).hook(self.trains, min_args=1,
help="Get train/bus services for a station (Powered by NRE)",
usage="<crs_id>")
events.on("received").on("command").on("nrservice"
events.on("received.command.nrservice"
).hook(self.service, min_args=1,
help="Get train service information for a UID, headcode or RID (Powered by NRE)",
usage="<service_id>")
events.on("received").on("command").on("nrhead"
events.on("received.command.nrhead"
).hook(self.head, min_args=1,
help="Get information for a given headcode/UID/RID (Powered by NRE)",
usage="<headcode>")
events.on("received").on("command").on("nrcode"
events.on("received.command.nrcode"
).hook(self.service_code, min_args=1,
help="Get the text for a given delay/cancellation code (Powered by NRE)",
usage="<code>")
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)
events.on("telegram.command.nrtrains").hook(self.trains)
events.on("telegram.command.nrcode").hook(self.service_code)
events.on("telegram.command.nrhead").hook(self.head)
events.on("telegram.command.nrservice").hook(self.service)
@property
def client(self):
@ -54,7 +54,7 @@ class Module(object):
header_token.TokenValue = token
client.set_options(soapheaders=header_token)
self._client = client
except:
except Exception as e:
pass
return self._client

View file

@ -2,8 +2,8 @@ import EventManager
class Module(object):
def __init__(self, bot, events, exports):
events.on("received").on("numeric").on("001").hook(
self.on_connect, priority=EventManager.PRIORITY_URGENT)
events.on("received.numeric.001").hook(self.on_connect,
priority=EventManager.PRIORITY_URGENT)
def on_connect(self, event):
commands = event["server"].get_setting("perform", [])

View file

@ -12,11 +12,11 @@ class Module(object):
self.preprocess_command)
events.on("received.part").hook(self.on_part)
events.on("received").on("command").on("identify"
).hook(self.identify, private_only=True, min_args=2,
events.on("received.command.identify").hook(self.identify,
private_only=True, min_args=2,
usage="<account> <password>", help="Identify yourself")
events.on("received").on("command").on("register"
).hook(self.register, private_only=True, min_args=1,
events.on("received.command.register").hook(self.register,
private_only=True, min_args=1,
usage="<password>", help="Register your nickname")
events.on("received.command.logout").hook(self.logout,
private_only=True, help="Sign out from the bot")

View file

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

View file

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

View file

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

View file

@ -8,8 +8,7 @@ class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
self.events = events
events.on("received").on("message").on("channel").hook(
self.channel_message)
events.on("received.message.channel").hook(self.channel_message)
exports.add("channelset", {"setting": "sed",
"help": "Disable/Enable sed in a channel",
@ -48,8 +47,8 @@ class Module(object):
pattern = re.compile(sed_split[1], regex_flags)
except:
traceback.print_exc()
self.events.on("send").on("stderr").call(target=event[
"channel"], module_name="Sed", server=event["server"],
self.events.on("send.stderr").call(target=event["channel"],
module_name="Sed", server=event["server"],
message="Invalid regex in pattern")
return
replace = sed_split[2].replace("\\/", "/")
@ -65,6 +64,6 @@ class Module(object):
prefix = "* %s" % line.sender
else:
prefix = "<%s>" % line.sender
self.events.on("send").on("stdout").call(target=event[
self.events.on("send.stdout").call(target=event[
"channel"], module_name="Sed", server=event["server"],
message="%s %s" % (prefix, new_message))

View file

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

View file

@ -57,8 +57,7 @@ class Module(object):
self.bot = bot
self.events = events
events.on("received").on("command").on("insult").hook(
self.dispense_insult)
events.on("received.command.insult").hook(self.dispense_insult)
def dispense_insult(self, event):
insult = [random.choice(INSULT_INTRO), random.choice(INSULT_PART_1),

View file

@ -10,8 +10,7 @@ class Module(object):
def SIGINT(self, signum, frame):
print()
self.events.on("signal").on("interrupt").call(signum=signum,
frame=frame)
self.events.on("signal.interrupt").call(signum=signum, frame=frame)
for server in self.bot.servers.values():
reason = "Leaving"

View file

@ -5,9 +5,8 @@ URL_SPOTIFY = "https://api.spotify.com/v1/search"
class Module(object):
def __init__(self, bot, events, exports):
events.on("received").on("command").on("spotify").hook(
self.spotify, help="Search for a track on spotify",
min_args=1)
events.on("received.command.spotify").hook(self.spotify, min_args=1,
help="Search for a track on spotify")
def spotify(self, event):
page = Utils.get_url(URL_SPOTIFY, get_params={"type": "track",

View file

@ -4,10 +4,10 @@ import Utils
class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
events.on("received").on("command").on("uptime"
).hook(self.uptime, help="Show my uptime")
events.on("received").on("command").on("stats"
).hook(self.stats, help="Show my network/channel/user stats")
events.on("received.command.uptime").hook(self.uptime,
help="Show my uptime")
events.on("received.command.stats").hook(self.stats,
help="Show my network/channel/user stats")
def uptime(self, event):
seconds = int(time.time()-self.bot.start_time)

View file

@ -24,7 +24,7 @@ class Module(Thread):
self.dispatcher.add_handler(command_handler)
self.updater.start_polling()
events.on("signal").on("interrupt").hook(self.sigint)
events.on("signal.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")
@ -46,7 +46,7 @@ class Module(Thread):
"stderr": IOWrapper(bot, message.chat_id, message.message_id),
"external": True,
}
self.events.on("telegram").on("command").on(command).call(**data)
self.events.on("telegram.command").on(command).call(**data)
def sigint(self, event):
self.updater.stop()

View file

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

View file

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

View file

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

View file

@ -2,13 +2,12 @@ import EventManager
class Module(object):
def __init__(self, bot, events, exports):
events.on("received").on("message").on("channel"
).hook(self.channel_message,
events.on("received.message.channel").hook(self.channel_message,
priority=EventManager.PRIORITY_HIGH)
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>")
events.on("received.command.to").hook(self.to, min_args=2,
help=("Relay a message to a user the next time they talk "
"in this channel"), channel_only=True,
usage="<username> <message>")
def channel_message(self, event):
messages = event["channel"].get_user_setting(event["user"].get_id(),

View file

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

View file

@ -8,10 +8,9 @@ URL_TRAKTSLUG = "https://trakt.tv/%s/%s"
class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
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]")
events.on("received.command").on("nowwatching", "nw").hook(
self.now_watching, usage="[username]",
help="Get what you or another user is now watching on trakt.tv")
exports.add("set", {"setting": "trakt",
"help": "Set username on trakt.tv"})

View file

@ -7,7 +7,7 @@ REGEX_LANGUAGES = re.compile("(\w+)?:(\w+)? ")
class Module(object):
def __init__(self, bot, events, exports):
events.on("received").on("command").on("translate", "tr").hook(
events.on("received.command").on("translate", "tr").hook(
self.translate, help="Translate the provided phrase or the "
"last line seen.", usage="[phrase]")

View file

@ -6,8 +6,7 @@ class Module(object):
_name = "UPC"
def __init__(self, bot, events, exports):
self.bot = bot
events.on("received").on("command").on(
"upc", "ean", "gtin").hook(
events.on("received.command").on("upc", "ean", "gtin").hook(
self.upc, min_args=1, usage="<UPC|EAN>",
help="Look up a product by UPC or EAN")

View file

@ -6,9 +6,8 @@ REGEX_DEFNUMBER = re.compile("-n(\d+) \S+")
class Module(object):
def __init__(self, bot, events, exports):
events.on("received").on("command").on("urbandictionary", "ud"
).hook(self.ud, min_args=1,
help="Get the definition of a provided term",
events.on("received.command").on("urbandictionary", "ud").hook(
self.ud, min_args=1, help="Get the definition of a provided term",
usage="<term>")
def ud(self, event):

View file

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

View file

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

View file

@ -8,7 +8,7 @@ class Module(object):
_name = "Wolfram|Alpha"
def __init__(self, bot, events, exports):
self.bot = bot
events.on("received").on("command").on("wolframalpha", "wa"
events.on("received.command").on("wolframalpha", "wa"
).hook(self.wa, min_args=1, help=
"Evauate a given string on Wolfram|Alpha",
usage="<query>")

View file

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

View file

@ -20,11 +20,9 @@ class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
self.events = events
events.on("received").on("command").on("yt", "youtube"
).hook(self.yt,
events.on("received.command").on("yt", "youtube").hook(self.yt,
help="Find a video on youtube", usage="[query]")
events.on("received").on("message").on("channel").hook(
self.channel_message)
events.on("received.message.channel").hook(self.channel_message)
exports.add("channelset", {"setting": "auto-youtube",
"help": "Disable/Enable automatically getting info from "
@ -101,6 +99,6 @@ class Module(object):
youtube_id = match.group(1)
video_details = self.video_details(youtube_id)
if video_details:
self.events.on("send").on("stdout").call(target=event[
"channel"], message=video_details, module_name="Youtube",
self.events.on("send.stdout").call(target=event["channel"],
message=video_details, module_name="Youtube",
server=event["server"])

View file

@ -36,7 +36,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.done").call()
for server in servers:
if not bot.connect(server):
sys.stderr.write("failed to connect to '%s', exiting\r\n" % (