feat(chat): add test mode

This commit is contained in:
Simon Vieille 2025-09-07 15:45:46 +02:00
commit cad4942e66
Signed by: deblan
GPG key ID: 579388D585F70417
3 changed files with 47 additions and 0 deletions

View file

@ -7,6 +7,7 @@ import (
"log" "log"
"net/http" "net/http"
"text/template" "text/template"
"time"
rice "github.com/GeertJohan/go.rice" rice "github.com/GeertJohan/go.rice"
"github.com/go-playground/validator" "github.com/go-playground/validator"
@ -14,6 +15,7 @@ import (
"github.com/labstack/echo/v4/middleware" "github.com/labstack/echo/v4/middleware"
"gitnet.fr/deblan/owncast-webhook/internal/client/twitch" "gitnet.fr/deblan/owncast-webhook/internal/client/twitch"
"gitnet.fr/deblan/owncast-webhook/internal/config" "gitnet.fr/deblan/owncast-webhook/internal/config"
"gitnet.fr/deblan/owncast-webhook/internal/store"
"gitnet.fr/deblan/owncast-webhook/internal/web/router" "gitnet.fr/deblan/owncast-webhook/internal/web/router"
) )
@ -43,6 +45,15 @@ func main() {
e.Use(middleware.Logger()) e.Use(middleware.Logger())
router.RegisterControllers(e) router.RegisterControllers(e)
if conf.Test.Enable {
go func() {
for {
store.GetMessageStore().Add(store.TestMessage{})
time.Sleep(1 * time.Second)
}
}()
}
if conf.Twitch.Enable { if conf.Twitch.Enable {
twitch.IrcClient() twitch.IrcClient()
} }

View file

@ -10,3 +10,7 @@ base_url = "https://live.example.com"
[twitch] [twitch]
enable = false enable = false
channel = "username" channel = "username"
; Add fake messages to test
[test]
enable = false

View file

@ -0,0 +1,32 @@
package store
import (
"fmt"
"math/rand"
"github.com/gempir/go-twitch-irc/v4"
)
type TestMessage struct {
Message twitch.PrivateMessage
}
func (o TestMessage) ID() string {
return fmt.Sprintf("%f", rand.Float64())
}
func (o TestMessage) Visible() bool {
return true
}
func (o TestMessage) Origin() MessageOrigin {
return MessageOriginTest
}
func (o TestMessage) Author() string {
return fmt.Sprintf("%f", rand.Float64())
}
func (o TestMessage) Content() string {
return fmt.Sprintf("%f", rand.Float64())
}