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

View file

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

View file

@ -2,7 +2,7 @@ import Utils
class Module(object): class Module(object):
def __init__(self, bot, events, exports): 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", exports.add("serverset", {"setting": "accept-invites",
"help": "Set whether I accept invites on this server", "help": "Set whether I accept invites on this server",
"validate": Utils.bool_or_none}) "validate": Utils.bool_or_none})

View file

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

View file

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

View file

@ -2,7 +2,7 @@
class Module(object): class Module(object):
def __init__(self, bot, events, exports): 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", exports.add("serverset", {"setting": "bot-channel",
"help": "Set main channel"}) "help": "Set main channel"})

View file

@ -3,7 +3,7 @@
class Module(object): class Module(object):
def __init__(self, bot, events, exports): def __init__(self, bot, events, exports):
self.bot = bot 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): def preprocess_command(self, event):
if event["is_channel"] and event["hook"].kwargs.get( if event["is_channel"] and event["hook"].kwargs.get(

View file

@ -61,7 +61,7 @@ class Module(object):
until_next_hour = 60-now.second until_next_hour = 60-now.second
until_next_hour += ((60-(now.minute+1))*60) until_next_hour += ((60-(now.minute+1))*60)
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, bot.add_timer("coin-interest", INTEREST_INTERVAL, persist=False,
next_due=time.time()+until_next_hour) next_due=time.time()+until_next_hour)

View file

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

View file

@ -4,8 +4,7 @@ import Utils
class Module(object): class Module(object):
def __init__(self, bot, events, exports): def __init__(self, bot, events, exports):
self.bot = bot self.bot = bot
events.on("received").on("message").on("private").hook( events.on("received.message.private").hook(self.private_message)
self.private_message)
exports.add("serverset", {"setting": "ctcp-responses", exports.add("serverset", {"setting": "ctcp-responses",
"help": "Set whether I respond to CTCPs on this server", "help": "Set whether I respond to CTCPs on this server",
"validate": Utils.bool_or_none}) "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.second
until_next_hour += ((60-(now.minute+1))*60) 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, bot.add_timer("database-backup", BACKUP_INTERVAL, persist=False,
next_due=time.time()+until_next_hour) 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): class Module(object):
def __init__(self, bot, events, exports): def __init__(self, bot, events, exports):
self.bot = bot self.bot = bot
events.on("received").on("command").on("define").hook( events.on("received.command.define").hook(self.define,
self.define, help="Define a provided term", help="Define a provided term", usage="<phrase>")
usage="<phrase>")
def define(self, event): def define(self, event):
if event["args"]: if event["args"]:

View file

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

View file

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

View file

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

View file

@ -5,10 +5,9 @@ URL_HAVEIBEENPWNED = "https://haveibeenpwned.com/"
class Module(object): class Module(object):
def __init__(self, bot, events, exports): def __init__(self, bot, events, exports):
events.on("received").on("command").on("beenpwned").hook( events.on("received.command.beenpwned").hook(self.beenpwned,
self.beenpwned, min_args=1,
help="Find out if a username, email or similar has appeared " help="Find out if a username, email or similar has appeared "
"in any hacked databases", usage="<username/email>") "in any hacked databases", usage="<username/email>", min_args=1)
def beenpwned(self, event): def beenpwned(self, event):
page = Utils.get_url(URL_HAVEIBEENPWNEDAPI % event["args"], json=True, page = Utils.get_url(URL_HAVEIBEENPWNEDAPI % event["args"], json=True,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -3,7 +3,7 @@ import EventManager
class Module(object): class Module(object):
def __init__(self, bot, events, exports): 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) priority=EventManager.PRIORITY_URGENT)
exports.add("serverset", {"setting": "nickserv-password", exports.add("serverset", {"setting": "nickserv-password",

View file

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

View file

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

View file

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

View file

@ -5,36 +5,36 @@ class Module(object):
def __init__(self, bot, events, exports): def __init__(self, bot, events, exports):
self.bot = bot self.bot = bot
events.on("received").on("message").on("channel").hook( events.on("received.message.channel").hook(
self.channel_message, priority=EventManager.PRIORITY_HIGH) 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) 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) 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) 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) self.server_notice, priority=EventManager.PRIORITY_HIGH)
events.on("received").on("join").hook(self.join) events.on("received.join").hook(self.join)
events.on("self").on("join").hook(self.self_join) events.on("self.join").hook(self.self_join)
events.on("received").on("part").hook(self.part) events.on("received.part").hook(self.part)
events.on("self").on("part").hook(self.self_part) events.on("self.part").hook(self.self_part)
events.on("received").on("nick").hook(self.on_nick) events.on("received.nick").hook(self.on_nick)
events.on("self").on("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("received.kick").hook(self.kick)
events.on("self").on("kick").hook(self.self_kick) events.on("self.kick").hook(self.self_kick)
events.on("received").on("topic").hook(self.on_topic) events.on("received.topic").hook(self.on_topic)
events.on("received").on("numeric").on("333").hook(self.on_333) 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): def print_line(self, event, line, channel=None):
timestamp = datetime.datetime.now().isoformat() timestamp = datetime.datetime.now().isoformat()

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -24,7 +24,7 @@ class Module(Thread):
self.dispatcher.add_handler(command_handler) self.dispatcher.add_handler(command_handler)
self.updater.start_polling() self.updater.start_polling()
events.on("signal").on("interrupt").hook(self.sigint) events.on("signal.interrupt").hook(self.sigint)
def start(self, bot, update): def start(self, bot, update):
bot.send_message(chat_id=update.message.chat_id, text="`Dolphin, but Telegram`", parse_mode="Markdown") bot.send_message(chat_id=update.message.chat_id, text="`Dolphin, but Telegram`", parse_mode="Markdown")
@ -46,7 +46,7 @@ class Module(Thread):
"stderr": IOWrapper(bot, message.chat_id, message.message_id), "stderr": IOWrapper(bot, message.chat_id, message.message_id),
"external": True, "external": True,
} }
self.events.on("telegram").on("command").on(command).call(**data) self.events.on("telegram.command").on(command).call(**data)
def sigint(self, event): def sigint(self, event):
self.updater.stop() self.updater.stop()

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -7,7 +7,7 @@ REGEX_LANGUAGES = re.compile("(\w+)?:(\w+)? ")
class Module(object): class Module(object):
def __init__(self, bot, events, exports): 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 " self.translate, help="Translate the provided phrase or the "
"last line seen.", usage="[phrase]") "last line seen.", usage="[phrase]")

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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