Commit Graph

82 Commits

Author SHA1 Message Date
Brian S. Stephan ef47fd3914 Module: reload the logging config file every __init__()
this is to allow for changing a module's logging level by changing
the config and then unload,load it
2012-07-28 09:47:30 -05:00
Brian S. Stephan 1a36becead convert to a MySQL backend
WARNING!
there's no going back now. this change is *huge* but it was overdue.
WARNING!

the database backend is now mysql. modules that should use a database
but don't yet were left untouched, they'll come later. scripts haven't
been converted yet, though i'm pretty sure i'll need to soon.

while i was going through everything, connection/cursor idioms were
cleaned up, as were a bunch of log messages and exception handling. this
change is so gross i'm happy things appear to be working, which is
the case --- all modules are lightly tested.
2012-07-27 02:18:01 -05:00
Brian S. Stephan cac3c0216a Module: log as 'drbotzo.classname' rather than 'drbotzo' 2012-07-26 20:28:17 -05:00
Brian S. Stephan ad80d86a73 Module: logging module (un)loading at info rather than debug 2012-07-26 20:09:57 -05:00
Brian S. Stephan e6be873f3d rename logger to drbotzo for clarity's sake 2012-07-26 20:09:22 -05:00
Brian S. Stephan f017422e69 dr.botzo, Module: misc cleaning up of old crap 2012-07-26 19:38:18 -05:00
Brian S. Stephan 61ceef6a88 Module: logging cleanup, add logging on unload 2012-07-15 21:48:49 -05:00
Brian S. Stephan 9654f4de98 switch to use python's logging, with config file i'm not entirely happy about 2012-07-15 21:32:12 -05:00
Brian S. Stephan 25d0f2f5c3 connect to sqlite with isolation_level=None as an attempt to avoid (invalid) database is locked errors 2012-03-29 20:09:50 -05:00
Brian S. Stephan 07744a0f66 indicate recursion better by adding _recursing to Event
for simplicity's sake, this was added to the extlib/irclib rather
than subclassing. because i'm lazy. anyway, check that flag instead
of doing the event._target = None hack, since that hack was breaking
Markov.

for an unrelated reason (what to learn and not learn), update Markov

also remove an unused method that was getting in my way while coding this
2012-03-29 20:07:32 -05:00
Brian S. Stephan 5c2c3882f3 Module: remove connection timeout setting from db connect 2012-03-07 22:47:10 -06:00
Brian S. Stephan 78f7614987 Module: it's come to this. bump the default sqlite connection timeout to 60 sec 2011-10-18 00:48:46 -05:00
Brian S. Stephan 9ecd66f94a Module: upsert drbotzo_modules 2011-07-06 21:51:30 -05:00
Brian S. Stephan 4566d1734e change the default sqlite timeout to 30 seconds
this should make the bot wait longer for table locks, assuming i
read the docs right
2011-07-01 18:42:49 -05:00
Brian S. Stephan ad4d75f724 Module: move REGEXP definition to every get_db() call
also remove some self.conn stuff that no one used anymore
2011-06-21 17:22:24 -05:00
Brian S. Stephan 097077174b close connections from get_db() 2011-06-20 22:20:41 -05:00
Brian S. Stephan c08e7cabc0 Module.py: make get_db() threadsafe by having it create a new connection every time 2011-06-20 22:08:49 -05:00
Brian S. Stephan 152ef2a1ad Module: remove the timer stuff, since individual modules can do this better themselves
Markov, Twitter: switch to forking a thread ourselves, and check every
second whether or not to quit. this is the "better" part above, as
now we can instantly quit the thread rather than waiting for all
the timers to fire and expire
2011-06-20 21:18:55 -05:00
Brian S. Stephan a61fb37394 Module: add convenience method to set the version for a module in the database 2011-05-01 09:36:37 -05:00
Brian S. Stephan aa6ea083fd remove reload support, since it was broken in the first place (somehow) 2011-04-27 22:49:04 -05:00
Brian S. Stephan 80f2ff469c Module: properly end timer threads by tracking when module's shutdown() was called 2011-04-23 12:07:30 -05:00
Brian S. Stephan 0c5fe348dc Module: add timer support to modules
modules that want to create a timer should implement timer_interval()
to return a non-zero value (the timer interval, in seconds) and
timer_do() (the method that does stuff)
2011-04-23 11:50:02 -05:00
Brian S. Stephan 3e63c2e458 since sending arbitrary text and replying now have very different goals, add Module.sendmsg
this just sends a privmsg to the specified target on the specified
connection. pretty straightforward. also, update the modules that
need it to use it.
2011-02-17 12:31:51 -06:00
Brian S. Stephan 752515a628 put check for pubmsg vs. privmsg in Module.reply() rather than a method where it achieved nothing 2011-02-17 12:07:41 -06:00
Brian S. Stephan 2aa369add7 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
Brian S. Stephan 64df118c65 move Twitter._unescape to Module._unencode_xml 2011-01-26 20:28:34 -06:00
Mike Bloy fdd059ddbc change default module description
Modules by default were returning None from help_description(), which
meant that they would not display in !help

Instead, return a generic not-available message. If a module really
doesn't want to display in !help, override and return None
2011-01-08 22:32:55 -06:00
Mike Bloy d34a134993 add help functions to Module.py 2011-01-08 22:02:02 -06:00
Brian S. Stephan f2668c3851 mention how Module.save() and Module.shutdown() are related 2011-01-08 00:45:42 -06:00
Brian S. Stephan 359ca24856 remove replypath and all the places it was used.
with alias calling do() internally, there is no need for all this
replypath nonsense, and if there's ever a module that needs to reply
to stuff on its own outside of do(), it'd have to be implementing
all of this anyway, so it was pretty irrelevant.

this makes DrBotIRC alias/recursion stuff a bit cleaner.
2011-01-07 23:09:07 -06:00
Brian S. Stephan fc2814e57c don't attach to pubmsg/privmsg events by default anymore.
this is possible because now the alias stuff in DrBotIRC calls
each module's do() on a pubmsg/privmsg.

this also gets rid of all the meta options (so remove them from
your config file!), and IrcAdmin now only needs to connect
to welcome.
2011-01-07 21:04:33 -06:00
Brian S. Stephan 01d3c7c80c 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
Brian S. Stephan 35419f9db9 to stop responding by default is too much power for one module to wield 2011-01-07 09:19:19 -06:00
Brian S. Stephan de3f9d9ae7 provide a priority (default 50) to add_global_handler 2011-01-07 01:10:52 -06:00
Brian S. Stephan 8bec2e62a1 make it possible for a module to respond and tell irclib to stop calling other handlers.
this works via Module.reply(). if it produces IRC output, it returns
"NO MORE", which is returned by do(), which is returned by the handler,
which instructs irclib to cease calling handlers. now all we need
is some priorities for the modules (also supported by irclib) and
we may be in business
2011-01-07 00:44:31 -06:00
Brian S. Stephan c1c9908d5d don't include metaopt meta.internal_only in lists (such as aliases) 2011-01-06 22:17:46 -06:00
Brian S. Stephan ea0fd9d509 small but significant unload/reload changes.
IrcAdmin:
* have sub_unload_module() call the module's shutdown() before deleting stuff
* sub_unload_module() needs to delete the sys.modules entry too
* slightly more verbose output in sub_unload_module()
* sub_reload_module() now does a self.sub_unload_module() + self.sub_load_module()

Module:
* remove reload() --- modules must now safely handle shutdown
2011-01-06 19:54:16 -06:00
Brian S. Stephan 0878c8809d implement a save() for modules, use it in MegaHAL to sync brain to disk 2011-01-06 00:28:50 -06:00
Brian S. Stephan 377d2145fa catch all exceptions around self.do, and log to console
as much as i find this uncouth, it is handy, and also it seems
that the megahal brain gets corrupted/unusable when an exception
isn't caught and the bot dies. this should cover most of the
cases
2010-12-24 13:16:09 -06:00
Brian S. Stephan f590daf5cd have all modules run a shutdown() when quitting, use it to have MegaHAL close the brain 2010-12-24 10:41:12 -06:00
Brian S. Stephan 1fe9575502 move recursion stuff out of Module.py and into modules/Alias.py
this comes with a recursion rewrite and simplification; it works
a bit more intuitively, now, but i still haven't figured out what
caused the bug that led me down this rabbit hole.

in any event, Alias now rules the roost when it comes to recursion,
which means it's a bit poorly named, but also means that there
won't (shouldn't) be multiple accidental runs for one output, caused
by multiple modules doing the recursion (despite only one really
having a legitimate reason to) --- a classic case of the intended
use of recursion (including the comment to only recurse when you
*know* the input is for you) being lost and forgotten with time

this also obsoletes meta.skip_recursion_scan. between this commit
and the last, people would be wise to revise their config files
2010-12-16 23:43:16 -06:00
Brian S. Stephan d18b2e49ff add 'meta.internal_only' option, defaulting to true
this allows for better control on recursion/alias type things, which
is an awful lot of what the bot does these days
2010-12-16 21:06:20 -06:00
Brian S. Stephan 0db4dbb518 duh, actually call register_handlers after doing a module reload 2010-12-15 20:55:04 -06:00
Brian S. Stephan 7a9b68f2c4 remove unnecessary method, preferring register_handlers 2010-12-15 20:53:52 -06:00
Brian S. Stephan 22615d7b9a rewrite reload support, making it an IrcAdmin command
only lightly tested for the moment
2010-12-15 20:43:14 -06:00
Brian S. Stephan 914e86d567 don't try to privmsg (and then crash) if replystr is None 2010-12-08 22:18:46 -06:00
Brian S. Stephan 57b6ffa0b7 re.IGNORECASE in the regexp function compiled for sqlite 2010-11-01 22:12:14 -05:00
Brian S. Stephan b7f2b9bd0e use re.search() rather than re.match() in a couple places
(search() looks for the regex anywhere in the string whereas
match() only looks for the regex starting from the beginning)
2010-10-29 00:30:02 -05:00
Brian S. Stephan 487e997a55 define a regexp function in sqlite 2010-10-28 23:52:06 -05:00
Brian S. Stephan 1d73deda1c sqlite related stuff as part of making sqlite the canonical backend
* Module.py __init__ sets up sqlite db connection by default
* Module.py __init__ calls init_db() which is empty, expects subclasses to implement as necessary
* Module.py doesn't close sqlite connection by default

Changes call for a couple updates in Karma.py, namely implementing db_init
and excepting sqlite3.Error rather than closing the connection
2010-10-27 17:59:01 -05:00