Misc: Add supybot.plugins.Misc.mores.

This commit is contained in:
Valentin Lorentz 2013-04-10 17:26:55 +02:00
parent 61eb0fd3f8
commit 7a71ecb9f9
4 changed files with 26 additions and 8 deletions

View File

@ -41,6 +41,9 @@ def configure(advanced):
conf.registerPlugin('Misc', True)
Misc = conf.registerPlugin('Misc')
conf.registerChannelValue(Misc, 'mores',
registry.PositiveInteger(1, _("""Determines how many messages the bot
will issue when using the 'more' command.""")))
conf.registerGlobalValue(Misc, 'listPrivatePlugins',
registry.Boolean(True, _("""Determines whether the bot will list private
plugins with the list command if given the --private switch. If this is

View File

@ -346,14 +346,15 @@ class Misc(callbacks.Plugin):
return
try:
L = irc._mores[userHostmask]
chunk = L.pop()
number = self.registryValue('mores', msg.args[0])
chunks = [L.pop() for x in xrange(0, number)]
if L:
if len(L) < 2:
more = _('more message')
else:
more = _('more messages')
chunk += format(' \x02(%s)\x0F', more)
irc.reply(chunk, True)
chunks[-1] += format(' \x02(%s)\x0F', more)
irc.replies(chunks, noLengthCheck=True, oneToOne=False)
except KeyError:
irc.error(_('You haven\'t asked me a command; perhaps you want '
'to see someone else\'s more. To do so, call this '

View File

@ -211,6 +211,18 @@ class MiscTestCase(ChannelPluginTestCase):
self.assertRegexp('echo %s' % ('abc'*300), 'more')
self.assertRegexp('more', 'more')
self.assertNotRegexp('more', 'more')
with conf.supybot.plugins.Misc.mores.context(2):
self.assertRegexp('echo %s' % ('abc'*600), 'more')
self.assertNotRegexp('more', 'more')
m = self.irc.takeMsg()
self.assertIsNot(m, None)
self.assertIn('more', m.args[1])
self.assertNotRegexp('more', 'more')
m = self.irc.takeMsg()
self.assertIsNot(m, None)
self.assertNotIn('more', m.args[1])
def testInvalidCommand(self):
self.assertError('echo []')

View File

@ -465,7 +465,8 @@ class RichReplyMethods(object):
return self.reply(s, **kwargs)
def replies(self, L, prefixer=None, joiner=None,
onlyPrefixFirst=False, to=None, **kwargs):
onlyPrefixFirst=False, to=None,
oneToOne=None, **kwargs):
if prefixer is None:
prefixer = ''
if joiner is None:
@ -474,10 +475,11 @@ class RichReplyMethods(object):
prefixer = prefixer.__add__
if isinstance(joiner, basestring):
joiner = joiner.join
if ircutils.isChannel(to):
oneToOne = conf.get(conf.supybot.reply.oneToOne, to)
else:
oneToOne = conf.supybot.reply.oneToOne()
if oneToOne is None: # Can be True, False, or None
if ircutils.isChannel(to):
oneToOne = conf.get(conf.supybot.reply.oneToOne, to)
else:
oneToOne = conf.supybot.reply.oneToOne()
if oneToOne:
return self.reply(prefixer(joiner(L)), to=to, **kwargs)
else: