diff -uNr a/bot.py b/bot.py --- a/bot.py 2019-10-08 16:57:09.000000000 -0400 +++ b/bot.py 2021-06-16 13:45:30.519940513 -0400 @@ -244,6 +244,17 @@ eat_logline(user, chan, text, action) +joined = False +def join_chans(): + global joined + # Join selected channels + if joined: + return + for chan in Channels: + logging.info("Joining channel '%s'..." % chan) + send("JOIN #%s\r\n" % chan) + joined = True + # IRCate until we get disconnected def irc(): global connected @@ -262,24 +273,24 @@ time_last_conn = datetime.now() # Auth to server - send("NICK %s\r\n" % Nick) - send("USER %s %s %s :%s\r\n" % (Nick, Nick, Nick, Nick)) - # If this is a production bot, rather than test, there will be a PW: if Pass != "": - send("NICKSERV IDENTIFY %s %s\r\n" % (Nick, Pass)) + send("PASS %s\r\n" % Pass) + + send("NICK %s\r\n" % Nick) + send("USER %s 0 * :%s\r\n\r\n" % (Nick, Nick)) time.sleep(Join_Delay) # wait to join until fleanode eats auth - # Join selected channels - for chan in Channels: - logging.info("Joining channel '%s'..." % chan) - send("JOIN #%s\r\n" % chan) - + lnrec = 0 while connected: try: data = sock.recv(Buf_Size) time_last_recv = datetime.now() # Received anything -- reset timer + lnrec = lnrec + 1 + if lnrec > 2: + join_chans() + except socket.timeout as e: logging.debug("Receive timed out") # Determine whether the connection has timed out: @@ -303,6 +314,7 @@ deinit_socket() continue try: + try: data = data.strip(b'\r\n').decode("utf-8") except UnicodeDecodeError: