I’m writing a twitch bot in golang that joins one or more channels and replies to simple FAQ commands for each channel.
During development I’ve stumbled upon this weird issue where my bot would randomly disconnect with an EOF error after a few minutes, and I have realized that making it also join its own channel fixes it. (for example, if the bot was running on the account shigebot, making it join #shigebot plus the other channels it should operate on fixes the disconnections).
Increasing the ping rate makes the disconnection quicker. And yes, I am also replying to twitch PINGs.
This happens regardless of chat activity (still disconnects even if the chat is active the entire time).
It is not a huge issue for me because it can be easily solved as I just explained, but is this expected behaviour or am I doing something wrong?
No, this is not expected behaviour. Most likely there is something wrong in your code. Perhaps you handle being in your own channel differently than being in others.
If you can’t find it yourself, post relevant code here and maybe I or someone else here can help. By the way you only need to send a PONG when you’ve received a PING.
Automatically reconnecting is not a bad idea regardless of your issues, this would look something like:
if str, err = reader.ReadString('\n'); err != nil {
if err == io.EOF {
//reconnect
//rejoin previous channels
}
}
EDIT: I just noticed that the ircevent library already handles PING internally by replying with PONG :server , but the disconnection issue was there even before I added my own PING handler.
Thank you, I am currently testing for disconnects after disabling the pings for ircevent by using a huge ping delay. If it doesn’t work out i’ll just write a library based off yours.
For what it’s worth, I use go-ircevent in both a bot and a desktop client (with the built-in ping handling) and have not encountered the issue you mention. It would seem that there’s something else afoot in your code.
Well, seems like the issue is resolved after disabling the built-in ping. However, since Carl said the builtin ping causes no issues for him, it could have very well been twitch somehow mistaking my bot for a spambot and dropping the connection. Now that i think about it I had started experiencing these issues only after switching the bot to its own newly created twitch account instead of my own.
Thanks everyone for the help, the bot has been up for 12+ hours now with no disconnects and without joining its own channel.
It replies to PING with PONG :tmi.twitch.tv and PING :something with :tmi.twitch.tv PONG tmi.twitch.tv :something. It’s how I measure my connection latency to the chat servers, and not replying to them would break compatibility with some clients.