Hello,
after a certain amount of time my bot keeps recieving ’ ’ from the twitch servers
After almost a month or so, me and my friend still don’t know how to fix this.
This is “probably” the problem why i get spaces:
con = socket.socket()
con.connect((HOST, PORT))
send_pass(PASS)
send_nick(NICK)
con.send(bytes(‘CAP REQ :twitch.tv/tags\r\n’, ‘UTF-8’))
join_channel(CHAN)
data = “”
while True:
try:
ready = select.select([con], [], [], 8)
if ready[0]:
data = data + con.recv(1024).decode(“UTF-8”)
print(data)
logging.basicConfig(filename=‘crash.log’, level = logging.DEBUG)
logging.info(data)
if len(data) != 0:
data_split = re.split(r"[~\r\n+]", data)
data = data_split.pop()
If you need anything else please say so
Just to clarify, this isn’t the PING/PONG messages that the server sends to keep the message alive?
i don’t think it’s the Ping but i might be wrong,
lately i doesn’t print Pong anymore
In case this is the problem
here is the ping/pong code:
if data == “PING :tmi.twitch.tv\r\n”:
con.send(“PONG :tmi.twitch.tv\r\n”.encode(“utf-8”))
print(“Pong send!”)
else:
sender = get_sender(line[1]).lower()
message = get_message(line[1:])
parse_message(message)
I have tried different Pong methodes with no success
I keep getting PING :tmi.twitch.tv
but it doesn’t print “Pong send!”
First off, you should parse the IRC message properly. It’ll save quite a bit of trouble doing it right the first time around.
The second thing is, you only need to identify it as a PING
, the trailing part (tmi.twitch.tv
) is irrelevant, you’ll just stick it in your PONG
reply.
Here’s a snippet from TwitchChatSharp (C#)
var ircMsg = IrcMessage.FromRawMessage(message);
MessageReceived(this, new IrcMessageEventArgs(ircMsg));
switch (ircMsg.Command)
{
case IrcCommand.Ping:
EnqueueMessage(message.Replace("PING", "PONG"), true);
break;
case IrcCommand.Reconnect:
Disconnect();
break;
}
As a side-note, please surround code with triple backticks and it’ll show up properly:
```
// code here
```
if data == "PING":
con.send("PONG")
print("Pong send!")
Is this what you mean?
More accurate would be
if data.startswith("PING"):
con.send("PONG")
print("Pong sent!")
But I’ve used something as dirty as checking if the first character in data is P, because in Twitch chat only PING messages start with P (others start with a colon :
or another letter)
Your code doesn’t seem to work
still getting only the ping but no Pong sent
Ok so i kinda know the problem now.
It doesn’t send a PONG because it can’t find the PING.
Any idea’s why?
Ok i fixed it
i had to make a schedule timer to pong every 5 min
system
Closed
September 2, 2016, 11:04am
11
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.