mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Added optional <id> argument to FunDB's excuse
This commit is contained in:
parent
f7caf3f4fd
commit
5c1fc0114d
@ -182,15 +182,29 @@ class FunDB(callbacks.Privmsg):
|
|||||||
irc.reply(msg, ', '.join(words))
|
irc.reply(msg, ', '.join(words))
|
||||||
|
|
||||||
def excuse(self, irc, msg, args):
|
def excuse(self, irc, msg, args):
|
||||||
"""takes no arguments
|
"""[<id>]
|
||||||
|
|
||||||
Gives you a standard BOFH excuse.
|
Gives you a standard, random BOFH excuse or the excuse with the given
|
||||||
|
<id>.
|
||||||
"""
|
"""
|
||||||
|
id = privmsgs.getArgs(args, needed=0, optional=1)
|
||||||
cursor = self.db.cursor()
|
cursor = self.db.cursor()
|
||||||
cursor.execute("""SELECT id, excuse FROM excuses
|
if id:
|
||||||
WHERE excuse NOTNULL
|
try:
|
||||||
ORDER BY random()
|
id = int(id)
|
||||||
LIMIT 1""")
|
except ValueError:
|
||||||
|
irc.error(msg, 'The <id> argument must be an integer.')
|
||||||
|
return
|
||||||
|
cursor.execute("""SELECT id, excuse FROM excuses WHERE id=%s""",
|
||||||
|
id)
|
||||||
|
if cursor.rowcount == 0:
|
||||||
|
irc.error(msg, 'There is no such excuse.')
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
cursor.execute("""SELECT id, excuse FROM excuses
|
||||||
|
WHERE excuse NOTNULL
|
||||||
|
ORDER BY random()
|
||||||
|
LIMIT 1""")
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.error(msg, 'There are currently no available excuses.')
|
irc.error(msg, 'There are currently no available excuses.')
|
||||||
else:
|
else:
|
||||||
|
@ -72,11 +72,16 @@ if sqlite is not None:
|
|||||||
|
|
||||||
def testExcuse(self):
|
def testExcuse(self):
|
||||||
self.assertNotError('dbadd excuse Power failure')
|
self.assertNotError('dbadd excuse Power failure')
|
||||||
self.assertNotError('excuse')
|
self.assertResponse('excuse', 'Power failure (#1)')
|
||||||
self.assertNotError('excuse a few random words')
|
self.assertError('excuse a few random words')
|
||||||
self.assertNotError('dbnum excuse')
|
self.assertNotError('dbnum excuse')
|
||||||
|
self.assertNotError('dbadd excuse /pub/lunch')
|
||||||
|
self.assertResponse('excuse 1', 'Power failure (#1)')
|
||||||
self.assertNotError('dbremove excuse 1')
|
self.assertNotError('dbremove excuse 1')
|
||||||
self.assertNotError('dbnum excuse')
|
self.assertNotError('dbnum excuse')
|
||||||
|
self.assertResponse('excuse', '/pub/lunch (#2)')
|
||||||
|
self.assertNotError('dbremove excuse 2')
|
||||||
|
self.assertNotError('dbnum excuse')
|
||||||
self.assertError('excuse')
|
self.assertError('excuse')
|
||||||
|
|
||||||
def testInsult(self):
|
def testInsult(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user