mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-12 05:02:32 +01:00
Added private and action keywords to IrcObjectProxy.reply and converted FunDB to use them.
This commit is contained in:
parent
0a2539c199
commit
3af8f1c790
@ -268,8 +268,8 @@ class FunDB(callbacks.Privmsg):
|
|||||||
sql = """SELECT id FROM %ss WHERE %s=%%s""" % (table, table)
|
sql = """SELECT id FROM %ss WHERE %s=%%s""" % (table, table)
|
||||||
cursor.execute(sql, s)
|
cursor.execute(sql, s)
|
||||||
id = cursor.fetchone()[0]
|
id = cursor.fetchone()[0]
|
||||||
response = [conf.replySuccess,'(%s #%s)' % (table,id)]
|
response = '%s (%s #%s)' % (conf.replySuccess, table, id)
|
||||||
irc.reply(msg, ' '.join(response))
|
irc.reply(msg, response)
|
||||||
|
|
||||||
def dbremove(self, irc, msg, args):
|
def dbremove(self, irc, msg, args):
|
||||||
"""<lart|excuse|insult|praise> <id>
|
"""<lart|excuse|insult|praise> <id>
|
||||||
@ -417,19 +417,17 @@ class FunDB(callbacks.Privmsg):
|
|||||||
irc.reply(msg, reply)
|
irc.reply(msg, reply)
|
||||||
|
|
||||||
def lart(self, irc, msg, args):
|
def lart(self, irc, msg, args):
|
||||||
"""[<channel>] <text>
|
"""<text> [for <reason>]
|
||||||
|
|
||||||
The <channel> argument is only necessary if the message isn't being
|
Uses a lart on <text> (giving the reason, if offered).
|
||||||
sent in the channel itself. Uses a lart on <text>.
|
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
|
||||||
nick = privmsgs.getArgs(args)
|
nick = privmsgs.getArgs(args)
|
||||||
try:
|
try:
|
||||||
(nick, reason) = map(' '.join,
|
(nick, reason) = map(' '.join,
|
||||||
utils.itersplit('for'.__eq__, nick.split(), 1))
|
utils.itersplit('for'.__eq__, nick.split(), 1))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
nick = ' '.join(args)
|
nick = ' '.join(args)
|
||||||
reason = ""
|
reason = ''
|
||||||
cursor = self.db.cursor()
|
cursor = self.db.cursor()
|
||||||
cursor.execute("""SELECT id, lart FROM larts
|
cursor.execute("""SELECT id, lart FROM larts
|
||||||
WHERE lart NOTNULL
|
WHERE lart NOTNULL
|
||||||
@ -445,26 +443,23 @@ class FunDB(callbacks.Privmsg):
|
|||||||
lartee = nick
|
lartee = nick
|
||||||
lart = lart.replace("$who", lartee)
|
lart = lart.replace("$who", lartee)
|
||||||
if len(reason) > 0:
|
if len(reason) > 0:
|
||||||
irc.queueMsg(ircmsgs.action(channel, '%s for %s (#%s)' %\
|
s = '%s for %s (#%s)' % (lart, reason, id)
|
||||||
(lart, reason, id)))
|
|
||||||
else:
|
else:
|
||||||
irc.queueMsg(ircmsgs.action(channel, '%s (#%s)' % (lart, id)))
|
s = '%s (#%s)' % (lart, id)
|
||||||
raise callbacks.CannotNest
|
irc.reply(msg, s, action=True)
|
||||||
|
|
||||||
def praise(self, irc, msg, args):
|
def praise(self, irc, msg, args):
|
||||||
"""[<channel>] <text>
|
"""<text> [for <reason>]
|
||||||
|
|
||||||
The <channel> argument is only necessary if the message isn't being
|
Uses a praise on <text> (giving the reason, if offered).
|
||||||
sent in the channel itself. Uses a praise on <text>.
|
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
|
||||||
nick = privmsgs.getArgs(args)
|
nick = privmsgs.getArgs(args)
|
||||||
try:
|
try:
|
||||||
(nick, reason) = map(' '.join,
|
(nick, reason) = map(' '.join,
|
||||||
utils.itersplit('for'.__eq__, nick.split(), 1))
|
utils.itersplit('for'.__eq__, nick.split(), 1))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
nick = ' '.join(args)
|
nick = ' '.join(args)
|
||||||
reason = ""
|
reason = ''
|
||||||
cursor = self.db.cursor()
|
cursor = self.db.cursor()
|
||||||
cursor.execute("""SELECT id, praise FROM praises
|
cursor.execute("""SELECT id, praise FROM praises
|
||||||
WHERE praise NOTNULL
|
WHERE praise NOTNULL
|
||||||
@ -474,17 +469,16 @@ class FunDB(callbacks.Privmsg):
|
|||||||
irc.error(msg, 'There are currently no available praises.')
|
irc.error(msg, 'There are currently no available praises.')
|
||||||
else:
|
else:
|
||||||
(id, praise) = cursor.fetchone()
|
(id, praise) = cursor.fetchone()
|
||||||
if nick == irc.nick or nick == 'me':
|
if nick == msg.nick or nick == 'me':
|
||||||
praisee = msg.nick
|
praisee = msg.nick
|
||||||
else:
|
else:
|
||||||
praisee = nick
|
praisee = nick
|
||||||
praise = praise.replace("$who", praisee)
|
praise = praise.replace("$who", praisee)
|
||||||
if len(reason) > 0:
|
if len(reason) > 0:
|
||||||
irc.queueMsg(ircmsgs.action(channel, '%s for %s (#%s)' %\
|
s = '%s for %s (#%s)' % (praise, reason, id)
|
||||||
(praise, reason, id)))
|
|
||||||
else:
|
else:
|
||||||
irc.queueMsg(ircmsgs.action(channel, '%s (#%s)' %(praise, id)))
|
s = '%s (#%s)' % (praise, id)
|
||||||
raise callbacks.CannotNest
|
irc.reply(msg, s, action=True)
|
||||||
|
|
||||||
def addword(self, irc, msg, args):
|
def addword(self, irc, msg, args):
|
||||||
"""<word>
|
"""<word>
|
||||||
|
@ -297,6 +297,8 @@ class IrcObjectProxy:
|
|||||||
self.args = args
|
self.args = args
|
||||||
self.counter = 0
|
self.counter = 0
|
||||||
self.finalEvaled = False
|
self.finalEvaled = False
|
||||||
|
self.action = False
|
||||||
|
self.private = False
|
||||||
self.prefixName = True
|
self.prefixName = True
|
||||||
self.noLengthCheck = False
|
self.noLengthCheck = False
|
||||||
world.commandsProcessed += 1
|
world.commandsProcessed += 1
|
||||||
@ -369,14 +371,22 @@ class IrcObjectProxy:
|
|||||||
debug.recoverableException()
|
debug.recoverableException()
|
||||||
self.error(self.msg, debug.exnToString(e))
|
self.error(self.msg, debug.exnToString(e))
|
||||||
|
|
||||||
def reply(self, msg, s, noLengthCheck=False, prefixName=True):
|
def reply(self, msg, s, noLengthCheck=False, prefixName=True,
|
||||||
self.noLengthCheck |= noLengthCheck
|
action=False, private=False):
|
||||||
|
# These use |= or &= based on whether or not they default to True or
|
||||||
|
# False. Those that default to True use &=; those that default to
|
||||||
|
# False use |=.
|
||||||
|
self.action |= action
|
||||||
|
self.private |= private
|
||||||
self.prefixName &= prefixName
|
self.prefixName &= prefixName
|
||||||
|
self.noLengthCheck |= noLengthCheck
|
||||||
if self.finalEvaled:
|
if self.finalEvaled:
|
||||||
if isinstance(self.irc, self.__class__):
|
if isinstance(self.irc, self.__class__):
|
||||||
self.irc.reply(msg, s, self.noLengthCheck, self.prefixName)
|
self.irc.reply(msg, s, self.noLengthCheck, self.prefixName)
|
||||||
elif self.noLengthCheck:
|
elif self.noLengthCheck:
|
||||||
self.irc.queueMsg(reply(msg, s, self.prefixName))
|
self.irc.queueMsg(reply(msg, s, self.prefixName))
|
||||||
|
elif self.action:
|
||||||
|
self.irc.queueMsg(ircmsgs.action(msg.args[0], s))
|
||||||
else:
|
else:
|
||||||
# The size of a PRIVMSG is:
|
# The size of a PRIVMSG is:
|
||||||
# 1 for the colon
|
# 1 for the colon
|
||||||
@ -404,8 +414,13 @@ class IrcObjectProxy:
|
|||||||
utils.nItems(len(msgs), 'message', 'more')
|
utils.nItems(len(msgs), 'message', 'more')
|
||||||
mask = msg.prefix.split('!', 1)[1]
|
mask = msg.prefix.split('!', 1)[1]
|
||||||
Privmsg._mores[mask] = msgs
|
Privmsg._mores[mask] = msgs
|
||||||
Privmsg._mores[msg.nick]=(ircutils.isChannel(msg.args[0]),msgs)
|
private = self.private or not ircutils.isChannel(msg.args[0])
|
||||||
self.irc.queueMsg(reply(msg, response, self.prefixName))
|
Privmsg._mores[msg.nick] = (private, msgs)
|
||||||
|
if self.private:
|
||||||
|
debug.printf('got here!')
|
||||||
|
self.irc.queueMsg(ircmsgs.privmsg(msg.nick, response))
|
||||||
|
else:
|
||||||
|
self.irc.queueMsg(reply(msg, response, self.prefixName))
|
||||||
else:
|
else:
|
||||||
self.args[self.counter] = s
|
self.args[self.counter] = s
|
||||||
self.evalArgs()
|
self.evalArgs()
|
||||||
|
@ -44,9 +44,9 @@ class TestFunDB(PluginTestCase, PluginDocumentation):
|
|||||||
|
|
||||||
def testLart(self):
|
def testLart(self):
|
||||||
self.assertNotError('dbadd lart jabs $who')
|
self.assertNotError('dbadd lart jabs $who')
|
||||||
self.assertResponse('lart #foo jemfinch for being dumb', '\x01ACTION'\
|
self.assertResponse('lart jemfinch for being dumb', '\x01ACTION'\
|
||||||
' jabs jemfinch for being dumb (#1)\x01')
|
' jabs jemfinch for being dumb (#1)\x01')
|
||||||
self.assertResponse('lart #foo jemfinch', '\x01ACTION jabs jemfinch'\
|
self.assertResponse('lart jemfinch', '\x01ACTION jabs jemfinch'\
|
||||||
' (#1)\x01')
|
' (#1)\x01')
|
||||||
self.assertNotError('dbnum lart')
|
self.assertNotError('dbnum lart')
|
||||||
self.assertNotError('dbremove lart 1')
|
self.assertNotError('dbremove lart 1')
|
||||||
@ -72,10 +72,10 @@ class TestFunDB(PluginTestCase, PluginDocumentation):
|
|||||||
|
|
||||||
def testPraise(self):
|
def testPraise(self):
|
||||||
self.assertNotError('dbadd praise pets $who')
|
self.assertNotError('dbadd praise pets $who')
|
||||||
self.assertNotError('praise #foo jemfinch')
|
self.assertNotError('praise jemfinch')
|
||||||
self.assertResponse('praise #foo jemfinch for being him', '\x01ACTION'\
|
self.assertResponse('praise jemfinch for being him', '\x01ACTION'\
|
||||||
' pets jemfinch for being him (#1)\x01')
|
' pets jemfinch for being him (#1)\x01')
|
||||||
self.assertResponse('praise #foo jemfinch', '\x01ACTION pets jemfinch'\
|
self.assertResponse('praise jemfinch', '\x01ACTION pets jemfinch'\
|
||||||
' (#1)\x01')
|
' (#1)\x01')
|
||||||
self.assertNotError('dbnum praise')
|
self.assertNotError('dbnum praise')
|
||||||
self.assertNotError('dbremove praise 1')
|
self.assertNotError('dbremove praise 1')
|
||||||
@ -107,7 +107,7 @@ class TestFunDB(PluginTestCase, PluginDocumentation):
|
|||||||
def testDbChange(self):
|
def testDbChange(self):
|
||||||
self.assertNotError('dbadd praise teaches $who perl')
|
self.assertNotError('dbadd praise teaches $who perl')
|
||||||
self.assertNotError('dbchange praise 1 s/perl/python/')
|
self.assertNotError('dbchange praise 1 s/perl/python/')
|
||||||
self.assertResponse('praise #foo jemfinch', '\x01ACTION teaches'\
|
self.assertResponse('praise jemfinch', '\x01ACTION teaches'\
|
||||||
' jemfinch python (#1)\x01')
|
' jemfinch python (#1)\x01')
|
||||||
self.assertNotError('dbremove praise 1')
|
self.assertNotError('dbremove praise 1')
|
||||||
|
|
||||||
|
@ -147,9 +147,18 @@ class FunctionsTestCase(unittest.TestCase):
|
|||||||
['foo', 'bar', 'baz'])
|
['foo', 'bar', 'baz'])
|
||||||
|
|
||||||
|
|
||||||
class PrivmsgTestCase(PluginTestCase):
|
class PrivmsgTestCase(ChannelPluginTestCase):
|
||||||
plugins = ('Utilities',)
|
plugins = ('Utilities', 'OwnerCommands')
|
||||||
|
conf.allowEval = True
|
||||||
def testEmptySquareBrackets(self):
|
def testEmptySquareBrackets(self):
|
||||||
self.assertResponse('echo []', '[]')
|
self.assertResponse('echo []', '[]')
|
||||||
|
|
||||||
|
def testSimpleReply(self):
|
||||||
|
self.assertResponse("eval irc.reply(msg, 'foo')", 'foo')
|
||||||
|
|
||||||
|
def testSimpleReplyAction(self):
|
||||||
|
self.assertResponse("eval irc.reply(msg, 'foo', action=True)",
|
||||||
|
'\x01ACTION foo\x01')
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
Loading…
Reference in New Issue
Block a user