Added private and action keywords to IrcObjectProxy.reply and converted FunDB to use them.

This commit is contained in:
Jeremy Fincher 2003-09-18 07:26:21 +00:00
parent 0a2539c199
commit 3af8f1c790
4 changed files with 51 additions and 33 deletions

View File

@ -268,8 +268,8 @@ class FunDB(callbacks.Privmsg):
sql = """SELECT id FROM %ss WHERE %s=%%s""" % (table, table)
cursor.execute(sql, s)
id = cursor.fetchone()[0]
response = [conf.replySuccess,'(%s #%s)' % (table,id)]
irc.reply(msg, ' '.join(response))
response = '%s (%s #%s)' % (conf.replySuccess, table, id)
irc.reply(msg, response)
def dbremove(self, irc, msg, args):
"""<lart|excuse|insult|praise> <id>
@ -417,19 +417,17 @@ class FunDB(callbacks.Privmsg):
irc.reply(msg, reply)
def lart(self, irc, msg, args):
"""[<channel>] <text>
"""<text> [for <reason>]
The <channel> argument is only necessary if the message isn't being
sent in the channel itself. Uses a lart on <text>.
Uses a lart on <text> (giving the reason, if offered).
"""
channel = privmsgs.getChannel(msg, args)
nick = privmsgs.getArgs(args)
try:
(nick, reason) = map(' '.join,
utils.itersplit('for'.__eq__, nick.split(), 1))
except ValueError:
nick = ' '.join(args)
reason = ""
reason = ''
cursor = self.db.cursor()
cursor.execute("""SELECT id, lart FROM larts
WHERE lart NOTNULL
@ -445,26 +443,23 @@ class FunDB(callbacks.Privmsg):
lartee = nick
lart = lart.replace("$who", lartee)
if len(reason) > 0:
irc.queueMsg(ircmsgs.action(channel, '%s for %s (#%s)' %\
(lart, reason, id)))
s = '%s for %s (#%s)' % (lart, reason, id)
else:
irc.queueMsg(ircmsgs.action(channel, '%s (#%s)' % (lart, id)))
raise callbacks.CannotNest
s = '%s (#%s)' % (lart, id)
irc.reply(msg, s, action=True)
def praise(self, irc, msg, args):
"""[<channel>] <text>
"""<text> [for <reason>]
The <channel> argument is only necessary if the message isn't being
sent in the channel itself. Uses a praise on <text>.
Uses a praise on <text> (giving the reason, if offered).
"""
channel = privmsgs.getChannel(msg, args)
nick = privmsgs.getArgs(args)
try:
(nick, reason) = map(' '.join,
utils.itersplit('for'.__eq__, nick.split(), 1))
except ValueError:
nick = ' '.join(args)
reason = ""
reason = ''
cursor = self.db.cursor()
cursor.execute("""SELECT id, praise FROM praises
WHERE praise NOTNULL
@ -474,17 +469,16 @@ class FunDB(callbacks.Privmsg):
irc.error(msg, 'There are currently no available praises.')
else:
(id, praise) = cursor.fetchone()
if nick == irc.nick or nick == 'me':
if nick == msg.nick or nick == 'me':
praisee = msg.nick
else:
praisee = nick
praise = praise.replace("$who", praisee)
if len(reason) > 0:
irc.queueMsg(ircmsgs.action(channel, '%s for %s (#%s)' %\
(praise, reason, id)))
s = '%s for %s (#%s)' % (praise, reason, id)
else:
irc.queueMsg(ircmsgs.action(channel, '%s (#%s)' %(praise, id)))
raise callbacks.CannotNest
s = '%s (#%s)' % (praise, id)
irc.reply(msg, s, action=True)
def addword(self, irc, msg, args):
"""<word>

View File

@ -297,6 +297,8 @@ class IrcObjectProxy:
self.args = args
self.counter = 0
self.finalEvaled = False
self.action = False
self.private = False
self.prefixName = True
self.noLengthCheck = False
world.commandsProcessed += 1
@ -369,14 +371,22 @@ class IrcObjectProxy:
debug.recoverableException()
self.error(self.msg, debug.exnToString(e))
def reply(self, msg, s, noLengthCheck=False, prefixName=True):
self.noLengthCheck |= noLengthCheck
def reply(self, msg, s, noLengthCheck=False, prefixName=True,
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.noLengthCheck |= noLengthCheck
if self.finalEvaled:
if isinstance(self.irc, self.__class__):
self.irc.reply(msg, s, self.noLengthCheck, self.prefixName)
elif self.noLengthCheck:
self.irc.queueMsg(reply(msg, s, self.prefixName))
elif self.action:
self.irc.queueMsg(ircmsgs.action(msg.args[0], s))
else:
# The size of a PRIVMSG is:
# 1 for the colon
@ -404,8 +414,13 @@ class IrcObjectProxy:
utils.nItems(len(msgs), 'message', 'more')
mask = msg.prefix.split('!', 1)[1]
Privmsg._mores[mask] = msgs
Privmsg._mores[msg.nick]=(ircutils.isChannel(msg.args[0]),msgs)
self.irc.queueMsg(reply(msg, response, self.prefixName))
private = self.private or not ircutils.isChannel(msg.args[0])
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:
self.args[self.counter] = s
self.evalArgs()

View File

@ -44,9 +44,9 @@ class TestFunDB(PluginTestCase, PluginDocumentation):
def testLart(self):
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')
self.assertResponse('lart #foo jemfinch', '\x01ACTION jabs jemfinch'\
self.assertResponse('lart jemfinch', '\x01ACTION jabs jemfinch'\
' (#1)\x01')
self.assertNotError('dbnum lart')
self.assertNotError('dbremove lart 1')
@ -72,10 +72,10 @@ class TestFunDB(PluginTestCase, PluginDocumentation):
def testPraise(self):
self.assertNotError('dbadd praise pets $who')
self.assertNotError('praise #foo jemfinch')
self.assertResponse('praise #foo jemfinch for being him', '\x01ACTION'\
self.assertNotError('praise jemfinch')
self.assertResponse('praise jemfinch for being him', '\x01ACTION'\
' pets jemfinch for being him (#1)\x01')
self.assertResponse('praise #foo jemfinch', '\x01ACTION pets jemfinch'\
self.assertResponse('praise jemfinch', '\x01ACTION pets jemfinch'\
' (#1)\x01')
self.assertNotError('dbnum praise')
self.assertNotError('dbremove praise 1')
@ -107,7 +107,7 @@ class TestFunDB(PluginTestCase, PluginDocumentation):
def testDbChange(self):
self.assertNotError('dbadd praise teaches $who perl')
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')
self.assertNotError('dbremove praise 1')

View File

@ -147,9 +147,18 @@ class FunctionsTestCase(unittest.TestCase):
['foo', 'bar', 'baz'])
class PrivmsgTestCase(PluginTestCase):
plugins = ('Utilities',)
class PrivmsgTestCase(ChannelPluginTestCase):
plugins = ('Utilities', 'OwnerCommands')
conf.allowEval = True
def testEmptySquareBrackets(self):
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: