Skip to content

Commit 68bb1dd

Browse files
tboergertechknowlogick
authored andcommitted
Prefix room ids automatically with exclamation mark (#12)
* Prefix room ids automatically with exclamation mark * Fix markdown rendering to build proper links
1 parent edb1c3a commit 68bb1dd

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

Gopkg.lock

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@
1717
[prune]
1818
go-tests = true
1919
unused-packages = true
20+
21+
[[constraint]]
22+
name = "gopkg.in/russross/blackfriday.v2"
23+
version = "2.0.0"
24+
25+
[[constraint]]
26+
name = "github.com/microcosm-cc/bluemonday"
27+
version = "1.0.0"

plugin.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"github.com/drone/drone-template-lib/template"
77
"github.com/matrix-org/gomatrix"
88
"github.com/pkg/errors"
9+
"github.com/microcosm-cc/bluemonday"
10+
"gopkg.in/russross/blackfriday.v2"
911
)
1012

1113
type (
@@ -74,7 +76,7 @@ func (p Plugin) Exec() error {
7476
m.SetCredentials(r.UserID, r.AccessToken)
7577
}
7678

77-
joined, err := m.JoinRoom(p.Config.RoomID, "", nil)
79+
joined, err := m.JoinRoom(prepend("!", p.Config.RoomID), "", nil)
7880

7981
if err != nil {
8082
return errors.Wrap(err, "failed to join room")
@@ -86,7 +88,18 @@ func (p Plugin) Exec() error {
8688
return errors.Wrap(err, "failed to render template")
8789
}
8890

89-
if _, err := m.SendNotice(joined.RoomID, message); err != nil {
91+
formatted := bluemonday.UGCPolicy().SanitizeBytes(
92+
blackfriday.Run([]byte(message)),
93+
)
94+
95+
content := gomatrix.HTMLMessage{
96+
Body: message,
97+
MsgType: "m.notice",
98+
Format: "org.matrix.custom.html",
99+
FormattedBody: string(formatted),
100+
}
101+
102+
if _, err := m.SendMessageEvent(joined.RoomID, "m.room.message", content); err != nil {
90103
return errors.Wrap(err, "failed to submit message")
91104
}
92105

0 commit comments

Comments
 (0)