Handle common CTCP messages

This commit is contained in:
Ken-Håvard Lieng
2020-05-20 04:19:40 +02:00
parent 4816fbfbca
commit 973578bb49
7 changed files with 105 additions and 39 deletions

View File

@@ -19,32 +19,8 @@ func (m *Message) LastParam() string {
return ""
}
type CTCP struct {
Command string
Params string
}
func (m *Message) ToCTCP() *CTCP {
lp := m.LastParam()
if len(lp) > 1 && lp[0] == 0x01 {
parts := strings.SplitN(strings.Trim(lp, "\x01"), " ", 2)
ctcp := CTCP{}
if parts[0] != "" {
ctcp.Command = parts[0]
} else {
return nil
}
if len(parts) == 2 {
ctcp.Params = parts[1]
}
return &ctcp
}
return nil
return DecodeCTCP(m.LastParam())
}
func ParseMessage(line string) *Message {