track config file changes
Some checks failed
continuous-integration/drone/tag Build is failing

This commit is contained in:
stryan 2021-08-07 13:02:50 -04:00
parent 83f24e6347
commit b9d3b287e8
5 changed files with 40 additions and 11 deletions

View File

@ -7,14 +7,20 @@ steps:
commands:
- make
- name: create release tar
image: golang
commands:
- tar -czf release-$DRONE_TAG.tar.gz init/simpbot.service simpbot
when:
event: tag
- name: release
image: plugins/gitea-release
settings:
api_key:
from_secret: gitea_token
files:
- simpbot
- config.yml.sample
- release-$DRONE_TAG.tar.gz
base_url: https://git.saintnet.tech
when:
event: tag

1
go.mod
View File

@ -3,6 +3,7 @@ module simpbot
go 1.15
require (
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/spf13/viper v1.7.1
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 // indirect

3
go.sum
View File

@ -49,6 +49,8 @@ github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
@ -267,6 +269,7 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c=

21
main.go
View File

@ -3,9 +3,13 @@ package main
import (
"fmt"
"log"
"os"
"os/signal"
"strings"
"syscall"
"time"
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
@ -100,15 +104,14 @@ func main() {
}
}
})
var vtubersRaw []VtuberConfig
err = viper.UnmarshalKey("vtubers", &vtubersRaw)
if err != nil {
panic(err)
}
for _, vt := range vtubersRaw {
log.Printf("adding vtuber %v", vt)
vtubers = append(vtubers, NewVtuber(vt.Name, vt.ChannelID, vt.LiveMsg))
}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGUSR1)
vtubers = LoadVtubers()
viper.WatchConfig()
viper.OnConfigChange(func(e fsnotify.Event) {
fmt.Println("Config file changed,reloading vtubers:", e.Name)
vtubers = LoadVtubers()
})
go func() {
for {

View File

@ -6,6 +6,8 @@ import (
"io/ioutil"
"log"
"net/http"
"github.com/spf13/viper"
)
type VtuberConfig struct {
@ -30,6 +32,20 @@ func NewVtuber(name, channelID, liveMsg string) *Vtuber {
}
}
func LoadVtubers() []*Vtuber {
var vtubersRaw []VtuberConfig
var vtubers []*Vtuber
err := viper.UnmarshalKey("vtubers", &vtubersRaw)
if err != nil {
panic(err)
}
for _, vt := range vtubersRaw {
log.Printf("adding vtuber %v", vt)
vtubers = append(vtubers, NewVtuber(vt.Name, vt.ChannelID, vt.LiveMsg))
}
return vtubers
}
func (v *Vtuber) IsLive() bool {
return v.CurrentStream != ""
}