mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add title and game to stream live announcement
This commit is contained in:
parent
24cdb70f0b
commit
a0bd453132
|
@ -133,6 +133,7 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
|
||||||
reply = app.createOfflineSubscription(target, cmdParams[2])
|
reply = app.createOfflineSubscription(target, cmdParams[2])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case "unnotify":
|
case "unnotify":
|
||||||
switch cmdParams[1] {
|
switch cmdParams[1] {
|
||||||
case "live":
|
case "live":
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
"github.com/lyx0/nourybot/internal/common"
|
"github.com/lyx0/nourybot/internal/common"
|
||||||
"github.com/lyx0/nourybot/internal/data"
|
"github.com/lyx0/nourybot/internal/data"
|
||||||
|
"github.com/lyx0/nourybot/pkg/ivr"
|
||||||
"github.com/nicklaw5/helix/v2"
|
"github.com/nicklaw5/helix/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -75,15 +76,19 @@ func (app *application) eventsubFollow(w http.ResponseWriter, r *http.Request, _
|
||||||
log.Printf("got stream online event webhook: %s is live\n", liveEvent.BroadcasterUserName)
|
log.Printf("got stream online event webhook: %s is live\n", liveEvent.BroadcasterUserName)
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
w.Write([]byte("ok"))
|
w.Write([]byte("ok"))
|
||||||
app.SendNoContext("nouryxd", fmt.Sprintf("%s went live FeelsGoodMan", liveEvent.BroadcasterUserName))
|
|
||||||
|
game := ivr.GameByUsername(liveEvent.BroadcasterUserLogin)
|
||||||
|
title := ivr.TitleByUsername(liveEvent.BroadcasterUserLogin)
|
||||||
|
|
||||||
|
app.SendNoBanphrase("nouryxd", fmt.Sprintf("%s went live FeelsGoodMan Game: %s; Title: %s; https://twitch.tv/%s", liveEvent.BroadcasterUserName, game, title, liveEvent.BroadcasterUserLogin))
|
||||||
|
|
||||||
case helix.EventSubTypeStreamOffline:
|
case helix.EventSubTypeStreamOffline:
|
||||||
var offlineEvent helix.EventSubStreamOfflineEvent
|
var offlineEvent helix.EventSubStreamOfflineEvent
|
||||||
err = json.NewDecoder(bytes.NewReader(vals.Event)).Decode(&offlineEvent)
|
err = json.NewDecoder(bytes.NewReader(vals.Event)).Decode(&offlineEvent)
|
||||||
log.Printf("got stream online event webhook: %s is live\n", offlineEvent.BroadcasterUserName)
|
log.Printf("got stream offline event webhook: %s is now offline\n", offlineEvent.BroadcasterUserName)
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
w.Write([]byte("ok"))
|
w.Write([]byte("ok"))
|
||||||
app.SendNoContext("nouryxd", fmt.Sprintf("%s went offline FeelsBadMan", offlineEvent.BroadcasterUserName))
|
app.SendNoBanphrase("nouryxd", fmt.Sprintf("%s went offline FeelsBadMan", offlineEvent.BroadcasterUserName))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,56 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ivrIDByUsernameResponse struct {
|
type ivrResponse struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
Stream ivrStream `json:"stream"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ivrStream struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Game ivrGame `json:"game"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ivrGame struct {
|
||||||
|
DisplayName string `json:"displayName"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func TitleByUsername(login string) string {
|
||||||
|
baseUrl := "https://api.ivr.fi/v2/twitch/user?login="
|
||||||
|
|
||||||
|
resp, err := http.Get(fmt.Sprintf("%s%s", baseUrl, login))
|
||||||
|
if err != nil {
|
||||||
|
return "xd"
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
responseList := make([]ivrResponse, 0)
|
||||||
|
_ = json.NewDecoder(resp.Body).Decode(&responseList)
|
||||||
|
if len(responseList) == 0 {
|
||||||
|
return "xd"
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseList[0].Stream.Title
|
||||||
|
}
|
||||||
|
|
||||||
|
func GameByUsername(login string) string {
|
||||||
|
baseUrl := "https://api.ivr.fi/v2/twitch/user?login="
|
||||||
|
|
||||||
|
resp, err := http.Get(fmt.Sprintf("%s%s", baseUrl, login))
|
||||||
|
if err != nil {
|
||||||
|
return "xd"
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
responseList := make([]ivrResponse, 0)
|
||||||
|
_ = json.NewDecoder(resp.Body).Decode(&responseList)
|
||||||
|
if len(responseList) == 0 {
|
||||||
|
return "xd"
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseList[0].Stream.Game.DisplayName
|
||||||
}
|
}
|
||||||
|
|
||||||
func IDByUsernameReply(username string) string {
|
func IDByUsernameReply(username string) string {
|
||||||
|
@ -18,7 +66,7 @@ func IDByUsernameReply(username string) string {
|
||||||
return "xd"
|
return "xd"
|
||||||
}
|
}
|
||||||
|
|
||||||
responseList := make([]ivrIDByUsernameResponse, 0)
|
responseList := make([]ivrResponse, 0)
|
||||||
err = json.NewDecoder(resp.Body).Decode(&responseList)
|
err = json.NewDecoder(resp.Body).Decode(&responseList)
|
||||||
if len(responseList) == 0 {
|
if len(responseList) == 0 {
|
||||||
return "xd"
|
return "xd"
|
||||||
|
@ -38,7 +86,7 @@ func IDByUsername(username string) string {
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
responseList := make([]ivrIDByUsernameResponse, 0)
|
responseList := make([]ivrResponse, 0)
|
||||||
_ = json.NewDecoder(resp.Body).Decode(&responseList)
|
_ = json.NewDecoder(resp.Body).Decode(&responseList)
|
||||||
if len(responseList) == 0 {
|
if len(responseList) == 0 {
|
||||||
return "xd"
|
return "xd"
|
||||||
|
|
Loading…
Reference in a new issue