Your special treatment of $cr and $lf looks motivated from my comments in the other thread about how these can be used as an exploit against someone doing "privmsg #channel string". But from looking at your source code it looks like you're replacing $cr and $lf with the 0x00 byte, effectively truncating the strings at the 1st position of either character. However, you may want to replace them with a space, for 2 reasons.
1 reason is to allow the user to see when someone tried to insert a payload. Another reason is that there can be innocent reasons for some fields to have $cr or $lf in them, though mostly this is in fields like 'comment' where someone just copypasted normal text from somewhere else