基本上,我用Python制作了一个IRC Twitch机器人,目前除了加入频道外什么也不做。Ping-pong循环一段时间后会出现标题中的错误而停止工作。我做错了什么?谢谢。
import re
import socket
HOST = "irc.twitch.tv"
PORT = 6667
NICK = "asdsad"
PASS = "oauth:asdasdasdasd"
channel = "#coolperson"
def send_message(sock, msg):
sock.send("PRIVMSG #{} {}".format(channel, msg))
s = socket.socket()
s.connect((HOST, PORT))
s.send("PASS {}\r\n".format(PASS).encode("utf-8"))
s.send("NICK {}\r\n".format(NICK).encode("utf-8"))
s.send("JOIN {}\r\n".format(channel).encode("utf-8"))
while True:
response = s.recv(1024).decode("utf-8")
if response == "PING :tmi.twitch.tv\r\n":
s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
print("answered the call")