Rewrite and refactor #1
15
simp.go
15
simp.go
@ -54,7 +54,7 @@ func (s *simp) Run() {
|
|||||||
for _, room := range rooms {
|
for _, room := range rooms {
|
||||||
if v.IsLive() {
|
if v.IsLive() {
|
||||||
// check to see if already embeded
|
// check to see if already embeded
|
||||||
var content youtubeWidget
|
var content YoutubeWidget
|
||||||
err = s.client.StateEvent(
|
err = s.client.StateEvent(
|
||||||
room,
|
room,
|
||||||
event.NewEventType("im.vector.modular.widgets"),
|
event.NewEventType("im.vector.modular.widgets"),
|
||||||
@ -99,7 +99,7 @@ func (s *simp) Run() {
|
|||||||
log.Info("Embed stream added", "event", resp, "vtuber", v.Name)
|
log.Info("Embed stream added", "event", resp, "vtuber", v.Name)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var content youtubeWidget
|
var content YoutubeWidget
|
||||||
err = s.client.StateEvent(room, event.NewEventType("im.vector.modular.widgets"), "dimension-m.video-simp-"+v.Name, &content)
|
err = s.client.StateEvent(room, event.NewEventType("im.vector.modular.widgets"), "dimension-m.video-simp-"+v.Name, &content)
|
||||||
if err == nil && content.ID != "" {
|
if err == nil && content.ID != "" {
|
||||||
// event found, kill it
|
// event found, kill it
|
||||||
@ -259,6 +259,7 @@ func (s *simp) SetupMatrix(uname, pass, token, hs, domain, dserver string) error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
s.dimensionServer = dserver
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -268,21 +269,21 @@ func (s *simp) Stop() {
|
|||||||
s.client.StopSync()
|
s.client.StopSync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *simp) NewYT(videoName, videoID, roomID string) *youtubeWidget {
|
func (s *simp) NewYT(videoName, videoID, roomID string) *YoutubeWidget {
|
||||||
encodedVod := url.QueryEscape("https://youtube.com/embed/" + videoID)
|
encodedVod := url.QueryEscape("https://youtube.com/embed/" + videoID)
|
||||||
return &youtubeWidget{
|
return &YoutubeWidget{
|
||||||
Type: "im.vector.modular.widgets",
|
Type: "im.vector.modular.widgets",
|
||||||
URL: "https://" + s.dimensionServer + "/widgets/video?url=" + encodedVod,
|
URL: "https://" + s.dimensionServer + "/widgets/video?url=" + encodedVod,
|
||||||
Name: videoName,
|
Name: videoName,
|
||||||
Data: videoData{
|
Data: VideoData{
|
||||||
VideoURL: "https://www.youtube.com/watch?v=" + videoID,
|
VideoURL: "https://www.youtube.com/watch?v=" + videoID,
|
||||||
URL: "https://youtube.com/embed/" + videoID,
|
URL: "https://youtube.com/embed/" + videoID,
|
||||||
DimensionAppMetadata: dimensionAppMetadata{
|
DimensionAppMetadata: DimensionAppMetadata{
|
||||||
InRoomID: roomID,
|
InRoomID: roomID,
|
||||||
WrapperURLBase: "https://" + s.dimensionServer + "/widgets/video?url=",
|
WrapperURLBase: "https://" + s.dimensionServer + "/widgets/video?url=",
|
||||||
WrapperID: "video",
|
WrapperID: "video",
|
||||||
ScalarWrapperID: "youtube",
|
ScalarWrapperID: "youtube",
|
||||||
Integration: integration{
|
Integration: Integration{
|
||||||
Category: "widget",
|
Category: "widget",
|
||||||
Type: "youtube",
|
Type: "youtube",
|
||||||
},
|
},
|
||||||
|
14
youtube.go
14
youtube.go
@ -1,27 +1,27 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
type integration struct {
|
type Integration struct {
|
||||||
Category string `json:"category"`
|
Category string `json:"category"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
type dimensionAppMetadata struct {
|
type DimensionAppMetadata struct {
|
||||||
InRoomID string `json:"inRoomId"`
|
InRoomID string `json:"inRoomId"`
|
||||||
WrapperURLBase string `json:"wrapperUrlBase"`
|
WrapperURLBase string `json:"wrapperUrlBase"`
|
||||||
WrapperID string `json:"wrapperId"`
|
WrapperID string `json:"wrapperId"`
|
||||||
ScalarWrapperID string `json:"scalarWrapperId"`
|
ScalarWrapperID string `json:"scalarWrapperId"`
|
||||||
Integration integration `json:"integration"`
|
Integration Integration `json:"integration"`
|
||||||
LastUpdatedTs int64 `json:"lastUpdatedTs"`
|
LastUpdatedTs int64 `json:"lastUpdatedTs"`
|
||||||
}
|
}
|
||||||
type videoData struct {
|
type VideoData struct {
|
||||||
VideoURL string `json:"videoUrl"`
|
VideoURL string `json:"videoUrl"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
DimensionAppMetadata dimensionAppMetadata `json:"dimension:app:metadata"`
|
DimensionAppMetadata DimensionAppMetadata `json:"dimension:app:metadata"`
|
||||||
}
|
}
|
||||||
type youtubeWidget struct {
|
type YoutubeWidget struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Data videoData `json:"data"`
|
Data VideoData `json:"data"`
|
||||||
CreatorUserID string `json:"creatorUserId"`
|
CreatorUserID string `json:"creatorUserId"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
RoomID string `json:"roomId"`
|
RoomID string `json:"roomId"`
|
||||||
|
Loading…
Reference in New Issue
Block a user