~ubuntu-branches/ubuntu/quantal/gozerbot/quantal

« back to all changes in this revision

Viewing changes to build/lib/gozerbot/plugs/rest.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2010-09-29 18:20:02 UTC
  • mfrom: (3.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100929182002-gi532gnem1vlu6jy
Tags: 0.9.1.3-5
Added python2.5 build dependency. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# gozerbot/plugs/rest.py
 
2
#
 
3
#
 
4
 
 
5
__author__ = "Wijnand 'tehmaze' Modderman - http://tehmaze.com"
 
6
__license__ = 'BSD'
 
7
 
 
8
# gozerbot imports
 
9
from gozerbot.commands import cmnds
 
10
from gozerbot.plughelp import plughelp
 
11
from gozerbot.examples import examples
 
12
from gozerbot.tests import tests
 
13
 
 
14
# basic imports
 
15
import time
 
16
 
 
17
plughelp.add('rest', 'show rest of the output in /msg')
 
18
 
 
19
def handle_rest(bot, ievent):
 
20
 
 
21
    """ show rest of the output in /msg. """
 
22
 
 
23
    try:
 
24
        who = ievent.args[0]
 
25
    except IndexError:
 
26
        if bot.jabber:
 
27
            who = ievent.userhost
 
28
        else:
 
29
            who = ievent.nick
 
30
 
 
31
    what, size = bot.less.more(who, 0)
 
32
 
 
33
    if not what:
 
34
        ievent.reply('no more data available for %s' % who)
 
35
        return
 
36
 
 
37
    if not bot.jabber and int(size)+1 > 10:
 
38
        ievent.reply("showing %d of %d lines in private" % \
 
39
(10, int(size)+1))
 
40
    else:
 
41
        ievent.reply("showing %d lines in private" % (int(size)+1))
 
42
 
 
43
    count = 0
 
44
 
 
45
    while what:
 
46
 
 
47
        count += 1
 
48
 
 
49
        if bot.jabber:
 
50
            if size:
 
51
                bot.say(ievent.userhost, "%s (+%s)" % (what, size))
 
52
            else:
 
53
                bot.say(ievent.userhost, what)
 
54
        else:
 
55
            if size:
 
56
                bot.output(ievent.nick, "%s (+%s)" % (what, size))
 
57
            else:
 
58
                bot.output(ievent.nick, what)
 
59
 
 
60
        # output limiter
 
61
        if count >= 10:
 
62
            what = None
 
63
        else:
 
64
            what, size = bot.less.more(who, 0)
 
65
            if what:
 
66
                time.sleep(3)
 
67
 
 
68
    # let the user know if we have remaining data
 
69
    if size:
 
70
        s = ''
 
71
        if size > 1:
 
72
            s = 's'
 
73
        if bot.jabber:
 
74
            bot.say(ievent.userhost, "%s more line%s" % (size, s)) 
 
75
        else:
 
76
            bot.output(ievent.nick, "%s more line%s" % (size, s))
 
77
 
 
78
cmnds.add('rest', handle_rest, 'USER')
 
79
examples.add('rest', 'show the rest of output cache data', 'rest')
 
80
tests.add('avail | rest')