Changed implementation of notes command.

This commit is contained in:
Jeremy Fincher 2003-04-14 14:47:02 +00:00
parent ab1d8cecd6
commit 250cf8a95a

View File

@ -196,13 +196,12 @@ class Notes(callbacks.Privmsg):
self.cursor.execute("""SELECT id, from_id, public, read FROM notes self.cursor.execute("""SELECT id, from_id, public, read FROM notes
WHERE to_id=%s WHERE to_id=%s
AND read=0""", senderID) AND read=0""", senderID)
count = cursor.rowcount
notes = self.cursor.fetchall() notes = self.cursor.fetchall()
self.cursor.execute("""SELECT count(*) FROM notes
WHERE to_id=%s
AND read=0""", senderID)
count = int(self.cursor.fetchone()[0])
#debug.printf("count: %s" % count)
L = [] L = []
if count == 0:
irc.reply(msg, 'You have no unread notes.')
else:
for (id, from_id, public, read) in notes: for (id, from_id, public, read) in notes:
if not int(read): if not int(read):
sender = self.getUserName(from_id) sender = self.getUserName(from_id)
@ -210,14 +209,9 @@ class Notes(callbacks.Privmsg):
L.append(r'#%s from %s' % (id, sender)) L.append(r'#%s from %s' % (id, sender))
else: else:
L.append(r'#%s (private)' % id) L.append(r'#%s (private)' % id)
if count > 5: while reduce(operator.add, L) + 2*len(L) > 400:
L = string.join(L[:5], ', ') L.pop()
reply = "you have %s unread notes, 5 shown: %s" % (count, L) irc.reply(msg, ', '.join(L))
else:
L = string.join(L, ', ')
reply = "you have %s unread notes: %s" % (count, L)
#debug.printf(L)
irc.reply(msg, reply)
Class = Notes Class = Notes