diff --git a/ChangeLog b/ChangeLog index 350a3030c..f5f4c338f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ + * Added Note.unsend command, to allow users to "unsend" notes + they've sent but whose recipient has not yet read. + * Added Channel.{deop,devoice,dehalfop,kick}. * Added Http.size and Http.doctype and Http.headers to retrieve diff --git a/plugins/Note.py b/plugins/Note.py index 9cc1c2763..ef2c612d7 100644 --- a/plugins/Note.py +++ b/plugins/Note.py @@ -154,6 +154,36 @@ class Note(callbacks.Privmsg): id = cursor.fetchone()[0] irc.reply(msg, 'Note #%s sent to %s.' % (id, name)) + def unsend(self, irc, msg, args): + """ + + Unsends the note with the id given. You must be the + author of the note, and it must be unread. + """ + id = privmsgs.getArgs(args) + try: + userid = ircdb.users.getUserId(msg.prefix) + except KeyError: + irc.error(msg, conf.replyNotRegistered) + return + db = self.dbHandler.getDb() + cursor = db.cursor() + cursor.execute("""SELECT from_id, read FROM notes WHERE id=%s""", id) + if cursor.rowcount == 0: + irc.error(msg, 'That\'s not a valid note id.') + return + (from_id, read) = map(int, cursor.fetchone()) + if from_id == userid: + if not read: + cursor.execute("""DELETE FROM notes WHERE id=%s""", id) + db.commit() + irc.reply(msg, conf.replySuccess) + else: + irc.error(msg, 'That note has been read already.') + else: + irc.error(msg, 'That note wasn\'t sent by you.') + + def get(self, irc, msg, args): """