client = None class Buffer: viewsize = 8 def __init__(self): self.buf = [] self.curline = 0 self.edit = False bufs = {} def mod_init(cl): global client client = cl def getnick(user): return user.split('!')[0] def getwindow(buf): bi = buf.curline - (buf.viewsize-1)/2 bs = buf.curline + buf.viewsize/2 + 1 if bs > len(buf.buf): bi = bi - (bs - len(buf.buf)) bs = len(buf.buf) if bi < 0: bi = 0 return range(bi, bs) def on_privchat(who, msg): nick = getnick(who) if nick not in bufs: bufs[nick] = Buffer() b = bufs[nick] if msg[0] == '.': args = msg[1:].split() cmd = args[0] if cmd == "l": if len(args) > 1: b.curline = int(args[1]) if b.curline > len(b.buf): b.curline = len(b.buf) if b.curline < 0: b.curline = 0 for i in getwindow(b): if i == b.curline: client.sendto(nick, '----') client.sendto(nick, '%3d: '%i + b.buf[i]) if b.curline == len(b.buf): client.sendto(nick, '----') if cmd == "e": if b.edit is True: b.edit = False else: b.edit = True if cmd == "d": if len(args) < 2: return if len(args) > 2: for i in range(int(args[1]), int(args[2])+1): b.buf.pop(int(args[1])) else: b.buf.pop(int(args[1])) else: if b.edit is True: b.buf.insert(b.curline, msg) b.curline = b.curline + 1