mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Added --id=<id> to praise and lart (RFE #827075)
This commit is contained in:
parent
71c79417e1
commit
5b1026e1f9
@ -42,6 +42,7 @@ import string
|
||||
import os.path
|
||||
|
||||
import sqlite
|
||||
import getopt
|
||||
|
||||
import conf
|
||||
import debug
|
||||
@ -376,18 +377,33 @@ class FunDB(callbacks.Privmsg):
|
||||
irc.reply(msg, reply)
|
||||
|
||||
def lart(self, irc, msg, args):
|
||||
"""<text> [for <reason>]
|
||||
"""[--id=<id>] <text> [for <reason>]
|
||||
|
||||
Uses a lart on <text> (giving the reason, if offered).
|
||||
Uses a lart on <text> (giving the reason, if offered). Will use lart
|
||||
number <id> from the database when <id> is given.
|
||||
"""
|
||||
nick = privmsgs.getArgs(args)
|
||||
(optlist, rest) = getopt.getopt(args, '', ['id='])
|
||||
try:
|
||||
(nick, reason) = map(' '.join,
|
||||
utils.itersplit('for'.__eq__, nick.split(), 1))
|
||||
utils.itersplit('for'.__eq__, rest, 1))
|
||||
except ValueError:
|
||||
nick = ' '.join(args)
|
||||
nick = ' '.join(rest)
|
||||
reason = ''
|
||||
cursor = self.db.cursor()
|
||||
for (option, argument) in optlist:
|
||||
if option == '--id':
|
||||
try:
|
||||
argument = int(argument)
|
||||
except ValueError:
|
||||
irc.error(msg, 'The <id> argument must be an integer.')
|
||||
return
|
||||
cursor.execute("""SELECT id, lart FROM larts WHERE id=%s""",
|
||||
argument)
|
||||
if cursor.rowcount == 0:
|
||||
irc.error(msg, 'There is no such lart.')
|
||||
return
|
||||
break
|
||||
else:
|
||||
cursor.execute("""SELECT id, lart FROM larts
|
||||
WHERE lart NOTNULL
|
||||
ORDER BY random()
|
||||
@ -408,18 +424,33 @@ class FunDB(callbacks.Privmsg):
|
||||
irc.reply(msg, s, action=True)
|
||||
|
||||
def praise(self, irc, msg, args):
|
||||
"""<text> [for <reason>]
|
||||
"""[--id=<id>] <text> [for <reason>]
|
||||
|
||||
Uses a praise on <text> (giving the reason, if offered).
|
||||
Uses a praise on <text> (giving the reason, if offered). Will use
|
||||
praise number <id> from the database when <id> is given.
|
||||
"""
|
||||
nick = privmsgs.getArgs(args)
|
||||
(optlist, rest) = getopt.getopt(args, '', ['id='])
|
||||
try:
|
||||
(nick, reason) = map(' '.join,
|
||||
utils.itersplit('for'.__eq__, nick.split(), 1))
|
||||
utils.itersplit('for'.__eq__, rest, 1))
|
||||
except ValueError:
|
||||
nick = ' '.join(args)
|
||||
nick = ' '.join(rest)
|
||||
reason = ''
|
||||
cursor = self.db.cursor()
|
||||
for (option, argument) in optlist:
|
||||
if option == '--id':
|
||||
try:
|
||||
argument = int(argument)
|
||||
except ValueError:
|
||||
irc.error(msg, 'The <id> argument must be an integer.')
|
||||
return
|
||||
cursor.execute("""SELECT id, praise FROM praises WHERE id=%s""",
|
||||
argument)
|
||||
if cursor.rowcount == 0:
|
||||
irc.error(msg, 'There is no such praise.')
|
||||
return
|
||||
break
|
||||
else:
|
||||
cursor.execute("""SELECT id, praise FROM praises
|
||||
WHERE praise NOTNULL
|
||||
ORDER BY random()
|
||||
|
@ -50,13 +50,22 @@ if sqlite is not None:
|
||||
|
||||
def testLart(self):
|
||||
self.assertNotError('dbadd lart jabs $who')
|
||||
self.assertResponse('lart jemfinch for being dumb', '\x01ACTION'\
|
||||
' jabs jemfinch for being dumb (#1)\x01')
|
||||
self.assertResponse('lart jemfinch', '\x01ACTION jabs jemfinch'\
|
||||
' (#1)\x01')
|
||||
self.assertResponse('lart jemfinch for being dumb',
|
||||
'\x01ACTION jabs jemfinch for being dumb (#1)\x01')
|
||||
self.assertResponse('lart jemfinch',
|
||||
'\x01ACTION jabs jemfinch (#1)\x01')
|
||||
self.assertNotError('dbnum lart')
|
||||
self.assertNotError('dbadd lart shoots $who')
|
||||
self.assertResponse('lart --id=1 jemfinch',
|
||||
'\x01ACTION jabs jemfinch (#1)\x01')
|
||||
self.assertResponse('lart --id=2 jemfinch for being dumb',
|
||||
'\x01ACTION shoots jemfinch for being dumb (#2)\x01')
|
||||
self.assertNotError('dbremove lart 1')
|
||||
self.assertNotError('dbnum lart')
|
||||
self.assertResponse('lart jemfinch',
|
||||
'\x01ACTION shoots jemfinch (#2)\x01')
|
||||
self.assertNotError('dbremove lart 2')
|
||||
self.assertNotError('dbnum lart')
|
||||
self.assertError('lart jemfinch')
|
||||
|
||||
def testExcuse(self):
|
||||
@ -78,14 +87,22 @@ if sqlite is not None:
|
||||
|
||||
def testPraise(self):
|
||||
self.assertNotError('dbadd praise pets $who')
|
||||
self.assertNotError('praise jemfinch')
|
||||
self.assertResponse('praise jemfinch for being him', '\x01ACTION'\
|
||||
' pets jemfinch for being him (#1)\x01')
|
||||
self.assertResponse('praise jemfinch', '\x01ACTION pets jemfinch'\
|
||||
' (#1)\x01')
|
||||
self.assertResponse('praise jemfinch for being him',
|
||||
'\x01ACTION pets jemfinch for being him (#1)\x01')
|
||||
self.assertResponse('praise jemfinch',
|
||||
'\x01ACTION pets jemfinch (#1)\x01')
|
||||
self.assertNotError('dbnum praise')
|
||||
self.assertNotError('dbadd praise gives $who a cookie')
|
||||
self.assertResponse('praise --id=1 jemfinch',
|
||||
'\x01ACTION pets jemfinch (#1)\x01')
|
||||
self.assertResponse('praise --id=2 jemfinch for being him',
|
||||
'\x01ACTION gives jemfinch a cookie for being him (#2)\x01')
|
||||
self.assertNotError('dbremove praise 1')
|
||||
self.assertNotError('dbnum praise')
|
||||
self.assertResponse('praise jemfinch',
|
||||
'\x01ACTION gives jemfinch a cookie (#2)\x01')
|
||||
self.assertNotError('dbremove praise 2')
|
||||
self.assertNotError('dbnum praise')
|
||||
self.assertError('praise jemfinch')
|
||||
|
||||
def testDbInfo(self):
|
||||
|
Loading…
Reference in New Issue
Block a user