mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 14:59:34 +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))
|
onStart.append('lookup add %s %s' % (command, filename))
|
||||||
|
|
||||||
|
|
||||||
|
conf.registerPlugin('Lookup')
|
||||||
|
conf.registerGroup(conf.supybot.plugins.Lookup, 'lookups')
|
||||||
|
|
||||||
class LookupDB(plugins.DBHandler):
|
class LookupDB(plugins.DBHandler):
|
||||||
def makeDb(self, filename):
|
def makeDb(self, filename):
|
||||||
return sqlite.connect(filename)
|
return sqlite.connect(filename)
|
||||||
@ -149,14 +152,21 @@ class Lookup(callbacks.Privmsg):
|
|||||||
self.addCommand(name)
|
self.addCommand(name)
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
except sqlite.DatabaseError:
|
except sqlite.DatabaseError:
|
||||||
# Good, there's no such database.
|
|
||||||
try:
|
try:
|
||||||
dataDir = conf.supybot.directories.data()
|
self.addDatabase(name, filename)
|
||||||
filename = os.path.join(dataDir, filename)
|
|
||||||
fd = file(filename)
|
|
||||||
except EnvironmentError, e:
|
except EnvironmentError, e:
|
||||||
irc.error('Could not open %s: %s' % (filename, e.args[1]))
|
irc.error('Could not open %s: %s' % (filename, e.args[1]))
|
||||||
return
|
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:
|
try:
|
||||||
cursor.execute("""SELECT COUNT(*) FROM %s""" % name)
|
cursor.execute("""SELECT COUNT(*) FROM %s""" % name)
|
||||||
except sqlite.DatabaseError:
|
except sqlite.DatabaseError:
|
||||||
@ -170,14 +180,10 @@ class Lookup(callbacks.Privmsg):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
cursor.execute("""DROP TABLE %s""" % name)
|
cursor.execute("""DROP TABLE %s""" % name)
|
||||||
s = 'Invalid line in %s: %r' % (filename, line)
|
s = 'Invalid line in %s: %r' % (filename, line)
|
||||||
irc.error(s)
|
raise callbacks.Error, s
|
||||||
return
|
|
||||||
cursor.execute(sql, key, value)
|
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()
|
db.commit()
|
||||||
self.addCommand(name)
|
|
||||||
irc.replySuccess('(lookup %s added)' % name)
|
|
||||||
add = privmsgs.checkCapability(add, 'admin')
|
|
||||||
|
|
||||||
def addCommand(self, name):
|
def addCommand(self, name):
|
||||||
def f(self, irc, msg, args):
|
def f(self, irc, msg, args):
|
||||||
|
Loading…
Reference in New Issue
Block a user