Added less command.

This commit is contained in:
Jeremy Fincher 2003-09-06 21:51:21 +00:00
parent c662da1621
commit e01d52b2f2
2 changed files with 33 additions and 1 deletions

View File

@ -53,6 +53,7 @@ import string
import random
import urllib
import inspect
import textwrap
import telnetlib
import threading
import mimetypes
@ -659,7 +660,7 @@ class FunCommands(callbacks.Privmsg):
elif option == 'regexp':
try:
r = utils.perlReToPythonRe(arg)
except ValueError:
except ValueError, e:
irc.error(msg, str(e))
return
predicates.append(lambda m: r.search(m.args[1]))
@ -790,6 +791,28 @@ class FunCommands(callbacks.Privmsg):
"""
irc.reply(msg, random.sample(self._these, 1)[0])
_lesses = {}
def less(self, irc, msg, args):
"""<text>
Deals out <text> in small, IrcMsg-sized pieces. Mostly useful for
piecing-out nested commands.
"""
text = privmsgs.getArgs(args, needed=0, optional=1)
userHostmask = msg.prefix.split('!', 1)[1]
if text:
lines = textwrap.wrap(text, 400)
lines.reverse()
s = lines.pop()
self._lesses[userHostmask] = lines
irc.reply(msg, s)
else:
try:
s = self._lesses[userHostmask].pop()
irc.reply(msg, s)
except (KeyError, IndexError): # Nothing in the list or dict.
irc.error(msg, 'I have no less history for you.')
def dns(self, irc, msg, args):
"""<host|ip>

View File

@ -110,6 +110,15 @@ class FunCommandsTest(PluginTestCase, PluginDocumentation):
self.assertResponse('rpn 1 dup', 'Stack: [1, 1]')
self.assertResponse('rpn 2 3 4 + -', str(2-7))
def testLess(self):
s390 = ' '.join(['123456789']*39)
s790 = ' '.join(['123456789']*79)
self.assertNotError('less %s' % s390)
self.assertError('less')
self.assertNotError('less %s' % s790)
self.assertNotError('less')
self.assertError('less')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: