]> jfr.im git - erebus.git/blobdiff - modules/basic_socket.py
basic_socket - wrap incoming lines
[erebus.git] / modules / basic_socket.py
index 3d3b7e9ed1243a1935a3b52d1fa59bfde4c7e169..bfd6b72cd12ecca2cef85cb8cf3418d2b7adebc0 100644 (file)
@@ -33,9 +33,11 @@ modstop = lib.modstop
 # 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
 
@@ -63,7 +65,13 @@ class BasicServer(object):
 
        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")