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