mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 08:40:01 +00:00
[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 (
|
||||
"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
|
||||
|
|
Loading…
Reference in a new issue