commit babf667bf1cec983b7063cf3980c6bb572fafc26
parent 0318fab3ae8f5de494a248da2e1ea570e5a435f2
Author: bsandro <[email protected]>
Date: Mon, 16 Aug 2021 02:50:05 +0300
Added "sounds" to config file
Diffstat:
5 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/app/app.go b/app/app.go
@@ -2,6 +2,7 @@ package app
import (
"bsandro.tech/git/twitchapon/config"
+ ifaces "bsandro.tech/git/twitchapon/interfaces"
"bsandro.tech/git/twitchapon/localserver"
"bsandro.tech/git/twitchapon/twitch"
"github.com/andreykaipov/goobs"
@@ -26,6 +27,10 @@ func NewApp() *TApp {
return app
}
+func (app *TApp) GetConfig() ifaces.IConfig {
+ return &app.Config
+}
+
func (app *TApp) GetAccessToken() string {
return app.Auth.AccessToken
}
diff --git a/config/config.go b/config/config.go
@@ -18,6 +18,7 @@ type TConfig struct {
Port string `json:"port"`
Password string `json:"password"`
} `json:"obs"`
+ Sounds []string `json:"sounds"`
}
func (conf *TConfig) Init() error {
@@ -62,4 +63,14 @@ func (conf *TConfig) InitSample() {
conf.Obs.Host = "127.0.0.1"
conf.Obs.Port = "4444"
conf.Obs.Password = "xxxxxxxxx"
+ conf.Sounds = []string{"Sound Reward 1", "Sound Reward 2"}
+}
+
+func (conf *TConfig) HasSound(title string) bool {
+ for _, sound := range conf.Sounds {
+ if sound == title {
+ return true
+ }
+ }
+ return false
}
diff --git a/interfaces/iapp.go b/interfaces/iapp.go
@@ -1,4 +1,4 @@
-package twitchapon
+package interfaces
import (
"github.com/andreykaipov/goobs"
@@ -17,4 +17,5 @@ type IApp interface {
GetUserId() string
GetConnection() *websocket.Conn
GetObs() *goobs.Client
+ GetConfig() IConfig
}
diff --git a/interfaces/iconfig.go b/interfaces/iconfig.go
@@ -0,0 +1,9 @@
+package interfaces
+
+type IConfig interface {
+ Init() error
+ IsInited() bool
+ Print()
+ InitSample()
+ HasSound(string) bool
+}
diff --git a/twitch/message.go b/twitch/message.go
@@ -62,7 +62,8 @@ func ProcessMessage(app iface.IApp, msg *TMessage) {
} else {
if chanPointsMsg.MsgType == "reward-redeemed" {
title := chanPointsMsg.Data.Redemption.Reward.Title
- if title == "Tutturu!" || title == "Selamat Pagi!" {
+
+ if app.GetConfig().HasSound(title) {
fmt.Printf("playing sound %s\n", title)
_, _ = app.GetObs().MediaControl.RestartMedia(&mediacontrol.RestartMediaParams{SourceName: title})
}