X-Git-Url: https://jfr.im/git/erebus.git/blobdiff_plain/aaa8eb8dc2f1e1237d44344488ec4cde9c0b0076..52c80cff91dce5fa14ae903c6c2bf20533ccca46:/modules/sockets.py diff --git a/modules/sockets.py b/modules/sockets.py index 0e96e04..f9577e1 100644 --- a/modules/sockets.py +++ b/modules/sockets.py @@ -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:] +[udp|tcp:][:] + + +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: # '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)