[core] Handle host announce messages from jtv user

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-11-25 23:43:17 +01:00
parent f3ad4a1332
commit e2c6f99f29
Signed by: luzifer
GPG Key ID: 0066F03ED215AD7D

25
irc.go
View File

@ -3,6 +3,7 @@ package main
import (
"crypto/tls"
"fmt"
"regexp"
"strconv"
"strings"
"sync"
@ -18,6 +19,8 @@ import (
var (
rawMessageHandlers []plugins.RawMessageHandlerFunc
rawMessageHandlersLock sync.Mutex
hostNotificationRegex = regexp.MustCompile(`^(?P<actor>\w+) is now(?: auto)? hosting you(?: for(?: up to)? (?P<amount>[0-9]+) viewers)?.$`)
)
func notifyRawMessageHandlers(m *irc.Message) error {
@ -295,6 +298,28 @@ func (i ircHandler) handleTwitchPrivmsg(m *irc.Message) {
configLock.RUnlock()
}
// Handle the jtv host message for hosts
if m.User == "jtv" && hostNotificationRegex.MatchString(m.Trailing()) {
matches := hostNotificationRegex.FindStringSubmatch(m.Trailing())
if matches[2] == "" {
matches[2] = "0"
}
fields := plugins.FieldCollectionFromData(map[string]interface{}{
"from": matches[1],
"viewerCount": 0,
})
if v, err := strconv.Atoi(matches[2]); err == nil {
fields.Set("viewerCount", v)
}
log.WithFields(log.Fields(fields.Data())).Info("Incoming Host (jtv announce)")
go handleMessage(i.c, m, eventTypeHost, fields)
return
}
if strings.HasPrefix(m.Trailing(), "!permit") {
i.handlePermit(m)
return