Removed requested_by and use_count from {lart,excuse,insult,praise} tables

This commit is contained in:
James Vega 2003-09-16 18:11:16 +00:00
parent 9ed2dcbc31
commit 292bb2550e

View File

@ -58,27 +58,19 @@ dbFilename = os.path.join(conf.dataDir, 'FunDB.db')
tableCreateStatements = { tableCreateStatements = {
'larts': ("""CREATE TABLE larts ( 'larts': ("""CREATE TABLE larts (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
lart TEXT, added_by TEXT, lart TEXT, added_by TEXT
requested_by TEXT,
use_count INTEGER
)""",), )""",),
'praises': ("""CREATE TABLE praises ( 'praises': ("""CREATE TABLE praises (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
praise TEXT, added_by TEXT, praise TEXT, added_by TEXT
requested_by TEXT,
use_count INTEGER
)""",), )""",),
'insults': ("""CREATE TABLE insults ( 'insults': ("""CREATE TABLE insults (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
insult TEXT, added_by TEXT, insult TEXT, added_by TEXT
requested_by TEXT,
use_count INTEGER
)""",), )""",),
'excuses': ("""CREATE TABLE excuses ( 'excuses': ("""CREATE TABLE excuses (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
excuse TEXT, added_by TEXT, excuse TEXT, added_by TEXT
requested_by TEXT,
use_count INTEGER
)""",), )""",),
'words': ("""CREATE TABLE words ( 'words': ("""CREATE TABLE words (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
@ -197,9 +189,6 @@ class FunDB(callbacks.Privmsg):
irc.error(msg, 'There are currently no available insults.') irc.error(msg, 'There are currently no available insults.')
return return
(id, insult) = cursor.fetchone() (id, insult) = cursor.fetchone()
sql = """UPDATE insults SET use_count=use_count+1, requested_by=%s
WHERE id=%s"""
cursor.execute(sql, msg.prefix, id)
nick = nick.strip() nick = nick.strip()
if nick in (irc.nick, 'yourself', 'me'): if nick in (irc.nick, 'yourself', 'me'):
insultee = msg.nick insultee = msg.nick
@ -244,9 +233,6 @@ class FunDB(callbacks.Privmsg):
irc.error(msg, 'There are currently no available excuses.') irc.error(msg, 'There are currently no available excuses.')
else: else:
(id, excuse) = cursor.fetchone() (id, excuse) = cursor.fetchone()
sql = """UPDATE excuses SET use_count=use_count+1, requested_by=%s
WHERE id=%s"""
cursor.execute(sql, msg.prefix, id)
irc.reply(msg, '%s (#%s)' % (excuse, id)) irc.reply(msg, '%s (#%s)' % (excuse, id))
def dbadd(self, irc, msg, args): def dbadd(self, irc, msg, args):
@ -276,8 +262,7 @@ class FunDB(callbacks.Privmsg):
(table, utils.commaAndify(self._tables))) (table, utils.commaAndify(self._tables)))
return return
cursor = self.db.cursor() cursor = self.db.cursor()
sql = """INSERT INTO %ss VALUES (NULL, %%s, %%s, 'nobody', sql = """INSERT INTO %ss VALUES (NULL, %%s, %%s)""" % table
0)""" % table
cursor.execute(sql, s, name) cursor.execute(sql, s, name)
self.db.commit() self.db.commit()
sql = """SELECT id FROM %ss WHERE %s=%%s""" % (table, table) sql = """SELECT id FROM %ss WHERE %s=%%s""" % (table, table)
@ -422,16 +407,13 @@ class FunDB(callbacks.Privmsg):
(table, utils.commaAndify(self._tables))) (table, utils.commaAndify(self._tables)))
return return
cursor = self.db.cursor() cursor = self.db.cursor()
sql = """SELECT added_by, requested_by, use_count FROM %ss WHERE sql = """SELECT added_by FROM %ss WHERE id=%%s""" % table
id=%%s""" % table
cursor.execute(sql, id) cursor.execute(sql, id)
if cursor.rowcount == 0: if cursor.rowcount == 0:
irc.error(msg, 'There is no such %s.' % table) irc.error(msg, 'There is no such %s.' % table)
else: else:
(add,req,count) = cursor.fetchone() add = cursor.fetchone()[0]
reply = '%s #%s: Created by %s. last requested by %s, requested'\ reply = '%s #%s: Created by %s.' % (table, id, add)
' a total of %s' % \
(table, id, add, req, utils.nItems(count, 'time'))
irc.reply(msg, reply) irc.reply(msg, reply)
def lart(self, irc, msg, args): def lart(self, irc, msg, args):
@ -457,9 +439,6 @@ class FunDB(callbacks.Privmsg):
irc.error(msg, 'There are currently no available larts.') irc.error(msg, 'There are currently no available larts.')
else: else:
(id, lart) = cursor.fetchone() (id, lart) = cursor.fetchone()
sql = """UPDATE larts SET use_count=use_count+1, requested_by=%s
WHERE id=%s"""
cursor.execute(sql, msg.prefix, id)
if nick == irc.nick or nick == 'me': if nick == irc.nick or nick == 'me':
lartee = msg.nick lartee = msg.nick
else: else:
@ -495,10 +474,6 @@ class FunDB(callbacks.Privmsg):
irc.error(msg, 'There are currently no available praises.') irc.error(msg, 'There are currently no available praises.')
else: else:
(id, praise) = cursor.fetchone() (id, praise) = cursor.fetchone()
sql = """UPDATE praises SET use_count=use_count+1, requested_by=%s
WHERE id=%s"""
cursor.execute(sql, msg.prefix, id)
self.db.commit()
if nick == irc.nick or nick == 'me': if nick == irc.nick or nick == 'me':
praisee = msg.nick praisee = msg.nick
else: else:
@ -571,21 +546,21 @@ if __name__ == '__main__':
elif category == 'larts': elif category == 'larts':
if '$who' in line: if '$who' in line:
cursor.execute("""INSERT INTO larts VALUES (NULL, %s, cursor.execute("""INSERT INTO larts VALUES (NULL, %s,
%s, nobody, 0)""", line, added_by) %s)""", line, added_by)
else: else:
print 'Invalid lart: %s' % line print 'Invalid lart: %s' % line
elif category == 'praises': elif category == 'praises':
if '$who' in line: if '$who' in line:
cursor.execute("""INSERT INTO praises VALUES (NULL, %s, cursor.execute("""INSERT INTO praises VALUES (NULL, %s,
%s, nobody, 0)""", line, added_by) %s)""", line, added_by)
else: else:
print 'Invalid praise: %s' % line print 'Invalid praise: %s' % line
elif category == 'insults': elif category == 'insults':
cursor.execute("""INSERT INTO insults VALUES (NULL, %s, %s, cursor.execute("""INSERT INTO insults VALUES (NULL, %s, %s
nobody, 0)""", line, added_by) )""", line, added_by)
elif category == 'excuses': elif category == 'excuses':
cursor.execute("""INSERT INTO excuses VALUES (NULL, %s, %s, cursor.execute("""INSERT INTO excuses VALUES (NULL, %s, %s
nobody, 0)""", line, added_by) )""", line, added_by)
db.commit() db.commit()
db.close() db.close()