# XXX error handling? what happens when the other side closes the socket?
#
# You can interact with the rest of the bot through `lib.parent`.
+
@lib.bind_tcp('0.0.0.0', 12543)
class BasicServer(object):
def __init__(self, sock):
+ self.chan = lib.parent.cfg.get('basic_socket', 'channel', '#')
self.buffer = b''
self.sock = sock
def parse(self, line):
peer = self.sock.getpeername()
- lib.parent.randbot().msg('#', "%s:%d says: %s" % (peer[0], peer[1], line))
+ bot = lib.parent.randbot()
+ maxlen = bot.maxmsglen() - len("PRIVMSG :") - len(self.chan)
+ bot.msg(self.chan, "%s:%d says:" % peer)
+ while len(line) > maxlen:
+ bot.msg(self.chan, line[0:maxlen])
+ line = line[maxlen:]
+ bot.msg(self.chan, line)
def send(self, line):
self.socket.sendall(line.encode('utf-8', 'backslashreplace')+b"\r\n")