Brian S. Stephan
01d3c7c80c
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
108 lines
3.3 KiB
Python
108 lines
3.3 KiB
Python
"""
|
|
dr.botzo - a pluggable IRC bot written in Python
|
|
Copyright (C) 2010 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/>.
|
|
"""
|
|
|
|
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
|
|
import os
|
|
import re
|
|
import sys
|
|
import inspect
|
|
import sqlite3
|
|
|
|
import DrBotIRC
|
|
from extlib import irclib
|
|
|
|
moduleList = [ "Countdown", "Dice", "IrcAdmin", "GoogleTranslate", "Seen", "FactFile" ]
|
|
modObjs = []
|
|
|
|
config_file = 'dr.botzo.cfg'
|
|
# check argv
|
|
if len(sys.argv) == 2:
|
|
config_file = sys.argv[1]
|
|
|
|
# read config file
|
|
|
|
config = ConfigParser({'debug': 'false'})
|
|
config.read(os.path.expanduser(config_file))
|
|
|
|
# load necessary options
|
|
try:
|
|
# load connection info
|
|
botserver = config.get('dr.botzo', 'server')
|
|
botport = config.getint('dr.botzo', 'port')
|
|
botnick = config.get('dr.botzo', 'nick')
|
|
botpass = config.get('dr.botzo', 'pass')
|
|
botuser = config.get('dr.botzo', 'user')
|
|
botircname = config.get('dr.botzo', 'name')
|
|
except NoSectionError as e:
|
|
sys.exit("Aborted due to error with necessary configuration: " + str(e))
|
|
except NoOptionError as e:
|
|
sys.exit("Aborted due to error with necessary configuration: " + str(e))
|
|
|
|
# load additional options
|
|
irclib.DEBUG = config.getboolean('dr.botzo', 'debug')
|
|
|
|
try:
|
|
# make sure we can initialize the database, if such a thing is
|
|
# called for in the config file
|
|
dbfile = config.get('dr.botzo', 'database')
|
|
conn = sqlite3.connect(dbfile)
|
|
try:
|
|
query = """
|
|
SELECT COUNT(*)
|
|
FROM sqlite_master
|
|
WHERE type = 'table' AND name = 'drbotzo_modules'
|
|
"""
|
|
row = conn.execute(query).fetchone()
|
|
if row[0] == 0:
|
|
# need to create the drbotzo_modules table
|
|
query = """
|
|
CREATE TABLE drbotzo_modules (
|
|
module TEXT,
|
|
version INTEGER
|
|
)
|
|
"""
|
|
conn.execute(query)
|
|
conn.commit()
|
|
finally: conn.close()
|
|
except NoOptionError: pass # if the config file has no db property, assume that
|
|
except NoSectionError: pass # the database doesn't need to exist
|
|
|
|
# start up the IRC bot
|
|
|
|
# create IRC and server objects and connect
|
|
irc = DrBotIRC.DrBotIRC(config)
|
|
server = irc.server().connect(botserver, botport, botnick, botpass, botuser, botircname)
|
|
|
|
# load features
|
|
try:
|
|
cfgmodlist = config.get('dr.botzo', 'module_list')
|
|
|
|
mods = cfgmodlist.split(',')
|
|
for mod in mods:
|
|
irc.load_module(mod)
|
|
except NoSectionError as e:
|
|
print("You seem to be missing a modules config section, which you probably wanted.")
|
|
except NoOptionError as e:
|
|
print("You seem to be missing a modlist config option, which you probably wanted.")
|
|
|
|
# loop forever
|
|
irc.process_forever()
|
|
|
|
# vi:tabstop=4:expandtab:autoindent
|
|
# kate: indent-mode python;indent-width 4;replace-tabs on;
|