]> jfr.im git - erebus.git/blobdiff - modules/sockets.py
update comments
[erebus.git] / modules / sockets.py
index 0e96e0455889335d7a14dedac84a7c8866ebf95b..f9577e18fbbee6eb70f0941d86720624bd6237ca 100644 (file)
@@ -1,9 +1,34 @@
 # Erebus IRC bot - Author: Erebus Team
 # vim: fileencoding=utf-8
+# Configurable sockets module. DO NOT USE without understanding the risks
 # This file is released into the public domain; see http://unlicense.org/
 
 # Note: this module doesn't do any kind of authentication, so anyone who can connect to the bound port can spam you.
 
+"""
+To use - add in bot.config something like:
+
+[sockets]
+127.0.0.1:1337 = #example
+
+The left side is the address to listen on and the right side is the channel to send to.
+The exmaple will send incoming lines/packets on localhost, port 1337 to channel #example
+
+The full syntax for the address is:
+[unix:]</path/to/socket>
+[udp|tcp:][<ip>:]<port>
+
+
+Address examples:
+
+Unix domain socket:          /path
+Unix domain socket:          unix:/path
+TCP socket (all interfaces): 1337
+TCP socket (one interface):  127.0.0.1:1337
+UDP socket (all interfaces): udp:1337
+UDP socket (one interface):  udp:127.0.0.1:1337
+"""
+
 # module info
 modinfo = {
        'author': 'Erebus Team',
@@ -28,9 +53,9 @@ def gotParent(parent):
                @lib.bind(bindto, data=channel)
                class BasicServer(object):
                        def __init__(self, sock, data):
-                               # The lambda bit is needed to make this copy the value-at-definition instead of using the closure value-at-runtime
+                               # NB neither directly referencing `channel`, nor trying to pass it through a default-arg-to-a-lambda like the python docs suggest, works here.
+                               # Yay python. At least passing it via bind works.
                                self.chan = data
-                               print(repr(self.chan))
                                self.buffer = b''
                                self.sock = sock
 
@@ -57,7 +82,10 @@ def gotParent(parent):
                                return lines
 
                        def parse(self, line):
-                               bot = lib.parent.randbot()
+                               try:
+                                       bot = lib.parent.channel(self.chan).bot
+                               except AttributeError: # <class 'AttributeError'> 'NoneType' object has no attribute 'bot'
+                                       bot = lib.parent.randbot()
                                maxlen = bot.maxmsglen() - len("PRIVMSG  :") - len(self.chan)
                                while len(line) > maxlen:
                                        cutat = line.rfind(' ', 0, maxlen)