gozerbot.less

maintain bot output cache.

class gozerbot.less.Less(nr)

Bases: object

output cache .. caches upto <nr> item of txt lines per nick.

add(nick, listoftxt)

add listoftxt to nick’s output .. set index for used by more commands.

get(nick, index1, index2)

return less entry.

entry is self.data[nick][index1][index2]

more(nick, index1)

return more entry pointed to by index .. increase index.

size(nick)

return sizes of cached output.

CODE

# gozerbot/less.py
#
#

""" maintain bot output cache. """

__status__ = "seen"

gozerbot imports

from utils.limlist import Limlist

Less class

class Less(object):

    """ output cache .. caches upto <nr> item of txt lines per nick. """

    def __init__(self, nr):
        self.data = {}
        self.index = {}
        self.nr = nr

    def add(self, nick, listoftxt):
        """
            add listoftxt to nick's output .. set index for used by more
            commands.

        """
        nick = nick.lower()
        if not self.data.has_key(nick): self.data[nick] = Limlist(self.nr)
        self.data[nick].insert(0, listoftxt)
        self.index[nick] = 1

    def get(self, nick, index1, index2):
        """
             return less entry.

             entry is self.data[nick][index1][index2]

        """
        nick = nick.lower()
        try: txt = self.data[nick][index1][index2]
        except (KeyError, IndexError): txt = None
        return txt

    def more(self, nick, index1):
        """ return more entry pointed to by index .. increase index. """
        nick = nick.lower()
        try: nr = self.index[nick]
        except KeyError: nr = 1
        try:
            txt = self.data[nick][index1][nr]
            size = len(self.data[nick][index1])-nr
            self.index[nick] = nr+1
        except (KeyError, IndexError): txt = None ; size = 0
        return (txt, size-1)

    def size(self, nick):
        """ return sizes of cached output. """
        nick = nick.lower()
        sizes = []
        if not self.data.has_key(nick): return sizes
        for i in self.data[nick]: sizes.append(len(i))
        return sizes

Table Of Contents

Previous topic

gozerbot.jsonusers

Next topic

gozerbot.monitor

This Page