Compare commits
2 commits
165683ee9f
...
9c019a3abf
Author | SHA1 | Date | |
---|---|---|---|
9c019a3abf | |||
18698a578e |
5 changed files with 22 additions and 18 deletions
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT 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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
11
README.md
11
README.md
|
@ -2,20 +2,13 @@
|
||||||
|
|
||||||
A [matterbridge] API plugin allowing you to connect message channels on [pnut.io] to other supported chat services.
|
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
|
## License
|
||||||
|
|
||||||
```
|
```
|
||||||
MIT 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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -38,5 +31,3 @@ SOFTWARE.
|
||||||
|
|
||||||
[matterbridge]: https://github.com/42wim/matterbridge
|
[matterbridge]: https://github.com/42wim/matterbridge
|
||||||
[pnut.io]: https://pnut.io
|
[pnut.io]: https://pnut.io
|
||||||
[email]: https://morgan.mcmillian.dev/contact
|
|
||||||
[#devel:mcmillian.ems.host]: https://matrix.to/#/#devel:mcmillian.ems.host
|
|
||||||
|
|
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.0.0-20220820203043-62b10b5c3c0d
|
mcmillian.dev/go/woodstock v0.3.1
|
||||||
)
|
)
|
||||||
|
|
4
go.sum
4
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=
|
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 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.0.0-20220820203043-62b10b5c3c0d h1:TTvGSHCAy5HsIV9p5ruxKX+C5XoJyQ/RlcWTmySV9SI=
|
mcmillian.dev/go/woodstock v0.3.1 h1:m88zZQ726dw+jBpPXhqbdeTXHL5/rnJ4g1MOzV+oMm0=
|
||||||
mcmillian.dev/go/woodstock v0.0.0-20220820203043-62b10b5c3c0d/go.mod h1:1CUHYZ1VUVX22aCcG9Pc/W9ZnwtFzHoyN4YHaAguO/I=
|
mcmillian.dev/go/woodstock v0.3.1/go.mod h1:1CUHYZ1VUVX22aCcG9Pc/W9ZnwtFzHoyN4YHaAguO/I=
|
||||||
|
|
|
@ -17,11 +17,11 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"mcmillian.dev/go/woodstock"
|
|
||||||
"github.com/gabriel-vasile/mimetype"
|
"github.com/gabriel-vasile/mimetype"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/mitchellh/go-wordwrap"
|
"github.com/mitchellh/go-wordwrap"
|
||||||
"gopkg.in/ini.v1"
|
"gopkg.in/ini.v1"
|
||||||
|
"mcmillian.dev/go/woodstock"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cfgfile *string
|
var cfgfile *string
|
||||||
|
@ -109,6 +109,11 @@ type PnutOembed struct {
|
||||||
Height int `json:"height"`
|
Height int `json:"height"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Raw struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Value interface{} `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
func subscribe(connectionID string, accessToken string, rooms []Room) {
|
func subscribe(connectionID string, accessToken string, rooms []Room) {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Set("connection_id", connectionID)
|
params.Set("connection_id", connectionID)
|
||||||
|
@ -171,9 +176,17 @@ func pnutMsgHandler(conf *Config, msg woodstock.Message) {
|
||||||
if msg.User.Username == conf.PnutUsername {
|
if msg.User.Username == conf.PnutUsername {
|
||||||
return
|
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)
|
log.Printf(">> sending message from channel %s to %s ...", msg.ChannelID, gateway)
|
||||||
data := MbOutMsg{
|
data := MbOutMsg{
|
||||||
Text: msg.Content.Text,
|
Text: msgtext,
|
||||||
Username: msg.User.Username,
|
Username: msg.User.Username,
|
||||||
Gateway: gateway,
|
Gateway: gateway,
|
||||||
}
|
}
|
||||||
|
@ -214,7 +227,7 @@ func bridgeMsgHandler(conf *Config, msg MbMessage) {
|
||||||
channelID := getPnutChannel(conf.Rooms, msg.Gateway)
|
channelID := getPnutChannel(conf.Rooms, msg.Gateway)
|
||||||
|
|
||||||
text := msg.Text
|
text := msg.Text
|
||||||
var raw []woodstock.Raw
|
var raw []Raw
|
||||||
for _, file := range msg.Extra.File {
|
for _, file := range msg.Extra.File {
|
||||||
fdata, err := base64.StdEncoding.DecodeString(file.Data)
|
fdata, err := base64.StdEncoding.DecodeString(file.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -235,7 +248,7 @@ func bridgeMsgHandler(conf *Config, msg MbMessage) {
|
||||||
Width: im.Width,
|
Width: im.Width,
|
||||||
Height: im.Height,
|
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 {
|
} else {
|
||||||
text = text + "\n" + file.URL
|
text = text + "\n" + file.URL
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue