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()
join_room(s)
try:
while True:
try:
response = s.recv(1024).decode()
except UnicodeDecodeError:
pass
if response == 'PING :tmi.twitch.tv\r\n':
s.send('PONG :tmi.twitch.tv\r\n'.encode())
else:
try:
username = re.search(r'\w+', response).group(0)
message = CHAT_MSG.sub("", response)
except AttributeError:
pass
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