send got messages as plain text notices

This commit is contained in:
Aaron Bieber 2020-10-01 21:27:46 +00:00
parent b7d551b67e
commit 4f03bc763a
2 changed files with 28 additions and 1 deletions

View File

@ -200,8 +200,15 @@ func main() {
return
}
msg = strings.TrimSuffix(msg, "\n")
if msg == "" {
fmt.Fprintf(w, "empty message")
return
}
log.Printf("GOT: sending '%s'\n", msg)
err = plugins.SendMDNotice(cli, got_room, msg)
err = plugins.SendNotice(cli, got_room, msg)
if err != nil {
http.Error(w, fmt.Sprintf("can not send commit info: %s", err), http.StatusInternalServerError)
return

View File

@ -177,6 +177,26 @@ func SendMDNotice(c *gomatrix.Client, roomID, message string) error {
return nil
}
// SendNotice sends an text notice to a given room. It pretends to be
// "typing" by calling UserTyping for the caller.
func SendNotice(c *gomatrix.Client, roomID, message string) error {
_, err := c.UserTyping(roomID, true, 3)
if err != nil {
return err
}
_, err = c.SendMessageEvent(roomID, "m.room.message", gomatrix.GetHTMLMessage("m.notice", message))
if err != nil {
return err
}
_, err = c.UserTyping(roomID, false, 0)
if err != nil {
return err
}
return nil
}
// SendMD takes markdown and converts it to an html message.
func SendMD(c *gomatrix.Client, roomID, message string) error {
md := []byte(message)