From 250cf8a95a6effefbcf1a1e3beea32d5cfb2666b Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Mon, 14 Apr 2003 14:47:02 +0000 Subject: [PATCH] Changed implementation of notes command. --- plugins/Notes.py | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/plugins/Notes.py b/plugins/Notes.py index f661e6f67..7ac31da84 100644 --- a/plugins/Notes.py +++ b/plugins/Notes.py @@ -196,28 +196,22 @@ class Notes(callbacks.Privmsg): self.cursor.execute("""SELECT id, from_id, public, read FROM notes WHERE to_id=%s AND read=0""", senderID) + count = cursor.rowcount 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 = [] - for (id, from_id, public, read) in notes: - if not int(read): - sender = self.getUserName(from_id) - if int(public): - L.append(r'#%s from %s' % (id, sender)) - else: - L.append(r'#%s (private)' % id) - if count > 5: - L = string.join(L[:5], ', ') - reply = "you have %s unread notes, 5 shown: %s" % (count, L) + if count == 0: + irc.reply(msg, 'You have no unread notes.') else: - L = string.join(L, ', ') - reply = "you have %s unread notes: %s" % (count, L) - #debug.printf(L) - irc.reply(msg, reply) + for (id, from_id, public, read) in notes: + if not int(read): + sender = self.getUserName(from_id) + if int(public): + L.append(r'#%s from %s' % (id, sender)) + else: + L.append(r'#%s (private)' % id) + while reduce(operator.add, L) + 2*len(L) > 400: + L.pop() + irc.reply(msg, ', '.join(L)) Class = Notes