Prefix room ids automatically with exclamation mark (#12)

* Prefix room ids automatically with exclamation mark

* Fix markdown rendering to build proper links
This commit is contained in:
Thomas Boerger 2018-09-26 00:42:25 +02:00 committed by techknowlogick
parent edb1c3a8d0
commit 68bb1dd635
3 changed files with 51 additions and 3 deletions

29
Gopkg.lock generated
View File

@ -24,21 +24,48 @@
packages = ["."] packages = ["."]
revision = "a7fc80c8060c2544fe5d4dae465b584f8e9b4e27" revision = "a7fc80c8060c2544fe5d4dae465b584f8e9b4e27"
[[projects]]
name = "github.com/microcosm-cc/bluemonday"
packages = ["."]
revision = "dafebb5b6ff2861a0d69af64991e10866c19be85"
version = "v1.0.0"
[[projects]] [[projects]]
name = "github.com/pkg/errors" name = "github.com/pkg/errors"
packages = ["."] packages = ["."]
revision = "645ef00459ed84a119197bfb8d8205042c6df63d" revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
version = "v0.8.0" version = "v0.8.0"
[[projects]]
branch = "master"
name = "github.com/shurcooL/sanitized_anchor_name"
packages = ["."]
revision = "86672fcb3f950f35f2e675df2240550f2a50762f"
[[projects]] [[projects]]
name = "github.com/urfave/cli" name = "github.com/urfave/cli"
packages = ["."] packages = ["."]
revision = "cfb38830724cc34fedffe9a2a29fb54fa9169cd1" revision = "cfb38830724cc34fedffe9a2a29fb54fa9169cd1"
version = "v1.20.0" version = "v1.20.0"
[[projects]]
branch = "master"
name = "golang.org/x/net"
packages = [
"html",
"html/atom"
]
revision = "f4c29de78a2a91c00474a2e689954305c350adf9"
[[projects]]
name = "gopkg.in/russross/blackfriday.v2"
packages = ["."]
revision = "cadec560ec52d93835bf2f15bd794700d3a2473b"
version = "v2.0.0"
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
inputs-digest = "e4283d82ea22e941f9ab4d2020b12f3721cd0235cb78cca670d2ae1105e148ef" inputs-digest = "243a217f076aeb5fdc8b28a2a2f38884c3476409410f664e316cd92acf44d012"
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

View File

@ -17,3 +17,11 @@
[prune] [prune]
go-tests = true go-tests = true
unused-packages = true unused-packages = true
[[constraint]]
name = "gopkg.in/russross/blackfriday.v2"
version = "2.0.0"
[[constraint]]
name = "github.com/microcosm-cc/bluemonday"
version = "1.0.0"

View File

@ -6,6 +6,8 @@ import (
"github.com/drone/drone-template-lib/template" "github.com/drone/drone-template-lib/template"
"github.com/matrix-org/gomatrix" "github.com/matrix-org/gomatrix"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/microcosm-cc/bluemonday"
"gopkg.in/russross/blackfriday.v2"
) )
type ( type (
@ -74,7 +76,7 @@ func (p Plugin) Exec() error {
m.SetCredentials(r.UserID, r.AccessToken) m.SetCredentials(r.UserID, r.AccessToken)
} }
joined, err := m.JoinRoom(p.Config.RoomID, "", nil) joined, err := m.JoinRoom(prepend("!", p.Config.RoomID), "", nil)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to join room") return errors.Wrap(err, "failed to join room")
@ -86,7 +88,18 @@ func (p Plugin) Exec() error {
return errors.Wrap(err, "failed to render template") return errors.Wrap(err, "failed to render template")
} }
if _, err := m.SendNotice(joined.RoomID, message); err != nil { formatted := bluemonday.UGCPolicy().SanitizeBytes(
blackfriday.Run([]byte(message)),
)
content := gomatrix.HTMLMessage{
Body: message,
MsgType: "m.notice",
Format: "org.matrix.custom.html",
FormattedBody: string(formatted),
}
if _, err := m.SendMessageEvent(joined.RoomID, "m.room.message", content); err != nil {
return errors.Wrap(err, "failed to submit message") return errors.Wrap(err, "failed to submit message")
} }