From e2c6f99f293710633a7497392707e10d949c3091 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Thu, 25 Nov 2021 23:43:17 +0100 Subject: [PATCH] [core] Handle host announce messages from jtv user Signed-off-by: Knut Ahlers --- irc.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/irc.go b/irc.go index 64fd700..fcada84 100644 --- a/irc.go +++ b/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\w+) is now(?: auto)? hosting you(?: for(?: up to)? (?P[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