2011-01-07 09:54:51 -06:00
|
|
|
"""
|
|
|
|
DrBotIRC - customizations of irclib, for dr.botzo
|
|
|
|
Copyright (C) 2011 Brian S. Stephan
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2012-12-18 22:15:52 -06:00
|
|
|
|
2011-01-07 09:54:51 -06:00
|
|
|
"""
|
|
|
|
|
2012-12-20 09:58:25 -06:00
|
|
|
import bisect
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
import copy
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
from ConfigParser import NoOptionError, NoSectionError
|
2012-07-15 21:32:12 -05:00
|
|
|
import logging
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
import re
|
|
|
|
import signal
|
2012-03-30 09:43:30 -05:00
|
|
|
from SimpleXMLRPCServer import SimpleXMLRPCServer
|
2011-01-07 09:54:51 -06:00
|
|
|
import socket
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
import sys
|
2012-03-30 09:43:30 -05:00
|
|
|
import thread
|
2011-01-07 09:54:51 -06:00
|
|
|
|
|
|
|
from extlib import irclib
|
|
|
|
|
2012-12-18 22:30:31 -06:00
|
|
|
|
|
|
|
log = logging.getLogger('drbotzo')
|
|
|
|
|
|
|
|
|
2012-03-30 09:43:30 -05:00
|
|
|
class DrBotzoMethods:
|
|
|
|
|
|
|
|
"""Methods to expose to the XML-RPC server."""
|
|
|
|
|
|
|
|
def __init__(self, irc):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Store the same stuff the core module would, since we'll probably
|
|
|
|
need it.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
irc the irc instance to save a reference to
|
|
|
|
|
|
|
|
"""
|
2012-03-30 09:43:30 -05:00
|
|
|
|
|
|
|
self.irc = irc
|
|
|
|
|
|
|
|
def say(self, target, message):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Say a message in a channel/to a nick.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
target the nick/channel to privmsg
|
|
|
|
message the message to send
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
"OK", since there's no other feedback to give.
|
2012-03-30 11:14:31 -05:00
|
|
|
|
2012-03-30 09:43:30 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
self.irc.server.privmsg(target, message)
|
|
|
|
return "OK"
|
|
|
|
|
|
|
|
def execute_module_method(self, modname, method, args):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Execute the method (with arguments) of the specified module.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
modname the loaded module to retrieve
|
|
|
|
method the method to call from that module
|
|
|
|
args the arguments to provide to the method as a tuple
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
An error string, or the outcome of the method call.
|
2012-03-30 11:14:31 -05:00
|
|
|
|
2012-03-30 09:43:30 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
for module in self.irc.modlist:
|
|
|
|
if modname == module.__class__.__name__:
|
|
|
|
try:
|
|
|
|
func = getattr(module, method)
|
|
|
|
except AttributeError:
|
2012-12-18 22:32:11 -06:00
|
|
|
return ("couldn't find '{0:s}' in found module "
|
|
|
|
"'{1:s}'".format(method, modname))
|
2012-03-30 09:43:30 -05:00
|
|
|
|
|
|
|
if hasattr(func, '__call__'):
|
|
|
|
return func(*args)
|
|
|
|
else:
|
2012-12-18 22:32:11 -06:00
|
|
|
return ("'{0:s}' in found module '{1:s}' is not "
|
|
|
|
"callable".format(method, modname))
|
2012-03-30 09:43:30 -05:00
|
|
|
|
2012-12-18 22:32:11 -06:00
|
|
|
return "couldn't find module '{0:s}'".format(modname)
|
2012-03-30 09:43:30 -05:00
|
|
|
|
2011-01-07 09:54:51 -06:00
|
|
|
class DrBotServerConnection(irclib.ServerConnection):
|
|
|
|
|
|
|
|
"""Subclass irclib's ServerConnection, in order to expand privmsg."""
|
|
|
|
|
2011-01-08 00:05:00 -06:00
|
|
|
nickmask = None
|
2011-01-07 23:56:51 -06:00
|
|
|
|
2012-12-19 15:12:57 -06:00
|
|
|
def __init__(self, irclibobj, nickname=None, username=None):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Instantiate the server connection.
|
|
|
|
|
|
|
|
Also start guessing at the nickmask and get ready to do on_welcome
|
|
|
|
stuff.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
irclibobj the irclib instance to connect with
|
2012-12-19 15:12:57 -06:00
|
|
|
nickname the nickname to use in nickmask guess
|
|
|
|
username the username to use in nickmask guess
|
2012-12-18 22:15:52 -06:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
2011-01-07 23:56:51 -06:00
|
|
|
irclib.ServerConnection.__init__(self, irclibobj)
|
|
|
|
|
2012-12-19 15:12:57 -06:00
|
|
|
# temporary. hopefully on_welcome() will set this, but this should be
|
|
|
|
# a pretty good guess if not
|
|
|
|
nick = nickname
|
|
|
|
user = username if username is not None else nick
|
|
|
|
host = socket.getfqdn()
|
|
|
|
self.nickmask = "{0:s}!~{1:s}@{2:s}".format(nick, user, host)
|
|
|
|
log.debug("guessing at nickmask '{0:s}'".format(self.nickmask))
|
2011-01-07 23:56:51 -06:00
|
|
|
|
|
|
|
self.add_global_handler('welcome', self.on_welcome, 1)
|
|
|
|
|
|
|
|
def on_welcome(self, connection, event):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Set the nickmask that the ircd tells us is us.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
connection source connection
|
|
|
|
event incoming event
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2011-01-07 23:56:51 -06:00
|
|
|
what = event.arguments()[0]
|
|
|
|
|
2012-12-19 00:09:28 -06:00
|
|
|
log.debug("welcome: {0:s}".format(what))
|
|
|
|
|
2011-01-07 23:56:51 -06:00
|
|
|
match = re.search('(\S+!\S+@\S+)', what)
|
|
|
|
if match:
|
2011-01-08 00:05:00 -06:00
|
|
|
self.nickmask = match.group(1)
|
2012-12-19 15:12:57 -06:00
|
|
|
log.debug("setting nickmask: {0:s}".format(self.nickmask))
|
2011-01-07 23:56:51 -06:00
|
|
|
|
2011-01-07 09:54:51 -06:00
|
|
|
def privmsg(self, target, text):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Send a PRIVMSG command.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
target the destination nick/channel
|
|
|
|
text the message to send
|
|
|
|
|
|
|
|
"""
|
2011-01-07 09:54:51 -06:00
|
|
|
|
2012-12-18 22:30:31 -06:00
|
|
|
log.debug("OUTGOING PRIVMSG: t[{0:s}] m[{1:s}]".format(target, text))
|
|
|
|
|
2011-01-07 09:54:51 -06:00
|
|
|
splitter = "..."
|
|
|
|
|
|
|
|
# split messages that are too long. Max length is 512.
|
2011-01-08 00:05:00 -06:00
|
|
|
# TODO: this does not properly handle when the nickmask has been
|
2011-01-07 09:54:51 -06:00
|
|
|
# masked by the ircd
|
2011-01-07 23:56:51 -06:00
|
|
|
# is the above still the case?
|
2011-01-08 00:05:00 -06:00
|
|
|
space = 512 - len('\r\n') - len(' PRIVMSG ') - len(target) - len(' :') - len(self.nickmask) - len(' :')
|
2011-01-07 09:54:51 -06:00
|
|
|
splitspace = space - (len(splitter) + 1)
|
|
|
|
|
|
|
|
if len(text) > space:
|
|
|
|
times = 1
|
|
|
|
|
|
|
|
while len(text) > splitspace:
|
|
|
|
splitpos = text.rfind(' ', 0, splitspace)
|
|
|
|
splittext = text[0:splitpos] + ' ' + splitter
|
|
|
|
text = splitter + ' ' + text[splitpos+1:]
|
2012-12-18 22:32:11 -06:00
|
|
|
self.send_raw("PRIVMSG {0:s} :{1:s}".format(target, splittext))
|
2011-01-07 09:54:51 -06:00
|
|
|
|
|
|
|
times = times + 1
|
|
|
|
if times >= 4:
|
2012-12-18 22:15:52 -06:00
|
|
|
# this is stupidly long, abort
|
2011-01-07 09:54:51 -06:00
|
|
|
return
|
|
|
|
|
|
|
|
# done splitting
|
2012-12-18 22:32:11 -06:00
|
|
|
self.send_raw("PRIVMSG {0:s} :{1:s}".format(target, text))
|
2011-01-07 09:54:51 -06:00
|
|
|
else:
|
2012-12-18 22:32:11 -06:00
|
|
|
self.send_raw("PRIVMSG {0:s} :{1:s}".format(target, text))
|
2011-01-07 09:54:51 -06:00
|
|
|
|
|
|
|
class DrBotIRC(irclib.IRC):
|
|
|
|
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
"""Implement a customized irclib IRC."""
|
|
|
|
|
|
|
|
modlist = []
|
|
|
|
config = None
|
|
|
|
server = None
|
|
|
|
|
|
|
|
def __init__(self, config):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Initialize XML-RPC interface and save references.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
config the config structure to load stuff from
|
|
|
|
|
|
|
|
"""
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
irclib.IRC.__init__(self)
|
|
|
|
|
|
|
|
self.config = config
|
2012-03-30 09:43:30 -05:00
|
|
|
self.xmlrpc = None
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
|
2012-12-20 09:58:25 -06:00
|
|
|
self.regex_handlers = dict()
|
|
|
|
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
# handle SIGINT
|
|
|
|
signal.signal(signal.SIGINT, self.sigint_handler)
|
2011-01-07 09:54:51 -06:00
|
|
|
|
2012-03-30 09:43:30 -05:00
|
|
|
# load XML-RPC server
|
|
|
|
try:
|
|
|
|
if self.config.has_section('XMLRPC'):
|
|
|
|
host = self.config.get('XMLRPC', 'host')
|
|
|
|
port = self.config.getint('XMLRPC', 'port')
|
|
|
|
if host and port:
|
|
|
|
self.funcs = DrBotzoMethods(self)
|
|
|
|
|
2012-07-28 09:55:54 -05:00
|
|
|
self.xmlrpc = SimpleXMLRPCServer((host, port), logRequests=False)
|
2012-03-30 09:43:30 -05:00
|
|
|
self.xmlrpc.register_introspection_functions()
|
|
|
|
self.xmlrpc.register_instance(self.funcs)
|
|
|
|
|
|
|
|
thread.start_new_thread(self._xmlrpc_listen, ())
|
|
|
|
except NoOptionError: pass
|
|
|
|
|
2011-01-07 09:54:51 -06:00
|
|
|
def server(self):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Create a DrBotServerConnection.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The newly created DrBotServerConnection.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2012-12-19 15:12:57 -06:00
|
|
|
# get the nick and user name so we can provide it to
|
|
|
|
# DrBotServerConnection as a hint for the nickmask
|
|
|
|
user = None
|
|
|
|
nick = None
|
|
|
|
try:
|
|
|
|
if self.config.has_section('dr.botzo'):
|
|
|
|
user = self.config.get('dr.botzo', 'user')
|
|
|
|
nick = self.config.get('dr.botzo', 'nick')
|
|
|
|
except NoOptionError: pass
|
|
|
|
|
|
|
|
self.server = DrBotServerConnection(self, user, nick)
|
2012-12-19 20:22:48 -06:00
|
|
|
|
|
|
|
# though we only handle one connection, the underlying library supports
|
|
|
|
# multiple. append the new one though we intend no others
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
self.connections.append(self.server)
|
|
|
|
|
|
|
|
return self.server
|
|
|
|
|
2012-12-20 09:58:25 -06:00
|
|
|
def add_global_regex_handler(self, event, regex, handler, priority=0):
|
|
|
|
"""Adds a global handler function for a specific event type and regex.
|
|
|
|
|
|
|
|
The handler function is called whenever the specified event is
|
|
|
|
triggered in any of the connections and the regex matches.
|
|
|
|
See documentation for the Event class.
|
|
|
|
|
|
|
|
The handler functions are called in priority order (lowest
|
|
|
|
number is highest priority). If a handler function returns
|
|
|
|
"NO MORE", no more handlers will be called.
|
|
|
|
|
|
|
|
This is basically an extension of add_global_handler(), either may
|
|
|
|
work, though it turns out most modules probably want this one.
|
|
|
|
|
|
|
|
The provided method should take as arguments:
|
|
|
|
* nick the nick creating the event, or None
|
|
|
|
* userhost the userhost creating the event, or None
|
2014-03-16 15:02:04 -05:00
|
|
|
* event list of the raw IRC events, which may be None
|
2012-12-20 09:58:25 -06:00
|
|
|
* from_admin whether or not the event came from an admin
|
|
|
|
* groups list of match.groups(), from re.search()
|
|
|
|
|
|
|
|
Args:
|
|
|
|
event event type (a string), as in numeric_events
|
|
|
|
regex regex string to match before doing callback invocation
|
|
|
|
handler callback function to invoke
|
|
|
|
priority integer, the lower number, the higher priority
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2014-03-16 15:02:04 -05:00
|
|
|
if type(event) != list:
|
|
|
|
event = [event]
|
|
|
|
|
|
|
|
for ev in event:
|
|
|
|
if not ev in self.regex_handlers:
|
|
|
|
self.regex_handlers[ev] = []
|
|
|
|
bisect.insort(self.regex_handlers[ev], ((priority, regex, handler)))
|
2012-12-20 09:58:25 -06:00
|
|
|
|
|
|
|
def remove_global_regex_handler(self, event, regex, handler):
|
|
|
|
"""Removes a global regex handler function.
|
|
|
|
|
|
|
|
Args:
|
2014-03-16 15:09:40 -05:00
|
|
|
event list of event type (a string), as in numeric_events
|
2012-12-20 09:58:25 -06:00
|
|
|
regex regex string that was used in matching
|
|
|
|
handler callback function to remove
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
1 on success, otherwise 0.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2014-03-16 15:09:40 -05:00
|
|
|
if type(event) != list:
|
|
|
|
event = [event]
|
|
|
|
|
|
|
|
for ev in event:
|
|
|
|
if not ev in self.regex_handlers:
|
|
|
|
continue
|
2012-12-20 09:58:25 -06:00
|
|
|
|
2014-03-16 15:09:40 -05:00
|
|
|
for h in self.regex_handlers[ev]:
|
|
|
|
if regex == h[1] and handler == h[2]:
|
|
|
|
self.regex_handlers[ev].remove(h)
|
2012-12-20 09:58:25 -06:00
|
|
|
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
def _handle_event(self, connection, event):
|
2012-12-20 09:58:25 -06:00
|
|
|
"""Override event handler to do recursion and regex checking.
|
2012-12-18 22:15:52 -06:00
|
|
|
|
|
|
|
Args:
|
|
|
|
connection source connection
|
|
|
|
event incoming event
|
|
|
|
|
|
|
|
"""
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
|
2012-12-18 22:30:31 -06:00
|
|
|
log.debug("EVENT: e[{0:s}] s[{1:s}] t[{2:s}] "
|
|
|
|
"a[{3:s}]".format(event.eventtype(), event.source(),
|
|
|
|
event.target(), event.arguments()))
|
|
|
|
|
2012-03-01 22:00:42 -06:00
|
|
|
try:
|
|
|
|
nick = irclib.nm_to_n(event.source())
|
|
|
|
except (IndexError, AttributeError):
|
|
|
|
nick = ''
|
|
|
|
|
|
|
|
try:
|
|
|
|
if self.config.has_section('Ignore'):
|
2012-03-07 22:48:30 -06:00
|
|
|
alias = self.config.get('Ignore', nick.lower())
|
2012-03-01 22:00:42 -06:00
|
|
|
if alias:
|
2012-12-18 22:30:31 -06:00
|
|
|
log.debug("ignoring {0:s} as per config file".format(nick))
|
2012-03-01 22:00:42 -06:00
|
|
|
return
|
|
|
|
except NoOptionError: pass
|
|
|
|
|
2011-04-27 22:11:37 -05:00
|
|
|
self.try_alias_cmds(connection, event)
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
self.try_recursion(connection, event)
|
|
|
|
self.try_alias(connection, event)
|
|
|
|
|
2012-12-20 09:58:25 -06:00
|
|
|
nick = None
|
|
|
|
userhost = None
|
|
|
|
admin = False
|
|
|
|
|
|
|
|
if event.source() is not None:
|
|
|
|
nick = irclib.nm_to_n(event.source())
|
|
|
|
try:
|
|
|
|
userhost = irclib.nm_to_uh(event.source())
|
|
|
|
except IndexError: pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
if userhost == self.config.get('dr.botzo', 'admin_userhost'):
|
|
|
|
admin = True
|
|
|
|
except NoOptionError: pass
|
|
|
|
|
|
|
|
# try regex handlers first, since they're more specific
|
|
|
|
rh = self.regex_handlers
|
|
|
|
trh = sorted(rh.get('all_events', []) + rh.get(event.eventtype(), []))
|
|
|
|
for handler in trh:
|
|
|
|
try:
|
|
|
|
prio, regex, method = handler
|
|
|
|
for line in event.arguments():
|
|
|
|
match = re.search(regex, line)
|
|
|
|
if match:
|
|
|
|
log.debug("pattern matched, calling "
|
|
|
|
"{0:s}".format(method))
|
|
|
|
# pattern matched, call method with pattern groups
|
|
|
|
ret = method(nick, userhost, event, admin,
|
|
|
|
match.groups())
|
|
|
|
if ret == 'NO MORE':
|
|
|
|
return
|
|
|
|
except Exception as e:
|
|
|
|
log.error("exception floated up to DrBotIrc!")
|
|
|
|
log.exception(e)
|
|
|
|
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
h = self.handlers
|
2012-12-20 09:50:20 -06:00
|
|
|
th = sorted(h.get('all_events', []) + h.get(event.eventtype(), []))
|
|
|
|
for handler in th:
|
2011-10-18 00:48:11 -05:00
|
|
|
try:
|
2012-12-20 09:50:20 -06:00
|
|
|
prio, method = handler
|
|
|
|
ret = method(connection, event)
|
|
|
|
if ret == 'NO MORE':
|
2011-10-18 00:48:11 -05:00
|
|
|
return
|
|
|
|
except Exception as e:
|
2012-12-18 22:30:31 -06:00
|
|
|
log.error("exception floated up to DrBotIrc!")
|
|
|
|
log.exception(e)
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
|
2012-03-30 10:17:13 -05:00
|
|
|
def xmlrpc_register_function(self, func, name):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Add a method to the XML-RPC interface.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
func the method to register
|
|
|
|
name the name to expose the method as
|
|
|
|
|
|
|
|
"""
|
2012-03-30 10:17:13 -05:00
|
|
|
|
2012-03-30 17:25:46 -05:00
|
|
|
if func and self.xmlrpc:
|
2012-03-30 10:17:13 -05:00
|
|
|
if hasattr(func, '__call__'):
|
|
|
|
self.xmlrpc.register_function(func, name)
|
|
|
|
|
2012-03-30 09:43:30 -05:00
|
|
|
def _xmlrpc_listen(self):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Begin listening.
|
|
|
|
|
|
|
|
Hopefully this was called in a new thread.
|
|
|
|
|
|
|
|
"""
|
2012-03-30 09:43:30 -05:00
|
|
|
|
|
|
|
self.xmlrpc.serve_forever()
|
|
|
|
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
def try_to_replace_event_text_with_module_text(self, connection, event):
|
|
|
|
"""Do something very similar to _handle_event, but for recursion.
|
|
|
|
|
|
|
|
The intent here is that we replace [text] with whatever a module
|
|
|
|
provides to us.
|
2012-12-18 22:15:52 -06:00
|
|
|
|
|
|
|
Args:
|
|
|
|
connection source connection
|
|
|
|
event incoming event
|
|
|
|
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
"""
|
|
|
|
|
2011-02-17 12:01:32 -06:00
|
|
|
replies = []
|
|
|
|
|
2012-12-20 09:58:25 -06:00
|
|
|
nick = None
|
|
|
|
userhost = None
|
|
|
|
admin = False
|
|
|
|
|
|
|
|
if event.source() is not None:
|
|
|
|
nick = irclib.nm_to_n(event.source())
|
|
|
|
try:
|
|
|
|
userhost = irclib.nm_to_uh(event.source())
|
|
|
|
except IndexError: pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
if userhost == self.config.get('dr.botzo', 'admin_userhost'):
|
|
|
|
admin = True
|
|
|
|
except NoOptionError: pass
|
|
|
|
|
|
|
|
# try regex handlers first, since they're more specific
|
|
|
|
rh = self.regex_handlers
|
|
|
|
trh = sorted(rh.get('all_events', []) + rh.get(event.eventtype(), []))
|
|
|
|
for handler in trh:
|
|
|
|
try:
|
|
|
|
prio, regex, method = handler
|
|
|
|
for line in event.arguments():
|
|
|
|
match = re.search(regex, line)
|
|
|
|
if match:
|
|
|
|
log.debug("pattern matched, calling "
|
|
|
|
"{0:s}".format(method))
|
|
|
|
# pattern matched, call method with pattern groups
|
|
|
|
ret = method(nick, userhost, event, admin,
|
|
|
|
match.groups())
|
|
|
|
if ret:
|
|
|
|
replies.append(ret)
|
|
|
|
except Exception as e:
|
|
|
|
log.error("exception floated up to DrBotIrc!")
|
|
|
|
log.exception(e)
|
|
|
|
|
2012-12-20 09:50:20 -06:00
|
|
|
h = self.handlers
|
|
|
|
th = sorted(h.get('all_events', []) + h.get(event.eventtype(), []))
|
|
|
|
for handler in th:
|
|
|
|
try:
|
|
|
|
prio, method = handler
|
|
|
|
ret = method(connection, event)
|
|
|
|
if ret:
|
|
|
|
replies.append(ret)
|
|
|
|
except Exception as e:
|
|
|
|
log.error("exception floated up to DrBotIrc!")
|
|
|
|
log.exception(e)
|
|
|
|
|
2011-02-17 12:01:32 -06:00
|
|
|
if len(replies):
|
|
|
|
event.arguments()[0] = '\n'.join(replies)
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
|
2011-04-27 22:11:37 -05:00
|
|
|
def try_alias_cmds(self, connection, event):
|
|
|
|
"""See if there is an alias ("!command") in the text, and if so
|
|
|
|
do alias manipulation before any other recursion or aliasing.
|
2012-12-18 22:15:52 -06:00
|
|
|
|
|
|
|
Args:
|
|
|
|
connection source connection
|
|
|
|
event incoming event
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The outcome of the alias command, if the text had one.
|
|
|
|
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
"""
|
|
|
|
|
2011-04-27 22:11:37 -05:00
|
|
|
try:
|
|
|
|
nick = irclib.nm_to_n(event.source())
|
|
|
|
except (IndexError, AttributeError):
|
|
|
|
nick = ''
|
|
|
|
try:
|
|
|
|
userhost = irclib.nm_to_uh(event.source())
|
|
|
|
except (IndexError, AttributeError):
|
|
|
|
userhost = ''
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
replypath = event.target()
|
2011-04-27 22:11:37 -05:00
|
|
|
try:
|
|
|
|
what = event.arguments()[0]
|
|
|
|
except (IndexError, AttributeError):
|
|
|
|
what = ''
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
admin_unlocked = False
|
|
|
|
|
2011-01-07 21:14:14 -06:00
|
|
|
# privmsg
|
|
|
|
if replypath == connection.get_nickname():
|
|
|
|
replypath = nick
|
|
|
|
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
try:
|
|
|
|
if userhost == self.config.get('dr.botzo', 'admin_userhost'):
|
|
|
|
admin_unlocked = True
|
|
|
|
except NoOptionError: pass
|
|
|
|
|
|
|
|
# first see if the aliases are being directly manipulated via add/remove
|
|
|
|
whats = what.split(' ')
|
2011-06-14 22:40:45 -05:00
|
|
|
|
|
|
|
if len(whats) <= 1:
|
|
|
|
return
|
|
|
|
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
try:
|
|
|
|
if whats[0] == '!alias' and whats[1] == 'add' and len(whats) >= 4:
|
|
|
|
if not self.config.has_section('Alias'):
|
|
|
|
self.config.add_section('Alias')
|
|
|
|
|
|
|
|
self.config.set('Alias', whats[2], ' '.join(whats[3:]))
|
2012-12-18 22:32:11 -06:00
|
|
|
replystr = "Added alias '{0:s}'.".format(whats[2])
|
2012-12-19 20:32:18 -06:00
|
|
|
return self.reply(event, replystr)
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
if whats[0] == '!alias' and whats[1] == 'remove' and len(whats) >= 3:
|
|
|
|
if not self.config.has_section('Alias'):
|
|
|
|
self.config.add_section('Alias')
|
|
|
|
|
|
|
|
if self.config.remove_option('Alias', whats[2]):
|
2012-12-18 22:32:11 -06:00
|
|
|
replystr = "Removed alias '{0:s}'.".format(whats[2])
|
2012-12-19 20:32:18 -06:00
|
|
|
return self.reply(event, replystr)
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
elif whats[0] == '!alias' and whats[1] == 'list':
|
|
|
|
try:
|
|
|
|
if len(whats) > 2:
|
|
|
|
alias = self.config.get('Alias', whats[2])
|
2012-12-19 20:32:18 -06:00
|
|
|
return self.reply(event, alias)
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
else:
|
|
|
|
alist = self.config.options('Alias')
|
2011-01-07 20:36:42 -06:00
|
|
|
alist.remove('debug')
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
alist.sort()
|
|
|
|
liststr = ', '.join(alist)
|
2012-12-19 20:32:18 -06:00
|
|
|
return self.reply(event, liststr)
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
except NoSectionError: pass
|
|
|
|
except NoOptionError: pass
|
|
|
|
except NoSectionError: pass
|
|
|
|
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
def try_alias(self, connection, event):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Try turning aliases into commands.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
connection source connection
|
|
|
|
event incoming event
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The de-aliased event object.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
try:
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
what = event.arguments()[0]
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
alias_list = self.config.options('Alias')
|
|
|
|
|
|
|
|
for alias in alias_list:
|
2011-02-17 09:38:41 -06:00
|
|
|
alias_re = re.compile(alias, re.IGNORECASE)
|
2011-06-20 20:05:03 -05:00
|
|
|
if alias_re.search(what) and alias != 'debug':
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
# we found an alias for our given string, doing a replace
|
2011-02-17 09:38:41 -06:00
|
|
|
command = re.sub(alias, self.config.get('Alias', alias), what, flags=re.IGNORECASE)
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
event.arguments()[0] = command
|
|
|
|
|
|
|
|
# now we have to check it for recursions again
|
|
|
|
self.try_recursion(connection, event)
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
|
2011-01-07 22:31:30 -06:00
|
|
|
# i guess someone could have an alias of an alias... try again
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
return self.try_alias(connection, event)
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
except NoOptionError: pass
|
|
|
|
except NoSectionError: pass
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
except IndexError: pass
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
|
|
|
|
# if we got here, there are no matching aliases, so return what we got
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
return event
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
def try_recursion(self, connection, event):
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
"""Scan message for subcommands to execute and use as part of this command.
|
|
|
|
|
|
|
|
Upon seeing a line intended for this module, see if there are subcommands
|
|
|
|
that we should do what is basically a text replacement on. The intent is to
|
|
|
|
allow things like the following:
|
|
|
|
|
|
|
|
command arg1 [anothercommand arg1 arg2]
|
|
|
|
|
|
|
|
where the output of anothercommand is command's arg2..n.
|
2012-12-18 22:15:52 -06:00
|
|
|
|
|
|
|
Args:
|
|
|
|
connection source connection
|
|
|
|
event incoming event
|
|
|
|
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
"""
|
|
|
|
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
try:
|
|
|
|
# begin recursion search
|
|
|
|
attempt = event.arguments()[0]
|
|
|
|
|
|
|
|
start_idx = attempt.find('[')
|
|
|
|
subcmd = attempt[start_idx+1:]
|
|
|
|
end_idx = subcmd.rfind(']')
|
|
|
|
subcmd = subcmd[:end_idx]
|
|
|
|
|
|
|
|
if start_idx != -1 and end_idx != -1 and len(subcmd) > 0:
|
|
|
|
# found recursion candidate
|
|
|
|
# copy the event and see if IT has recursion to do
|
|
|
|
newevent = copy.deepcopy(event)
|
|
|
|
newevent.arguments()[0] = subcmd
|
2012-03-29 20:07:32 -05:00
|
|
|
newevent._recursing = True
|
|
|
|
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
self.try_recursion(connection, newevent)
|
|
|
|
|
|
|
|
# recursion over, check for aliases
|
|
|
|
self.try_alias(connection, newevent)
|
|
|
|
|
|
|
|
# now that we have a string that has been de-aliased and
|
|
|
|
# recursed all the way deeper into its text, see if any
|
|
|
|
# modules can do something with it. this calls the same
|
|
|
|
# event handlers in the same way as if this were a native
|
|
|
|
# event.
|
|
|
|
self.try_to_replace_event_text_with_module_text(connection, newevent)
|
|
|
|
|
|
|
|
# we have done all we can do with the sub-event. whatever
|
|
|
|
# the text of that event now is, we should replace the parent
|
|
|
|
# event's [] section with it.
|
|
|
|
oldtext = event.arguments()[0]
|
|
|
|
newtext = oldtext.replace('['+subcmd+']', newevent.arguments()[0])
|
|
|
|
event.arguments()[0] = newtext
|
|
|
|
|
|
|
|
# we have now resolved the []. recursion will unfold, replacing
|
|
|
|
# it further and further, until we eventually get back to the
|
|
|
|
# original irc event in _handle_event, which will do one
|
|
|
|
# last search on the text.
|
|
|
|
except IndexError: pass
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
|
|
|
|
def quit_irc(self, connection, msg):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Quit IRC, disconnect, shut everything down.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
connection the connection to quit
|
|
|
|
msg the message to send while quitting
|
|
|
|
"""
|
|
|
|
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
for module in self.modlist:
|
2011-01-08 00:44:37 -06:00
|
|
|
module.save()
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
module.shutdown()
|
|
|
|
|
|
|
|
connection.quit(msg)
|
2012-12-18 22:30:31 -06:00
|
|
|
log.info(self.save_config())
|
2012-03-30 09:43:30 -05:00
|
|
|
self._xmlrpc_shutdown()
|
2012-12-18 22:30:31 -06:00
|
|
|
log.info("Bot shutting down.")
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
sys.exit()
|
|
|
|
|
2012-12-19 20:32:18 -06:00
|
|
|
def reply(self, event, replystr, stop=False):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Reply over IRC to replypath or return a string with the reply.
|
|
|
|
|
2012-12-19 20:51:35 -06:00
|
|
|
The primary utility for this is to properly handle recursion. The
|
|
|
|
recursion code in DrBotIRC will set up a couple hints that this method
|
|
|
|
picks up on and will appropriately send an IRC event or return a
|
|
|
|
string.
|
|
|
|
|
|
|
|
Unless you know what you are doing, the modules you write should use
|
|
|
|
this method rather than send a privmsg reply, as failing to call this
|
|
|
|
method will certainly have recursion do odd things with your module.
|
|
|
|
|
2012-12-18 22:15:52 -06:00
|
|
|
Args:
|
|
|
|
event incoming event
|
|
|
|
replystr the message to reply with
|
|
|
|
stop whether or not to let other handlers see this
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The replystr if the event is inside recursion, or, potentially,
|
|
|
|
"NO MORE" to stop other event handlers from acting.
|
|
|
|
|
|
|
|
"""
|
2012-07-10 17:18:35 -05:00
|
|
|
|
|
|
|
replypath = event.target()
|
|
|
|
|
2012-12-19 20:32:18 -06:00
|
|
|
# if this is a privmsg, reply to the sender
|
|
|
|
if replypath == self.server.get_nickname():
|
2012-07-10 17:18:35 -05:00
|
|
|
replypath = irclib.nm_to_n(event.source())
|
|
|
|
|
|
|
|
if replystr is not None:
|
|
|
|
if event._recursing:
|
|
|
|
return replystr
|
|
|
|
else:
|
|
|
|
replies = replystr.split('\n')
|
|
|
|
for reply in replies:
|
2012-12-19 20:32:18 -06:00
|
|
|
self.server.privmsg(replypath, reply)
|
2012-12-18 22:15:52 -06:00
|
|
|
if stop:
|
2012-07-10 17:18:35 -05:00
|
|
|
return "NO MORE"
|
|
|
|
|
2011-01-08 00:49:10 -06:00
|
|
|
def save_modules(self):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Call each module's save(), in case they have something to do."""
|
|
|
|
|
2011-01-08 00:49:10 -06:00
|
|
|
for module in self.modlist:
|
|
|
|
module.save()
|
|
|
|
|
2012-03-30 09:43:30 -05:00
|
|
|
def _xmlrpc_shutdown(self):
|
|
|
|
"""Shut down the XML-RPC server."""
|
|
|
|
|
|
|
|
if self.xmlrpc is not None:
|
|
|
|
self.xmlrpc.shutdown()
|
|
|
|
self.xmlrpc.server_close()
|
|
|
|
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
def save_config(self):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Write the config file to disk.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Short string indicating success.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
with open('dr.botzo.cfg', 'w') as cfg:
|
|
|
|
self.config.write(cfg)
|
|
|
|
|
2012-12-18 22:32:11 -06:00
|
|
|
return "Saved config."
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
|
|
|
|
def load_module(self, modname):
|
|
|
|
"""Load a module (in both the python and dr.botzo sense) if not
|
|
|
|
already loaded.
|
2012-12-18 22:15:52 -06:00
|
|
|
|
|
|
|
Args:
|
|
|
|
modname the module to attempt to load
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
String describing the outcome of the load attempt.
|
|
|
|
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
"""
|
|
|
|
|
|
|
|
for module in self.modlist:
|
|
|
|
if modname == module.__class__.__name__:
|
2012-12-18 22:32:11 -06:00
|
|
|
return "Module '{0:s}' is already loaded.".format(modname)
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
|
|
|
|
# not loaded, let's get to work
|
|
|
|
try:
|
|
|
|
modstr = 'modules.'+modname
|
|
|
|
__import__(modstr)
|
|
|
|
module = sys.modules[modstr]
|
2012-12-19 21:06:53 -06:00
|
|
|
botmod = eval('module.' + modname + '(self, self.config)')
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
self.modlist.append(botmod)
|
rewrite recursion/alias code for the 500th time.
more of a moving of the code, actually, it now exists in (an overridden)
_handle_event, so that recursions happen against irc events directly,
rather than an already partially interpreted object.
with this change, modules don't need to implement do() nor do we have a
need for the internal_bus, which was doing an additional walk of the
modules after the irc event was already handled and turned into text. now
the core event handler does the recursion scans.
to support this, we bring back the old replypath trick and use it again,
so we know when to send a privmsg reply and when to return text so that
it may be chained in recursion. this feels old hat by now, but if you
haven't been following along, you should really look at the diff.
that's the meat of the change. the rest is updating modules to use
self.reply() and reimplementing (un)register_handlers where appropriate
2011-02-17 01:08:45 -06:00
|
|
|
botmod.register_handlers()
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
|
|
|
|
# might as well add it to the list
|
|
|
|
modset = set(self.config.get('dr.botzo', 'module_list').split(','))
|
|
|
|
modset.add(modname)
|
|
|
|
self.config.set('dr.botzo', 'module_list', ','.join(modset))
|
|
|
|
|
2012-12-18 22:32:11 -06:00
|
|
|
return "Module '{0:s}' loaded.".format(modname)
|
2012-07-26 20:25:55 -05:00
|
|
|
except ImportError as e:
|
2012-12-18 22:30:31 -06:00
|
|
|
log.error("Error loading '{0:s}'".format(modname))
|
|
|
|
log.exception(e)
|
2012-12-18 22:32:11 -06:00
|
|
|
return "Module '{0:s}' could not be loaded.".format(modname)
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
|
|
|
|
def unload_module(self, modname):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Attempt to unload and del a module if it's loaded.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
modname the module to attempt to unload
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
String describing the outcome of the unload attempt.
|
|
|
|
|
|
|
|
"""
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
|
|
|
|
modstr = 'modules.'+modname
|
|
|
|
for module in self.modlist:
|
|
|
|
if modname == module.__class__.__name__:
|
|
|
|
# do anything the module needs to do to clean up
|
2011-01-08 00:44:37 -06:00
|
|
|
module.save()
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
module.shutdown()
|
|
|
|
|
|
|
|
# remove module references
|
|
|
|
self.modlist.remove(module)
|
|
|
|
module.unregister_handlers()
|
|
|
|
|
|
|
|
# del it
|
|
|
|
del(sys.modules[modstr])
|
|
|
|
del(module)
|
|
|
|
|
|
|
|
# might as well remove it from the list
|
|
|
|
modset = set(self.config.get('dr.botzo', 'module_list').split(','))
|
|
|
|
modset.remove(modname)
|
|
|
|
self.config.set('dr.botzo', 'module_list', ','.join(modset))
|
|
|
|
|
2012-12-18 22:32:11 -06:00
|
|
|
return "Module '{0:s}' unloaded.".format(modname)
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
|
|
|
|
# guess it was never loaded
|
2012-12-18 22:32:11 -06:00
|
|
|
return "Module '{0:s}' is not loaded.".format(modname)
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
|
2011-01-08 01:22:31 -06:00
|
|
|
def list_modules(self):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""List loaded modules.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A list of the loaded modules' names.
|
|
|
|
|
|
|
|
"""
|
2011-01-08 01:22:31 -06:00
|
|
|
|
|
|
|
modnames = []
|
|
|
|
for module in self.modlist:
|
|
|
|
modnames.append(module.__class__.__name__)
|
|
|
|
|
|
|
|
return modnames
|
|
|
|
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
def sigint_handler(self, signal, frame):
|
2012-12-18 22:15:52 -06:00
|
|
|
"""Cleanly shutdown on SIGINT."""
|
|
|
|
|
2011-01-08 00:44:37 -06:00
|
|
|
for module in self.modlist:
|
|
|
|
module.save()
|
|
|
|
module.shutdown()
|
|
|
|
|
2012-12-18 22:30:31 -06:00
|
|
|
log.info(self.save_config())
|
2012-03-30 09:43:30 -05:00
|
|
|
self._xmlrpc_shutdown()
|
migrate some code that became pivotal to the bot into DrBotIRC.
this is a big change. DrBotIrc is now in charge of module loading
and unloading, aliases, and recursion. the Alias module is no more,
and a bunch of functionality was moved out of IrcAdmin, including
also config file saving, the sigint handler, and quitting the bot.
additionally, a lot of stuff got caught in the wake. dr.botzo.py
is simpler now, and lets DrBotIRC do the dynamic loading stuff.
Module.__init__ changed, modules no longer get modlist and instead
get a reference to the DrBotIRC object. IrcAdmin still has the same
exposed methods, but now calls out to DrBotIRC to achieve some of
them.
naturally, a recursion/alias rewrite was included with this change.
it is clearer now (i think), but probably brittle somewhere.
additionally, currently any module that has registered a pubmsg
handler can potentially fire more than once on one input (without
recursion). this may be the next thing to fix. do() may need to
be split, or maybe it's time to stop having modules deal with
pubmsg/privmsg entirely. need to decide.
WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
2011-01-07 17:38:26 -06:00
|
|
|
sys.exit()
|
2011-01-07 09:54:51 -06:00
|
|
|
|
|
|
|
# vi:tabstop=4:expandtab:autoindent
|
|
|
|
# kate: indent-mode python;indent-width 4;replace-tabs on;
|