aboutsummaryrefslogtreecommitdiff
path: root/matrix
diff options
context:
space:
mode:
Diffstat (limited to 'matrix')
-rw-r--r--matrix/matrix.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/matrix/matrix.go b/matrix/matrix.go
index 3a37e64..3c97dbb 100644
--- a/matrix/matrix.go
+++ b/matrix/matrix.go
@@ -31,6 +31,7 @@ import (
"strings"
"time"
+ "gopkg.in/russross/blackfriday.v2"
"maunium.net/go/gomatrix"
"maunium.net/go/gomuks/config"
"maunium.net/go/gomuks/debug"
@@ -326,6 +327,30 @@ func (c *Container) SendMessage(roomID, msgtype, text string) (string, error) {
return resp.EventID, nil
}
+func (c *Container) SendMarkdownMessage(roomID, msgtype, text string) (string, error) {
+ defer c.gmx.Recover()
+
+ html := string(blackfriday.Run([]byte(text)))
+ if html == text {
+ return c.SendMessage(roomID, msgtype, text)
+ }
+ debug.Print(html)
+ debug.Print(text)
+
+ c.SendTyping(roomID, false)
+ resp, err := c.client.SendMessageEvent(roomID, "m.room.message",
+ map[string]interface{}{
+ "msgtype": msgtype,
+ "body": text,
+ "format": "org.matrix.custom.html",
+ "formatted_body": html,
+ })
+ if err != nil {
+ return "", err
+ }
+ return resp.EventID, nil
+}
+
// SendTyping sets whether or not the user is typing in the given room.
func (c *Container) SendTyping(roomID string, typing bool) {
defer c.gmx.Recover()