Double Message issue

Been looking around and have not seen a similar issue that listed a resolution on it. This is also a learning project so some things might be messy.

My bot connects and runs well but occassionally it will get a double message and in doing so stomp out one of the messages.

What was in the chat:
User1: Hello!
User2: What is this?
User3: O no…

What the bot sees:
User1: Hello!
User1: Hello!
User3: O no…

Below is the code that should be getting this information:

def open_socket():
    s = socket.socket()
    s.connect((HOST, PORT))
    s.send(('PASS ' + PASS + '\r\n').encode())
    s.send(('NICK ' + BOT + '\r\n').encode())
    s.send(('JOIN #' + CHAN + '\r\n').encode())
    return s

s = open_socket()

    while True:
            response = s.recv(1024).decode()
        except UnicodeDecodeError:
        if response == 'PING\r\n':
                username ='\w+', response).group(0)
                message = CHAT_MSG.sub("", response)
            except AttributeError:
            print(str(ts()) + username + ': ' + message.strip())

Everything below this is custom coded stuff (commands and what not). Any insight or suggestions would be very much appreciated.

Python 2.7 if that helps

My python is rusty

But doesn’t this block of code say if a fault occurred in reading what User2 said.
print out what in is in the vars, username and message which is still set to what User1 said.

  • User1 read fine
  • Set message to the message and username to User1
  • print username/message
  • User2 READFAULT, have an exception/AttributeError (or a UnicodeDecodeError further up the stack),
  • print username/message (still set to user1 name and message)
  • User3 read fine set message to message and username to User3
  • print username/message

username/message having been made globals and not blanked when you try to read. Shouldn’t the pass be a return or something else?

1 Like

Actually, yes, yes it does. I was miss reading my own code on that ><.

Got a starting point now. Thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.