database connection grabbing for Modules
This commit is contained in:
parent
40ab270324
commit
240612fecf
15
Module.py
15
Module.py
@ -20,6 +20,7 @@ from ConfigParser import NoSectionError, NoOptionError
|
||||
import inspect
|
||||
import re
|
||||
import sys
|
||||
import sqlite3
|
||||
|
||||
from extlib import irclib
|
||||
|
||||
@ -281,6 +282,20 @@ class Module(object):
|
||||
|
||||
self.server._handle_event(event)
|
||||
|
||||
def get_db(self):
|
||||
"""
|
||||
Get a database connection to sqlite3. Once grabbed, it should be closed
|
||||
when work is done. Modules that need a database connection should
|
||||
test for and create (or, eventually, alter) required table structure
|
||||
in their __init__ IF that structure does not already exist. Well-behaved
|
||||
modules should use a prefix in their table names (eg "karma_log" rather
|
||||
than "log")
|
||||
"""
|
||||
|
||||
dbfile = self.config.get('dr.botzo', 'database')
|
||||
conn = sqlite3.connect(dbfile)
|
||||
return conn
|
||||
|
||||
def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
|
||||
"""
|
||||
Do the primary thing this module was intended to do.
|
||||
|
Loading…
Reference in New Issue
Block a user