I’m developing my own bot using C++ and recently I encountered a weird problem with IRC. The bot works fine, reads messages and performs some simple commands. But after some time of bot inactivity (connection still remains opened) twitch IRC ignores first message of my bot. All other messages are being sent.
This is what happens step by step:
- I send command to chat in browser.
- Bot answers it.
- I leave my chat tab open but do some other things for a while.
- I send same command again.
- There is no answer from the bot.
- I check logs. Bot received message, proceded it and sent its response (or at least it seems so, I can’t check if it was actually sent to twitch but the code was executed).
- I send the command again.
- Now bot answers me.
This is how I send messages to IRC.
tosend = “PRIVMSG #” + this->channel + " :" + tosend + “\r\n\r\n”;
char *buffer = new char[512];
strcpy(buffer, tosend.c_str());
int *bytes = new int(0),
*total = new int(0),
*length = new int(strlen(buffer)-1);
while(*total < *length) {
*bytes = ::send(this->s, tosend.c_str(), tosend.length(), 0);
if(*bytes == -1) return false;
*total += *bytes;
}
delete bytes, total, length;
delete buffer;
P.S. The message is followed by double \r\n because single \r\n doesn’t seem to work for me.