diff --git a/LICENSE b/LICENSE index 3906dbd..41c2357 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Morgan McMillian +Copyright (c) 2023 Morgan McMillian Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 72d334e..7e71076 100644 --- a/README.md +++ b/README.md @@ -2,20 +2,13 @@ A [matterbridge] API plugin allowing you to connect message channels on [pnut.io] to other supported chat services. -## Contributing - -Report bugs or submit patches via [email]. - -Join my public chat room for development discussion. - -- [#devel:mcmillian.ems.host] ## License ``` MIT License -Copyright (c) 2021 Morgan McMillian +Copyright (c) 2023 Morgan McMillian Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -38,5 +31,3 @@ SOFTWARE. [matterbridge]: https://github.com/42wim/matterbridge [pnut.io]: https://pnut.io -[email]: https://morgan.mcmillian.dev/contact -[#devel:mcmillian.ems.host]: https://matrix.to/#/#devel:mcmillian.ems.host diff --git a/go.mod b/go.mod index a083584..82e2822 100644 --- a/go.mod +++ b/go.mod @@ -8,5 +8,5 @@ require ( github.com/mitchellh/go-wordwrap v1.0.1 github.com/smartystreets/goconvey v1.6.4 // indirect gopkg.in/ini.v1 v1.62.0 - mcmillian.dev/go/woodstock v0.0.0-20220820203043-62b10b5c3c0d + mcmillian.dev/go/woodstock v0.3.1 ) diff --git a/go.sum b/go.sum index 8dc7fc8..f1edfcf 100644 --- a/go.sum +++ b/go.sum @@ -26,5 +26,5 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU= gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -mcmillian.dev/go/woodstock v0.0.0-20220820203043-62b10b5c3c0d h1:TTvGSHCAy5HsIV9p5ruxKX+C5XoJyQ/RlcWTmySV9SI= -mcmillian.dev/go/woodstock v0.0.0-20220820203043-62b10b5c3c0d/go.mod h1:1CUHYZ1VUVX22aCcG9Pc/W9ZnwtFzHoyN4YHaAguO/I= +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= diff --git a/pnut-bridge.go b/pnut-bridge.go index f4dbea8..e8c86e5 100644 --- a/pnut-bridge.go +++ b/pnut-bridge.go @@ -17,11 +17,11 @@ import ( "strings" "time" - "mcmillian.dev/go/woodstock" "github.com/gabriel-vasile/mimetype" "github.com/gorilla/websocket" "github.com/mitchellh/go-wordwrap" "gopkg.in/ini.v1" + "mcmillian.dev/go/woodstock" ) var cfgfile *string @@ -109,6 +109,11 @@ type PnutOembed struct { Height int `json:"height"` } +type Raw struct { + Type string `json:"type"` + Value interface{} `json:"value"` +} + func subscribe(connectionID string, accessToken string, rooms []Room) { params := url.Values{} params.Set("connection_id", connectionID) @@ -171,9 +176,17 @@ func pnutMsgHandler(conf *Config, msg woodstock.Message) { if msg.User.Username == conf.PnutUsername { return } + msgtext := msg.Content.Text + linktext := "" + for _, v := range msg.Content.Entities.Links { + linktext = "| " + linktext + v.URL + "\n" + } + if len(linktext) > 0 { + msgtext = msgtext + "\n\n" + linktext + } log.Printf(">> sending message from channel %s to %s ...", msg.ChannelID, gateway) data := MbOutMsg{ - Text: msg.Content.Text, + Text: msgtext, Username: msg.User.Username, Gateway: gateway, } @@ -214,7 +227,7 @@ func bridgeMsgHandler(conf *Config, msg MbMessage) { channelID := getPnutChannel(conf.Rooms, msg.Gateway) text := msg.Text - var raw []woodstock.Raw + var raw []Raw for _, file := range msg.Extra.File { fdata, err := base64.StdEncoding.DecodeString(file.Data) if err != nil { @@ -235,7 +248,7 @@ func bridgeMsgHandler(conf *Config, msg MbMessage) { Width: im.Width, Height: im.Height, } - raw = append(raw, woodstock.Raw{Type: "io.pnut.core.oembed", Value: oembed}) + raw = append(raw, Raw{Type: "io.pnut.core.oembed", Value: oembed}) } else { text = text + "\n" + file.URL }