From e01d52b2f2f9f0343bd13a4107d3e44852a71391 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Sat, 6 Sep 2003 21:51:21 +0000 Subject: [PATCH] Added less command. --- plugins/FunCommands.py | 25 ++++++++++++++++++++++++- test/test_FunCommands.py | 9 +++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/plugins/FunCommands.py b/plugins/FunCommands.py index 1e082e000..f0131351f 100644 --- a/plugins/FunCommands.py +++ b/plugins/FunCommands.py @@ -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): + """ + + Deals out 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): """ diff --git a/test/test_FunCommands.py b/test/test_FunCommands.py index 8bac0c0f0..bca080d42 100644 --- a/test/test_FunCommands.py +++ b/test/test_FunCommands.py @@ -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: