MongoDB-based rewrite and code cleanup

The hope is that this will make it easier to extend the bot, as the
database is now really extensible.