From 18698a578ee43506e64d32a7edae125fc7cc561f Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Mon, 4 Dec 2023 22:33:23 -0800 Subject: [PATCH 1/2] Update to woodstock release v0.3.1 --- go.mod | 2 +- go.sum | 4 ++-- pnut-bridge.go | 11 ++++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) 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..03e023e 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) @@ -214,7 +219,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 +240,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 } -- 2.45.2 From 9c019a3abfa5f7723329b4790fe4732c206f7bc8 Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sun, 10 Dec 2023 10:07:23 -0800 Subject: [PATCH 2/2] Include embedded links from pnut messages being sent to bridge Resolves issue #1 --- LICENSE | 2 +- README.md | 11 +---------- pnut-bridge.go | 10 +++++++++- 3 files changed, 11 insertions(+), 12 deletions(-) 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/pnut-bridge.go b/pnut-bridge.go index 03e023e..e8c86e5 100644 --- a/pnut-bridge.go +++ b/pnut-bridge.go @@ -176,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, } -- 2.45.2