[core] Handle host announce messages from jtv user
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
f3ad4a1332
commit
e2c6f99f29
1 changed files with 25 additions and 0 deletions
25
irc.go
25
irc.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -18,6 +19,8 @@ import (
|
||||||
var (
|
var (
|
||||||
rawMessageHandlers []plugins.RawMessageHandlerFunc
|
rawMessageHandlers []plugins.RawMessageHandlerFunc
|
||||||
rawMessageHandlersLock sync.Mutex
|
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 {
|
func notifyRawMessageHandlers(m *irc.Message) error {
|
||||||
|
@ -295,6 +298,28 @@ func (i ircHandler) handleTwitchPrivmsg(m *irc.Message) {
|
||||||
configLock.RUnlock()
|
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") {
|
if strings.HasPrefix(m.Trailing(), "!permit") {
|
||||||
i.handlePermit(m)
|
i.handlePermit(m)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue