From 7c314688665a844855c6db3721a18daf501876c1 Mon Sep 17 00:00:00 2001 From: Brett Kelly Date: Thu, 3 Apr 2003 05:48:57 +0000 Subject: [PATCH] everything appears to be working, please lemme know if it barfs --- plugins/Notes.py | 72 +++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 44 deletions(-) diff --git a/plugins/Notes.py b/plugins/Notes.py index 6b9eb33f9..295092e84 100644 --- a/plugins/Notes.py +++ b/plugins/Notes.py @@ -109,8 +109,12 @@ class Notes(callbacks.Privmsg): args[0] = msg.nick return ircmsgs.IrcMsg(command = msg.command, prefix = msg.prefix, args = tuple(args)) + + def setAsRead(self, noteid): + self.cursor.execute('UPDATE notes SET read=1 WHERE id=%s', noteid) + self.db.commit() -# def setNoteUnread(self, irc, msg, args): +# def setUnread(self, irc, msg, args): # "set a note as unread" # noteid = privmsgs.getArgs(args) # self.cursor.execute('UPDATE notes SET read=0 where id=%s'% noteid) @@ -118,8 +122,9 @@ class Notes(callbacks.Privmsg): # irc.reply(msg, conf.replySuccess) def sendnote(self, irc, msg, args): - "sends a new note to an IRC user" - # sendnote + """ + + Sends a new note to the user specified.""" (name, note) = privmsgs.getArgs(args, needed=2) sender = ircutils.nickFromHostmask(msg.prefix) if ircdb.users.hasUser(name): @@ -143,8 +148,9 @@ class Notes(callbacks.Privmsg): irc.reply(msg, conf.replySuccess) def note(self, irc, msg, args): - "retrieves a single note by unique note id" - # BLOODY HELL, THIS ACTUALLY WORKS!!! + """ + + Retrieves a single note by unique note id.""" noteid = privmsgs.getArgs(args) if not self.isNote(noteid): irc.error(msg, 'Not a valid note id') @@ -163,67 +169,45 @@ class Notes(callbacks.Privmsg): if public: irc.reply(msg, newnote) else: - "trying to change message target" msg = self.makePrivate(msg) irc.reply(msg, newnote) - self.cursor.execute("""UPDATE notes SET read=%s - WHERE id=%s""", (1, noteid[0])) - self.db.commit() + debug.printf("setting note to read=true") + self.setAsRead(noteid) else: irc.error(msg, 'You are not the recipient of note %s' % noteid) def notes(self, irc, msg, args): - "takes no arguments, retrieves all unread notes for the requesting user" + """ + + Retrieves all unread notes for the requesting user.""" sender = ircdb.users.getUserName(msg.prefix) senderID = self.getUserID(sender) - self.cursor.execute("""SELECT id, from_id FROM notes + self.cursor.execute("""SELECT id, from_id, public, read FROM notes WHERE to_id=%s AND read=0""", senderID) notes = self.cursor.fetchall() self.cursor.execute("""SELECT count(*) FROM notes WHERE to_id=%s AND read=0""", senderID) - count = self.cursor.fetchone()[0] + count = int(self.cursor.fetchone()[0]) + debug.printf("count: %d" % count) L = [] - for (id, from_id) in notes: - sender = self.getUserName(from_id) - L.append(r'#%d from %s;; ' % (id, sender)) + for (id, from_id, public, read) in notes: + if not int(read): + sender = self.getUserName(from_id) + if int(public): + L.append(r'#%d from %s' % (id, sender)) + else: + L.append(r'#%d (private)' % id) if count > 5: - L = string.join(L[:5], '') + L = string.join(L[:5], ', ') reply = "you have %s unread notes, 5 shown: %s" % (count, L) else: + L = string.join(L, ', ') reply = "you have %s unread notes: %s" % (count, L) debug.printf(L) irc.reply(msg, reply) -# def deletenote(self, irc, msg, args): -# "removes single note using note id" -# noteid = privmsgs.getArgs(args) -# sender = ircdb.users.getUserName(msg.prefix) -# senderID = self.getUserID(sender) -# self.cursor.execute("""SELECT to_id FROM notes -# WHERE id=%d""" % int(noteid)) -# to_id = self.cursor.fetchall() -# if senderID == to_id: -# self.cursor.execute("""DELETE FROM notes -# WHERE id=%d""" % noteid) -# self.db.commit() -# irc.reply(msg, conf.replySuccess) -# else: -# irc.error(msg, 'Unable to delete note') - -# def getnotes(self, irc, msg, args): -# "takes no arguments gets all notes for sender" -# sender = ircdb.users.getUserName(msg.prefix) -# senderID = self.getUserID(sender) -# self.cursor.execute("""SELECT id, from_id FROM notes -# WHERE to_id=%d""" % senderID) -# notes = self.cursor.fetchall() -# L = [] -# for (id, from_id) in notes: -# sender = self.getUserName(from_id) -# L.append(r'#%d from %s;;' % (id, sender)) - def die(self): self.db.close()