mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +01:00
Update to use the new-style DB abstraction.
This commit is contained in:
parent
d242c8ad81
commit
bc8a6b94d9
@ -81,12 +81,29 @@ conf.registerChannelValue(conf.supybot.plugins.Karma, 'allowUnaddressedKarma',
|
||||
increase/decrease karma without being addressed."""))
|
||||
|
||||
class SqliteKarmaDB(object):
|
||||
def __init__(self, filename):
|
||||
self.dbs = ircutils.IrcDict()
|
||||
self.filename = filename
|
||||
|
||||
def close(self):
|
||||
for db in self.dbs.itervalues():
|
||||
db.close()
|
||||
|
||||
def _getDb(self, channel):
|
||||
filename = plugins.makeChannelFilename('Karma.db', channel)
|
||||
try:
|
||||
import sqlite
|
||||
except ImportError:
|
||||
raise callbacks.Error, 'You need to have PySQLite installed to ' \
|
||||
'use this plugin. Download it at ' \
|
||||
'<http://pysqlite.sf.net/>'
|
||||
filename = plugins.makeChannelFilename(self.filename, channel)
|
||||
if filename in self.dbs:
|
||||
return self.dbs[filename]
|
||||
if os.path.exists(filename):
|
||||
self.dbs[filename] = sqlite.connect(filename)
|
||||
return self.dbs[filename]
|
||||
db = sqlite.connect(filename)
|
||||
else:
|
||||
db = sqlite.connect(filename)
|
||||
self.dbs[filename] = db
|
||||
cursor = db.cursor()
|
||||
cursor.execute("""CREATE TABLE karma (
|
||||
id INTEGER PRIMARY KEY,
|
||||
@ -204,9 +221,8 @@ class SqliteKarmaDB(object):
|
||||
WHERE normalized=%s""", normalized)
|
||||
db.commit()
|
||||
|
||||
|
||||
def KarmaDB():
|
||||
return SqliteKarmaDB()
|
||||
KarmaDB = plugins.DB('Karma',
|
||||
{'sqlite': SqliteKarmaDB})
|
||||
|
||||
class Karma(callbacks.Privmsg):
|
||||
callBefore = ('Factoids', 'MoobotFactoids', 'Infobot')
|
||||
@ -214,6 +230,9 @@ class Karma(callbacks.Privmsg):
|
||||
self.db = KarmaDB()
|
||||
super(Karma, self).__init__()
|
||||
|
||||
def die(self):
|
||||
self.db.close()
|
||||
|
||||
def _normalizeThing(self, thing):
|
||||
assert thing
|
||||
if thing[0] == '(' and thing[-1] == ')':
|
||||
|
@ -79,8 +79,9 @@ class NewsRecord(object):
|
||||
return s
|
||||
|
||||
class SqliteNewsDB(object):
|
||||
def __init__(self):
|
||||
def __init__(self, filename):
|
||||
self.dbs = ircutils.IrcDict()
|
||||
self.filename = filename
|
||||
|
||||
def close(self):
|
||||
for db in self.dbs.itervalues():
|
||||
@ -93,7 +94,7 @@ class SqliteNewsDB(object):
|
||||
raise callbacks.Error, 'You need to have PySQLite installed to ' \
|
||||
'use this plugin. Download it at ' \
|
||||
'<http://pysqlite.sf.net/>'
|
||||
filename = plugins.makeChannelFilename(channel, 'News.db')
|
||||
filename = plugins.makeChannelFilename(self.filename, channel)
|
||||
if filename in self.dbs:
|
||||
return self.dbs[filename]
|
||||
if os.path.exists(filename):
|
||||
@ -170,8 +171,8 @@ class SqliteNewsDB(object):
|
||||
cursor.execute("""UPDATE news SET subject=%s, item=%s WHERE id=%s""",
|
||||
newSubject, newItem, id)
|
||||
|
||||
def NewsDB():
|
||||
return SqliteNewsDB()
|
||||
NewsDB = plugins.DB('News',
|
||||
{'sqlite': SqliteNewsDB})
|
||||
|
||||
class News(callbacks.Privmsg):
|
||||
def __init__(self):
|
||||
|
Loading…
Reference in New Issue
Block a user