Add the ability to send unescaped messages

This commit is contained in:
Aaron Bieber 2021-03-22 14:53:30 -06:00
parent ae5ba68640
commit 0332d09fc4
2 changed files with 40 additions and 4 deletions

18
main.go
View File

@ -223,7 +223,11 @@ func main() {
case http.MethodPost:
msg = r.Form.Get("file")
default:
http.Error(w, fmt.Sprintf("method %q not implemented", r.Method), http.StatusMethodNotAllowed)
http.Error(
w,
fmt.Sprintf("method %q not implemented", r.Method),
http.StatusMethodNotAllowed,
)
return
}
@ -236,9 +240,13 @@ func main() {
for _, line := range strings.Split(msg, "\n") {
log.Printf("GOT: sending '%s'\n", line)
err = plugins.SendNotice(cli, gotRoom, line)
err = plugins.SendUnescNotice(cli, gotRoom, line)
if err != nil {
http.Error(w, fmt.Sprintf("can not send commit info: %s", err), http.StatusInternalServerError)
http.Error(
w,
fmt.Sprintf("can not send commit info: %s", err),
http.StatusInternalServerError,
)
return
}
}
@ -259,7 +267,9 @@ func main() {
errataCount, err = strconv.Atoi(storeCount)
got, err := ParseRemoteErrata(
fmt.Sprintf("http://ftp.openbsd.org/pub/OpenBSD/patches/%s/common/", openbsdRelease),
fmt.Sprintf("http://ftp.openbsd.org/pub/OpenBSD/patches/%s/common/",
openbsdRelease,
),
)
if err != nil {
fmt.Println(err)

View File

@ -177,6 +177,32 @@ func SendMDNotice(c *gomatrix.Client, roomID, message string) error {
return nil
}
// SendUnescNotice sends an text notice to a given room. It pretends to be
// "typing" by calling UserTyping for the caller.
func SendUnescNotice(c *gomatrix.Client, roomID, message string) error {
_, err := c.UserTyping(roomID, true, 3)
if err != nil {
return err
}
// Undo the escaping
_, err = c.SendMessageEvent(roomID, "m.room.message", gomatrix.HTMLMessage{
Body: message,
MsgType: "m.notice",
Format: "org.matrix.custom.text",
FormattedBody: message,
})
if err != nil {
return err
}
_, err = c.UserTyping(roomID, false, 0)
if err != nil {
return err
}
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 {