Add method to get message without formatting

This commit is contained in:
Iceflower 2018-06-26 08:48:51 +02:00
parent 5063e5f260
commit e975eae5ba
No known key found for this signature in database
GPG Key ID: 50C8E6502C63EB17

View File

@ -8,6 +8,7 @@ import (
"crypto/tls" "crypto/tls"
"log" "log"
"net" "net"
"regexp"
"sync" "sync"
"time" "time"
) )
@ -80,3 +81,17 @@ func (e *Event) Message() string {
} }
return e.Arguments[len(e.Arguments)-1] return e.Arguments[len(e.Arguments)-1]
} }
// https://stackoverflow.com/a/10567935/6754440
// Regex of IRC formatting.
var ircFormat = regexp.MustCompile(`[\x02\x1F\x0F\x16\x1D]|\x03(\d\d?(,\d\d?)?)?`)
// Retrieve the last message from Event arguments, but without IRC formatting (color.
// This function leaves the arguments untouched and
// returns an empty string if there are none.
func (e *Event) MessageWithoutFormat() string {
if len(e.Arguments) == 0 {
return ""
}
return ircFormat.ReplaceAllString(e.Arguments[len(e.Arguments)-1], "")
}