Add media links to messages from pnut.io
All checks were successful
thrrgilag/pnut-bridge/pipeline/head This commit looks good
All checks were successful
thrrgilag/pnut-bridge/pipeline/head This commit looks good
Updated to woodstock v0.4.0 and added links to media from pnut.io messages.
This commit is contained in:
parent
c75f36a126
commit
db21b02342
3 changed files with 41 additions and 2 deletions
2
go.mod
2
go.mod
|
@ -8,5 +8,5 @@ require (
|
||||||
github.com/mitchellh/go-wordwrap v1.0.1
|
github.com/mitchellh/go-wordwrap v1.0.1
|
||||||
github.com/smartystreets/goconvey v1.6.4 // indirect
|
github.com/smartystreets/goconvey v1.6.4 // indirect
|
||||||
gopkg.in/ini.v1 v1.62.0
|
gopkg.in/ini.v1 v1.62.0
|
||||||
mcmillian.dev/go/woodstock v0.3.1
|
mcmillian.dev/go/woodstock v0.4.0
|
||||||
)
|
)
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -28,3 +28,5 @@ gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
|
||||||
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
mcmillian.dev/go/woodstock v0.3.1 h1:m88zZQ726dw+jBpPXhqbdeTXHL5/rnJ4g1MOzV+oMm0=
|
mcmillian.dev/go/woodstock v0.3.1 h1:m88zZQ726dw+jBpPXhqbdeTXHL5/rnJ4g1MOzV+oMm0=
|
||||||
mcmillian.dev/go/woodstock v0.3.1/go.mod h1:1CUHYZ1VUVX22aCcG9Pc/W9ZnwtFzHoyN4YHaAguO/I=
|
mcmillian.dev/go/woodstock v0.3.1/go.mod h1:1CUHYZ1VUVX22aCcG9Pc/W9ZnwtFzHoyN4YHaAguO/I=
|
||||||
|
mcmillian.dev/go/woodstock v0.4.0 h1:3ROqcfnfuihKMcyQ3TsaP4Z1vACEjEyvwtBM2HYfuhc=
|
||||||
|
mcmillian.dev/go/woodstock v0.4.0/go.mod h1:1CUHYZ1VUVX22aCcG9Pc/W9ZnwtFzHoyN4YHaAguO/I=
|
||||||
|
|
|
@ -181,6 +181,42 @@ func pnutMsgHandler(conf *Config, msg woodstock.Message) {
|
||||||
for _, v := range msg.Content.Entities.Links {
|
for _, v := range msg.Content.Entities.Links {
|
||||||
linktext = "| " + linktext + v.URL + "\n"
|
linktext = "| " + linktext + v.URL + "\n"
|
||||||
}
|
}
|
||||||
|
for rawtype, value := range msg.Raw {
|
||||||
|
if rawtype == "io.pnut.core.oembed" {
|
||||||
|
for _, v := range value {
|
||||||
|
var embed woodstock.RawEmbed
|
||||||
|
byteData, _ := json.Marshal(v)
|
||||||
|
jerr := json.Unmarshal(byteData, &embed)
|
||||||
|
if jerr != nil {
|
||||||
|
log.Println("Error unmarshaling raw", jerr)
|
||||||
|
}
|
||||||
|
switch embed.Type {
|
||||||
|
case "photo":
|
||||||
|
var photo woodstock.PhotoEmbed
|
||||||
|
jerr := json.Unmarshal(byteData, &photo)
|
||||||
|
if jerr != nil {
|
||||||
|
log.Println("Error unmarshaling photo", jerr)
|
||||||
|
}
|
||||||
|
linktext = linktext + "🖼️\n" + photo.URL + "\n"
|
||||||
|
case "video":
|
||||||
|
var video woodstock.VideoEmbed
|
||||||
|
jerr := json.Unmarshal(byteData, &video)
|
||||||
|
if jerr != nil {
|
||||||
|
log.Println("Error unmarshaling video", jerr)
|
||||||
|
}
|
||||||
|
linktext = linktext + "📽️\n" + video.URL + "\n"
|
||||||
|
case "audio":
|
||||||
|
var audio woodstock.AudioEmbed
|
||||||
|
jerr := json.Unmarshal(byteData, &audio)
|
||||||
|
if jerr != nil {
|
||||||
|
log.Println("Error unmarshaling audio", jerr)
|
||||||
|
}
|
||||||
|
linktext = linktext + "🔈\n" + audio.URL + "\n"
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if len(linktext) > 0 {
|
if len(linktext) > 0 {
|
||||||
msgtext = msgtext + "\n\n" + linktext
|
msgtext = msgtext + "\n\n" + linktext
|
||||||
}
|
}
|
||||||
|
@ -262,7 +298,7 @@ func bridgeMsgHandler(conf *Config, msg MbMessage) {
|
||||||
line := msg.Username + " " + line
|
line := msg.Username + " " + line
|
||||||
log.Printf(">> sending message from %s to channel %s ...", msg.Gateway, channelID)
|
log.Printf(">> sending message from %s to channel %s ...", msg.Gateway, channelID)
|
||||||
newmessage := woodstock.NewMessage{Text: line, Raw: raw}
|
newmessage := woodstock.NewMessage{Text: line, Raw: raw}
|
||||||
_, err := client.CreateMessage(channelID, newmessage)
|
_, err := client.CreateMessage(channelID, newmessage, url.Values{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("!! problem posting message to pnut.io", err)
|
log.Println("!! problem posting message to pnut.io", err)
|
||||||
}
|
}
|
||||||
|
@ -316,6 +352,7 @@ func main() {
|
||||||
|
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Set("access_token", conf.PnutAccessToken)
|
params.Set("access_token", conf.PnutAccessToken)
|
||||||
|
params.Set("include_raw", "1")
|
||||||
|
|
||||||
socketURL := "wss://stream.pnut.io/v1/user?" + params.Encode()
|
socketURL := "wss://stream.pnut.io/v1/user?" + params.Encode()
|
||||||
conn, _, err := websocket.DefaultDialer.Dial(socketURL, nil)
|
conn, _, err := websocket.DefaultDialer.Dial(socketURL, nil)
|
||||||
|
|
Loading…
Reference in a new issue