send pretty notifications, and only do it once

This commit is contained in:
Aaron Bieber 2020-04-06 16:38:39 -06:00
parent b20c2e6480
commit ec48ddba4e
3 changed files with 29 additions and 11 deletions

View File

@ -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<pre>%s</pre>\n[A source code patch exists which remedies this problem.](%s)",
return fmt.Sprintf("# OpenBSD Errata %03d ( _%s_ )\n<pre>%s</pre>\n[A source code patch exists which remedies this problem.](%s)",
e.ID,
e.Date.Format("January 2, 2006"),
e.Desc,

View File

@ -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

View File

@ -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)