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