diff --git a/errata.go b/errata.go index 3f8caab..d560546 100644 --- a/errata.go +++ b/errata.go @@ -189,18 +189,18 @@ func ParseRemoteErrata(s string) (*Errata, error) { } // PrintErrata pretty prints an errata -func PrintErrata(e *Erratum) string { - return fmt.Sprintf("New OpenBSD Errata: %03d\n%s: %s\n%s", - e.ID, - e.Date.String(), - e.Desc, - e.Link, - ) -} +//func PrintErrata(e *Erratum) string { +// return fmt.Sprintf("New OpenBSD Errata: %03d\n%s: %s\n%s", +// e.ID, +// e.Date.String(), +// e.Desc, +// e.Link, +// ) +//} // PrintErrataMD pretty prints an errata in markdown func PrintErrataMD(e *Erratum) string { - return fmt.Sprintf("# OpenBSD Errata %03d (_%s_)\n
%s
\n[A source code patch exists which remedies this problem.](%s)", + return fmt.Sprintf("# OpenBSD Errata %03d ( _%s_ )\n
%s
\n[A source code patch exists which remedies this problem.](%s)", e.ID, e.Date.Format("January 2, 2006"), e.Desc, diff --git a/main.go b/main.go index e1aad16..8a0ec18 100644 --- a/main.go +++ b/main.go @@ -180,8 +180,7 @@ func main() { break } for _, room := range strings.Split(alertRooms, ",") { - cli.SendNotice(room, PrintErrata(&erratum)) - plugins.SendMD(cli, room, PrintErrataMD(&erratum)) + plugins.SendMDNotice(cli, room, PrintErrataMD(&erratum)) } } c = c + 1 diff --git a/plugins/plugins.go b/plugins/plugins.go index cbfd580..3763e8b 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -143,6 +143,25 @@ func SendHTML(c *gomatrix.Client, roomID, message string) error { return nil } +// SendMDNotice sends an html notice to a given room. It pretends to be +// "typing" by calling UserTyping for the caller. +func SendMDNotice(c *gomatrix.Client, roomID, message string) error { + _, err := c.UserTyping(roomID, true, 3) + if err != nil { + return err + } + + md := []byte(message) + html := markdown.ToHTML(md, nil, nil) + c.SendMessageEvent(roomID, "m.room.message", gomatrix.GetHTMLMessage("m.notice", string(html))) + + _, 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)