mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-30 14:14:37 +01:00
Added --{from,to} and --sent options to Note.list
This commit is contained in:
parent
b943f611e2
commit
096bbdc463
@ -1,3 +1,5 @@
|
|||||||
|
* Added --{from,to} and --sent options to Note.sent.
|
||||||
|
|
||||||
* Changed channel capabilities to use a comma to separate the
|
* Changed channel capabilities to use a comma to separate the
|
||||||
channel from the capability instead of a period. This is because
|
channel from the capability instead of a period. This is because
|
||||||
channels can include periods (but not commas) and since we now
|
channels can include periods (but not commas) and since we now
|
||||||
|
103
plugins/Note.py
103
plugins/Note.py
@ -173,7 +173,7 @@ class Note(callbacks.Privmsg):
|
|||||||
db = self.dbHandler.getDb()
|
db = self.dbHandler.getDb()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""SELECT from_id, read FROM notes WHERE id=%s""", id)
|
cursor.execute("""SELECT from_id, read FROM notes WHERE id=%s""", id)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount < 1:
|
||||||
irc.error('That\'s not a valid note id.')
|
irc.error('That\'s not a valid note id.')
|
||||||
return
|
return
|
||||||
(from_id, read) = map(int, cursor.fetchone())
|
(from_id, read) = map(int, cursor.fetchone())
|
||||||
@ -213,7 +213,7 @@ class Note(callbacks.Privmsg):
|
|||||||
FROM notes
|
FROM notes
|
||||||
WHERE (to_id=%s OR from_id=%s) AND id=%s""",
|
WHERE (to_id=%s OR from_id=%s) AND id=%s""",
|
||||||
id, id, noteid)
|
id, id, noteid)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount < 1:
|
||||||
s = 'You may only retrieve notes you\'ve sent or received.'
|
s = 'You may only retrieve notes you\'ve sent or received.'
|
||||||
irc.error(s)
|
irc.error(s)
|
||||||
return
|
return
|
||||||
@ -241,38 +241,71 @@ class Note(callbacks.Privmsg):
|
|||||||
return '#%s (private)' % id
|
return '#%s (private)' % id
|
||||||
|
|
||||||
def list(self, irc, msg, args):
|
def list(self, irc, msg, args):
|
||||||
"""[--{old,sent}]
|
"""[--{old,sent}] [--{from,to} <user>]
|
||||||
|
|
||||||
Retrieves the ids of all your unread notes. If --old is given, list
|
Retrieves the ids of all your unread notes. If --old is given, list
|
||||||
read notes. If --sent is given, list notes that you have sent.
|
read notes. If --sent is given, list notes that you have sent. If
|
||||||
|
--from is specified, only lists notes sent to you from <user>. If
|
||||||
|
--to is specified, only lists notes sent by you to <user>.
|
||||||
"""
|
"""
|
||||||
options = ['old', 'sent']
|
options = ['old', 'sent', 'from=', 'to=']
|
||||||
(optlist, rest) = getopt.getopt(args, '', options)
|
(optlist, rest) = getopt.getopt(args, '', options)
|
||||||
for (option, _) in optlist:
|
sender, receiver, old, sent = ('', '', False, False)
|
||||||
|
for (option, arg) in optlist:
|
||||||
option = option.lstrip('-')
|
option = option.lstrip('-')
|
||||||
if option == 'old':
|
if option == 'old':
|
||||||
return self._oldnotes(irc, msg)
|
old = True
|
||||||
if option == 'sent':
|
if option == 'sent':
|
||||||
return self._sentnotes(irc, msg)
|
sent = True
|
||||||
|
if option == 'from':
|
||||||
|
sender = arg
|
||||||
|
if option == 'to':
|
||||||
|
receiver = arg
|
||||||
|
sent = True
|
||||||
|
if old:
|
||||||
|
return self._oldnotes(irc, msg, sender)
|
||||||
|
if sent:
|
||||||
|
return self._sentnotes(irc, msg, receiver)
|
||||||
try:
|
try:
|
||||||
id = ircdb.users.getUserId(msg.prefix)
|
id = ircdb.users.getUserId(msg.prefix)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
irc.errorNotRegistered()
|
irc.errorNotRegistered()
|
||||||
return
|
return
|
||||||
|
sql = """SELECT id, from_id, public
|
||||||
|
FROM notes
|
||||||
|
WHERE notes.to_id=%r AND notes.read=0""" % id
|
||||||
|
if sender:
|
||||||
|
try:
|
||||||
|
sender = ircdb.users.getUserId(sender)
|
||||||
|
except KeyError:
|
||||||
|
irc.error('That user is not in my user database.')
|
||||||
|
return
|
||||||
|
sql = '%s %s' % (sql, 'AND notes.from_id=%r' % sender)
|
||||||
db = self.dbHandler.getDb()
|
db = self.dbHandler.getDb()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""SELECT id, from_id, public
|
cursor.execute(sql)
|
||||||
FROM notes
|
|
||||||
WHERE notes.to_id=%s AND notes.read=0""", id)
|
|
||||||
count = cursor.rowcount
|
count = cursor.rowcount
|
||||||
L = []
|
if count < 1:
|
||||||
if count == 0:
|
|
||||||
irc.reply('You have no unread notes.')
|
irc.reply('You have no unread notes.')
|
||||||
else:
|
else:
|
||||||
L = [self._formatNoteData(msg, *t) for t in cursor.fetchall()]
|
L = [self._formatNoteData(msg, *t) for t in cursor.fetchall()]
|
||||||
|
L = self._condense(L)
|
||||||
irc.reply(utils.commaAndify(L))
|
irc.reply(utils.commaAndify(L))
|
||||||
|
|
||||||
def _sentnotes(self, irc, msg):
|
def _condense(self, notes):
|
||||||
|
temp = {}
|
||||||
|
for note in notes:
|
||||||
|
note = note.split(' ', 1)
|
||||||
|
if note[1] in temp:
|
||||||
|
temp[note[1]].append(note[0])
|
||||||
|
else:
|
||||||
|
temp[note[1]] = [note[0]]
|
||||||
|
notes = []
|
||||||
|
for (k,v) in temp.iteritems():
|
||||||
|
notes.append('%s %s' % (', '.join(v), k))
|
||||||
|
return notes
|
||||||
|
|
||||||
|
def _sentnotes(self, irc, msg, receiver):
|
||||||
"""takes no arguments
|
"""takes no arguments
|
||||||
|
|
||||||
Returns a list of your most recent old notes.
|
Returns a list of your most recent old notes.
|
||||||
@ -282,20 +315,28 @@ class Note(callbacks.Privmsg):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
irc.errorNotRegistered()
|
irc.errorNotRegistered()
|
||||||
return
|
return
|
||||||
|
sql = """SELECT id, to_id, public
|
||||||
|
FROM notes
|
||||||
|
WHERE notes.from_id=%r""" % id
|
||||||
|
if receiver:
|
||||||
|
try:
|
||||||
|
receiver = ircdb.users.getUserId(receiver)
|
||||||
|
except KeyError:
|
||||||
|
irc.error('That user is not in my user database.')
|
||||||
|
return
|
||||||
|
sql = '%s %s' % (sql, 'AND notes.to_id=%r' % receiver)
|
||||||
db = self.dbHandler.getDb()
|
db = self.dbHandler.getDb()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""SELECT id, to_id, public
|
cursor.execute(sql)
|
||||||
FROM notes
|
if cursor.rowcount < 1:
|
||||||
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.')
|
irc.reply('I couldn\'t find any sent notes for your user.')
|
||||||
else:
|
else:
|
||||||
ids = [self._formatNoteData(msg, sent=True, *t) for t in
|
ids = [self._formatNoteData(msg, sent=True, *t) for t in
|
||||||
cursor.fetchall()]
|
cursor.fetchall()]
|
||||||
|
ids = self._condense(ids)
|
||||||
irc.reply(utils.commaAndify(ids))
|
irc.reply(utils.commaAndify(ids))
|
||||||
|
|
||||||
def _oldnotes(self, irc, msg):
|
def _oldnotes(self, irc, msg, sender):
|
||||||
"""takes no arguments
|
"""takes no arguments
|
||||||
|
|
||||||
Returns a list of your most recent old notes.
|
Returns a list of your most recent old notes.
|
||||||
@ -305,16 +346,28 @@ class Note(callbacks.Privmsg):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
irc.errorNotRegistered()
|
irc.errorNotRegistered()
|
||||||
return
|
return
|
||||||
|
sql = """SELECT id, from_id, public
|
||||||
|
FROM notes
|
||||||
|
WHERE notes.to_id=%r AND notes.read=1""" % id
|
||||||
|
#self.log.warning(sender)
|
||||||
|
if sender:
|
||||||
|
try:
|
||||||
|
sender = ircdb.users.getUserId(sender)
|
||||||
|
except KeyError:
|
||||||
|
irc.error('That user is not in my user database.')
|
||||||
|
return
|
||||||
|
sql = '%s %s' % (sql, 'AND notes.from_id=%r' % sender)
|
||||||
db = self.dbHandler.getDb()
|
db = self.dbHandler.getDb()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""SELECT id, from_id, public
|
cursor.execute(sql)
|
||||||
FROM notes
|
#self.log.warning(cursor.rowcount)
|
||||||
WHERE notes.to_id=%s AND notes.read=1
|
if cursor.rowcount < 1:
|
||||||
ORDER BY id DESC""", id)
|
|
||||||
if cursor.rowcount == 0:
|
|
||||||
irc.reply('I couldn\'t find any read notes for your user.')
|
irc.reply('I couldn\'t find any read notes for your user.')
|
||||||
else:
|
else:
|
||||||
ids = [self._formatNoteData(msg, *t) for t in cursor.fetchall()]
|
ids = [self._formatNoteData(msg, *t) for t in cursor.fetchall()]
|
||||||
|
#self.log.warning(ids)
|
||||||
|
ids.reverse()
|
||||||
|
ids = self._condense(ids)
|
||||||
irc.reply(utils.commaAndify(ids))
|
irc.reply(utils.commaAndify(ids))
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ if sqlite is not None:
|
|||||||
_ = self.getMsg(' ')
|
_ = self.getMsg(' ')
|
||||||
self.assertNotError('note send inkedmn 1,2,3')
|
self.assertNotError('note send inkedmn 1,2,3')
|
||||||
_ = self.getMsg(' ')
|
_ = self.getMsg(' ')
|
||||||
self.assertRegexp('note list --sent', r'#2.*#1')
|
self.assertRegexp('note list --sent', r'#1.*#2')
|
||||||
self.assertRegexp('note list', r'#1.*#2')
|
self.assertRegexp('note list', r'#1.*#2')
|
||||||
self.assertRegexp('note 1', 'testing')
|
self.assertRegexp('note 1', 'testing')
|
||||||
self.assertResponse('note list --old', '#1 from inkedmn')
|
self.assertResponse('note list --old', '#1 from inkedmn')
|
||||||
|
Loading…
Reference in New Issue
Block a user