cleanInput

This commit is contained in:
blackbeard420 2020-01-06 16:26:46 -05:00
parent c208c2ff8f
commit f1a12eacee

13
irc.go
View File

@ -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())