mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Partial conversion to registry, need to get it on my desktop box to test.
This commit is contained in:
parent
285ac5ef6d
commit
03c6efcb7f
@ -88,6 +88,9 @@ def configure(advanced):
|
||||
onStart.append('lookup add %s %s' % (command, filename))
|
||||
|
||||
|
||||
conf.registerPlugin('Lookup')
|
||||
conf.registerGroup(conf.supybot.plugins.Lookup, 'lookups')
|
||||
|
||||
class LookupDB(plugins.DBHandler):
|
||||
def makeDb(self, filename):
|
||||
return sqlite.connect(filename)
|
||||
@ -149,14 +152,21 @@ class Lookup(callbacks.Privmsg):
|
||||
self.addCommand(name)
|
||||
irc.replySuccess()
|
||||
except sqlite.DatabaseError:
|
||||
# Good, there's no such database.
|
||||
try:
|
||||
dataDir = conf.supybot.directories.data()
|
||||
filename = os.path.join(dataDir, filename)
|
||||
fd = file(filename)
|
||||
self.addDatabase(name, filename)
|
||||
except EnvironmentError, e:
|
||||
irc.error('Could not open %s: %s' % (filename, e.args[1]))
|
||||
return
|
||||
self.addCommand(name)
|
||||
irc.replySuccess('(lookup %s added)' % name)
|
||||
add = privmsgs.checkCapability(add, 'admin')
|
||||
|
||||
def addDatabase(self, name, filename):
|
||||
db = self.dbHandler.getDb()
|
||||
cursor = db.cursor()
|
||||
dataDir = conf.supybot.directories.data()
|
||||
filename = os.path.join(dataDir, filename)
|
||||
fd = file(filename)
|
||||
try:
|
||||
cursor.execute("""SELECT COUNT(*) FROM %s""" % name)
|
||||
except sqlite.DatabaseError:
|
||||
@ -170,14 +180,10 @@ class Lookup(callbacks.Privmsg):
|
||||
except ValueError:
|
||||
cursor.execute("""DROP TABLE %s""" % name)
|
||||
s = 'Invalid line in %s: %r' % (filename, line)
|
||||
irc.error(s)
|
||||
return
|
||||
raise callbacks.Error, s
|
||||
cursor.execute(sql, key, value)
|
||||
cursor.execute("CREATE INDEX %s_keys ON %s (key)" %(name,name))
|
||||
cursor.execute("CREATE INDEX %s_keys ON %s (key)" % (name, name))
|
||||
db.commit()
|
||||
self.addCommand(name)
|
||||
irc.replySuccess('(lookup %s added)' % name)
|
||||
add = privmsgs.checkCapability(add, 'admin')
|
||||
|
||||
def addCommand(self, name):
|
||||
def f(self, irc, msg, args):
|
||||
|
Loading…
Reference in New Issue
Block a user