mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-02 15:44:06 +01:00
So begins the slow whittling away at the "Condense old notes" RFE
This commit is contained in:
parent
7f2578a13e
commit
b410a79d64
@ -39,6 +39,7 @@ __revision__ = "$Id$"
|
||||
import plugins
|
||||
|
||||
import time
|
||||
import getopt
|
||||
import os.path
|
||||
from itertools import imap
|
||||
|
||||
@ -228,24 +229,31 @@ class Note(callbacks.Privmsg):
|
||||
irc.reply(newnote, private=(not public))
|
||||
self.setAsRead(noteid)
|
||||
|
||||
def _formatNoteData(self, msg, id, fromId, public):
|
||||
def _formatNoteData(self, msg, id, fromId, public, sent=False):
|
||||
(id, fromId, public) = imap(int, (id, fromId, public))
|
||||
if public or not ircutils.isChannel(msg.args[0]):
|
||||
sender = ircdb.users.getUser(fromId).name
|
||||
if sent:
|
||||
return '#%s to %s' % (id, sender)
|
||||
else:
|
||||
return '#%s from %s' % (id, sender)
|
||||
else:
|
||||
return '#%s (private)' % id
|
||||
|
||||
def list(self, irc, msg, args):
|
||||
"""[--old]
|
||||
"""[--{old,sent}]
|
||||
|
||||
Retrieves the ids of all your unread notes. If --old is given, list
|
||||
read notes.
|
||||
read notes. If --sent is given, list notes that you have sent.
|
||||
"""
|
||||
if '--old' in args:
|
||||
while '--old' in args:
|
||||
args.remove('--old')
|
||||
return self._oldnotes(irc, msg, args)
|
||||
options = ['old', 'sent']
|
||||
(optlist, rest) = getopt.getopt(args, '', options)
|
||||
for (option, _) in optlist:
|
||||
option = option.lstrip('-')
|
||||
if option == 'old':
|
||||
return self._oldnotes(irc, msg)
|
||||
if option == 'sent':
|
||||
return self._sentnotes(irc, msg)
|
||||
try:
|
||||
id = ircdb.users.getUserId(msg.prefix)
|
||||
except KeyError:
|
||||
@ -264,7 +272,30 @@ class Note(callbacks.Privmsg):
|
||||
L = [self._formatNoteData(msg, *t) for t in cursor.fetchall()]
|
||||
irc.reply(utils.commaAndify(L))
|
||||
|
||||
def _oldnotes(self, irc, msg, args):
|
||||
def _sentnotes(self, irc, msg):
|
||||
"""takes no arguments
|
||||
|
||||
Returns a list of your most recent old notes.
|
||||
"""
|
||||
try:
|
||||
id = ircdb.users.getUserId(msg.prefix)
|
||||
except KeyError:
|
||||
irc.errorNotRegistered()
|
||||
return
|
||||
db = self.dbHandler.getDb()
|
||||
cursor = db.cursor()
|
||||
cursor.execute("""SELECT id, to_id, public
|
||||
FROM notes
|
||||
WHERE notes.from_id=%s
|
||||
ORDER BY id DESC""", id)
|
||||
if cursor.rowcount == 0:
|
||||
irc.reply('I couldn\'t find any sent notes for your user.')
|
||||
else:
|
||||
ids = [self._formatNoteData(msg, sent=True, *t) for t in
|
||||
cursor.fetchall()]
|
||||
irc.reply(utils.commaAndify(ids))
|
||||
|
||||
def _oldnotes(self, irc, msg):
|
||||
"""takes no arguments
|
||||
|
||||
Returns a list of your most recent old notes.
|
||||
@ -278,12 +309,12 @@ class Note(callbacks.Privmsg):
|
||||
cursor = db.cursor()
|
||||
cursor.execute("""SELECT id, from_id, public
|
||||
FROM notes
|
||||
WHERE notes.to_id=%s AND notes.read=1""", id)
|
||||
WHERE notes.to_id=%s AND notes.read=1
|
||||
ORDER BY id DESC""", id)
|
||||
if cursor.rowcount == 0:
|
||||
irc.reply('I couldn\'t find any read notes for your user.')
|
||||
else:
|
||||
ids = [self._formatNoteData(msg, *t) for t in cursor.fetchall()]
|
||||
ids.reverse()
|
||||
irc.reply(utils.commaAndify(ids))
|
||||
|
||||
|
||||
|
@ -42,26 +42,39 @@ except ImportError:
|
||||
if sqlite is not None:
|
||||
class NoteTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('Note', 'Misc', 'User')
|
||||
def setUp(self):
|
||||
PluginTestCase.setUp(self)
|
||||
# setup a user
|
||||
self.prefix = 'foo!bar@baz'
|
||||
self.assertNotError('register inkedmn bar')
|
||||
|
||||
def testSendnote(self):
|
||||
#print repr(ircdb.users.getUser(self.prefix))
|
||||
self.prefix = 'foo!bar@baz'
|
||||
self.assertNotError('register foo bar')
|
||||
(id, u) = ircdb.users.newUser()
|
||||
u.name = 'inkedmn'
|
||||
ircdb.users.setUser(id, u)
|
||||
self.assertRegexp('note send inkedmn test', '#1')
|
||||
# have to getMsg(' ') after each Note.send to absorb supybot's
|
||||
# automatic "You have an unread note" message
|
||||
_ = self.getMsg(' ')
|
||||
self.assertError('note send alsdkjfasldk foo')
|
||||
self.assertNotRegexp('note send inkedmn test2', 'the operation')
|
||||
self.assertNotError('note send inkedmn test2')
|
||||
_ = self.getMsg(' ')
|
||||
|
||||
def testNote(self):
|
||||
# self.assertNotError('note 1')
|
||||
self.assertNotError('note send inkedmn test')
|
||||
_ = self.getMsg(' ')
|
||||
self.assertRegexp('note 1', 'test')
|
||||
self.assertError('note blah')
|
||||
|
||||
def testNotes(self):
|
||||
self.assertNotError('note list')
|
||||
def testList(self):
|
||||
self.assertResponse('note list', 'You have no unread notes.')
|
||||
self.assertNotError('note send inkedmn testing')
|
||||
_ = self.getMsg(' ')
|
||||
self.assertNotError('note send inkedmn 1,2,3')
|
||||
_ = self.getMsg(' ')
|
||||
self.assertRegexp('note list --sent', r'#2.*#1')
|
||||
self.assertRegexp('note list', r'#1.*#2')
|
||||
self.assertRegexp('note 1', 'testing')
|
||||
self.assertResponse('note list --old', '#1 from inkedmn')
|
||||
|
||||
def testOldNotes(self):
|
||||
self.assertNotError('note list --old')
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
Loading…
Reference in New Issue
Block a user