From a8c0c9650555fbb169512a8a0b8cd01c95fddfff Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 17 Jan 2023 22:49:57 -0500 Subject: [PATCH] add subs --- main.go | 18 +++++++++++++++++- vtuber.go | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 9dc8c34..03b0766 100644 --- a/main.go +++ b/main.go @@ -153,8 +153,19 @@ func main() { client.SendText(evt.RoomID, "Reloading config") fmt.Println("Reload requested,reloading vtubers") vtubers = LoadVtubers() + case "subscribe": + if len(body_s) < 3 { + client.SendText(evt.RoomID, "Need a member to subscribe to") + } + vt := body_s[2] + for _, v := range vtubers { + if strings.ToUpper(v.Name) == strings.ToUpper(vt) { + v.Subs[evt.Sender] = true + } + } + case "help": - client.SendText(evt.RoomID, "Supported commands: info,version,stats") + client.SendText(evt.RoomID, "Supported commands: info,version,stats,reload,subscribe") default: //command not found client.SendText(evt.RoomID, "command not recognized") @@ -211,6 +222,11 @@ func main() { } } client.SendNotice(room, fmt.Sprintf("%v's Title: %v", v.Name, v.CurrentStreamTitle)) + var subs string + for k := range v.Subs { + subs += k.String() + " " + } + client.SendText(room, fmt.Sprintf("Pinging %v", subs)) resp, err := client.SendStateEvent(room, event.NewEventType("im.vector.modular.widgets"), "dimension-m.video-simp-"+v.Name, NewYT(v.Name+"'s stream", v.CurrentStream, string(room))) if err != nil { log.Println("error embeding video") diff --git a/vtuber.go b/vtuber.go index e64ac0c..9014565 100644 --- a/vtuber.go +++ b/vtuber.go @@ -8,6 +8,7 @@ import ( "net/http" "github.com/spf13/viper" + "maunium.net/go/mautrix/id" ) type VtuberConfig struct { @@ -25,6 +26,7 @@ type Vtuber struct { LiveMsg string AnnounceLive bool TotalStreams int + Subs map[id.UserID]bool } func NewVtuber(name, channelID, liveMsg string, announce bool) *Vtuber { @@ -36,6 +38,7 @@ func NewVtuber(name, channelID, liveMsg string, announce bool) *Vtuber { LiveMsg: liveMsg, AnnounceLive: announce, TotalStreams: 0, + Subs: make(map[id.UserID]bool), } }