twitch-bot/plugins/helpers.go
Knut Ahlers a91410d1ce
[core] Add username fields to events
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2021-10-16 14:44:11 +02:00

36 lines
634 B
Go

package plugins
import (
"fmt"
"strings"
"github.com/go-irc/irc"
)
func DeriveChannel(m *irc.Message, evtData FieldCollection) string {
if m != nil && len(m.Params) > 0 && strings.HasPrefix(m.Params[0], "#") {
return m.Params[0]
}
if s, err := evtData.String("channel"); err == nil {
return fmt.Sprintf("#%s", strings.TrimLeft(s, "#"))
}
return ""
}
func DeriveUser(m *irc.Message, evtData FieldCollection) string {
if m != nil && m.User != "" {
return m.User
}
if s, err := evtData.String("user"); err == nil {
return s
}
if s, err := evtData.String("username"); err == nil {
return s
}
return ""
}