diff --git a/irc.go b/irc.go index a674dfe..490b51b 100644 --- a/irc.go +++ b/irc.go @@ -26,6 +26,17 @@ type Connection struct { userList map[string][]string } +func cleanInput(msg string) string { + ret := msg + if strings.Contains(msg, "\n") { + ret = strings.ReplaceAll(msg, "\n", "-") + } + if strings.Contains(ret, "\r") { + ret = strings.ReplaceAll(msg, "\r", "") + } + return ret +} + //SendPong replies to the received PING func (c *Connection) SendPong(ping string) { pong := strings.Replace(ping, "PING", "PONG", 1) @@ -35,6 +46,7 @@ func (c *Connection) SendPong(ping string) { //SendPrivmsg sends a privmsg to channel/target func (c *Connection) SendPrivmsg(channel, msg string) { + msg = cleanInput(msg) _, err := c.Sock.Write([]byte(fmt.Sprintf("PRIVMSG %s :%s\n", channel, msg))) if err != nil { log.Printf("Error sending private message: %s\n", err.Error()) @@ -43,6 +55,7 @@ func (c *Connection) SendPrivmsg(channel, msg string) { //SendNotice sends a notice to channel/target func (c *Connection) SendNotice(channel, msg string) { + msg = cleanInput(msg) _, err := c.Sock.Write([]byte(fmt.Sprintf("NOTICE %s :%s\n", channel, msg))) if err != nil { log.Printf("Error sending NOTICE message: %s\n", err.Error())