mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Changed --id=<id> to just <id> in praise and lart.
This commit is contained in:
parent
69c214785b
commit
a67748ec5f
@ -377,33 +377,35 @@ class FunDB(callbacks.Privmsg):
|
||||
irc.reply(msg, reply)
|
||||
|
||||
def lart(self, irc, msg, args):
|
||||
"""[--id=<id>] <text> [for <reason>]
|
||||
"""[<id>] <text> [for <reason>]
|
||||
|
||||
Uses a lart on <text> (giving the reason, if offered). Will use lart
|
||||
number <id> from the database when <id> is given.
|
||||
"""
|
||||
(optlist, rest) = getopt.getopt(args, '', ['id='])
|
||||
privmsgs.getArgs(rest)
|
||||
(id, nick) = privmsgs.getArgs(args, optional=1)
|
||||
try:
|
||||
id = int(id)
|
||||
if id < 1:
|
||||
irc.error(msg, 'There is no such lart.')
|
||||
return
|
||||
except ValueError:
|
||||
nick = ' '.join([id, nick]).strip()
|
||||
id = 0
|
||||
if not nick:
|
||||
raise callbacks.ArgumentError
|
||||
|
||||
try:
|
||||
(nick, reason) = map(' '.join,
|
||||
utils.itersplit('for'.__eq__, rest, 1))
|
||||
utils.itersplit('for'.__eq__, nick.split(), 1))
|
||||
except ValueError:
|
||||
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
|
||||
if id:
|
||||
cursor.execute("""SELECT id, lart FROM larts WHERE id=%s""", id)
|
||||
if cursor.rowcount == 0:
|
||||
irc.error(msg, 'There is no such lart.')
|
||||
return
|
||||
else:
|
||||
cursor.execute("""SELECT id, lart FROM larts
|
||||
WHERE lart NOTNULL
|
||||
@ -425,38 +427,41 @@ class FunDB(callbacks.Privmsg):
|
||||
irc.reply(msg, s, action=True)
|
||||
|
||||
def praise(self, irc, msg, args):
|
||||
"""[--id=<id>] <text> [for <reason>]
|
||||
"""[<id>] <text> [for <reason>]
|
||||
|
||||
Uses a praise on <text> (giving the reason, if offered). Will use
|
||||
praise number <id> from the database when <id> is given.
|
||||
"""
|
||||
(optlist, rest) = getopt.getopt(args, '', ['id='])
|
||||
privmsgs.getArgs(rest)
|
||||
(id, nick) = privmsgs.getArgs(args, optional=1)
|
||||
try:
|
||||
id = int(id)
|
||||
if id < 1:
|
||||
irc.error(msg, 'There is no such praise.')
|
||||
return
|
||||
except ValueError:
|
||||
nick = ' '.join([id, nick]).strip()
|
||||
id = 0
|
||||
if not nick:
|
||||
raise callbacks.ArgumentError
|
||||
|
||||
try:
|
||||
(nick, reason) = map(' '.join,
|
||||
utils.itersplit('for'.__eq__, rest, 1))
|
||||
utils.itersplit('for'.__eq__, nick.split(), 1))
|
||||
except ValueError:
|
||||
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
|
||||
if id:
|
||||
cursor.execute("""SELECT id, praise FROM praises WHERE id=%s""", id)
|
||||
if cursor.rowcount == 0:
|
||||
irc.error(msg, 'There is no such praise.')
|
||||
return
|
||||
else:
|
||||
cursor.execute("""SELECT id, praise FROM praises
|
||||
WHERE praise NOTNULL
|
||||
ORDER BY random()
|
||||
LIMIT 1""")
|
||||
|
||||
if cursor.rowcount == 0:
|
||||
irc.error(msg, 'There are currently no available praises.')
|
||||
else:
|
||||
|
@ -50,17 +50,17 @@ if sqlite is not None:
|
||||
|
||||
def testLart(self):
|
||||
self.assertNotError('dbadd lart jabs $who')
|
||||
self.assertRegexp('lart', '^lart [--id=<id>]')
|
||||
self.assertRegexp('lart', '^lart \[<id>\]')
|
||||
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.assertRegexp('lart --id=1', '^lart [--id=<id>]')
|
||||
self.assertResponse('lart --id=1 jemfinch',
|
||||
self.assertRegexp('lart 1', '^lart \[<id>\]')
|
||||
self.assertResponse('lart 1 jemfinch',
|
||||
'\x01ACTION jabs jemfinch (#1)\x01')
|
||||
self.assertResponse('lart --id=2 jemfinch for being dumb',
|
||||
self.assertResponse('lart 2 jemfinch for being dumb',
|
||||
'\x01ACTION shoots jemfinch for being dumb (#2)\x01')
|
||||
self.assertNotError('dbremove lart 1')
|
||||
self.assertNotError('dbnum lart')
|
||||
@ -89,17 +89,17 @@ if sqlite is not None:
|
||||
|
||||
def testPraise(self):
|
||||
self.assertNotError('dbadd praise pets $who')
|
||||
self.assertRegexp('praise', '^praise [--id=<id>]')
|
||||
self.assertRegexp('praise', '^praise \[<id>\]')
|
||||
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.assertRegexp('praise --id=1', '^praise [--id=<id>]')
|
||||
self.assertResponse('praise --id=1 jemfinch',
|
||||
self.assertRegexp('praise 1', '^praise \[<id>\]')
|
||||
self.assertResponse('praise 1 jemfinch',
|
||||
'\x01ACTION pets jemfinch (#1)\x01')
|
||||
self.assertResponse('praise --id=2 jemfinch for being him',
|
||||
self.assertResponse('praise 2 jemfinch for being him',
|
||||
'\x01ACTION gives jemfinch a cookie for being him (#2)\x01')
|
||||
self.assertNotError('dbremove praise 1')
|
||||
self.assertNotError('dbnum praise')
|
||||
|
Loading…
Reference in New Issue
Block a user