Here is essentially what my code is, besides connection variables
sock = socket.socket()
sock.connect((server, port))
sock.send(f"PASS {token}\r\n".encode('utf-8'))
sock.send(f"NICK {nickname}\r\n".encode('utf-8'))
sock.send(f"JOIN {channel}\r\n".encode('utf-8'))
while True:
resp = sock.recv(2048).decode('utf-8', 'ignore')
if resp.startswith('PING'):
sock.send("PONG\r\n".encode('utf-8'))
print('PINGPONG')
messageList = resp.splitlines()
time.sleep(rate + 1)
if not resp.startswith(':tmi.twitch.tv') and not resp.startswith(':streamelements') and not resp.startswith(':fossabot'):
if resp == "":
print('---------------EMPTY STRING---------------')
for chatMessage in messageList:
if chatMessage.find(' :') != -1 and chatMessage.find('!') != -1 and chatMessage.find('@') != -1:
userWithThing = chatMessage.split('!')[0]
user = userWithThing[1:]
message = chatMessage.split(' :')[1]
formattedChannel = channel[1:]
print('User: ' + user + ' Message: ' + message)
Am I handling the Pings correctly? I do see instances where “PINGPONG” gets printed to console, but they happen pretty irregularly.