send pretty notifications, and only do it once
This commit is contained in:
parent
b20c2e6480
commit
ec48ddba4e
18
errata.go
18
errata.go
@ -189,18 +189,18 @@ func ParseRemoteErrata(s string) (*Errata, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PrintErrata pretty prints an errata
|
// PrintErrata pretty prints an errata
|
||||||
func PrintErrata(e *Erratum) string {
|
//func PrintErrata(e *Erratum) string {
|
||||||
return fmt.Sprintf("New OpenBSD Errata: %03d\n%s: %s\n%s",
|
// return fmt.Sprintf("New OpenBSD Errata: %03d\n%s: %s\n%s",
|
||||||
e.ID,
|
// e.ID,
|
||||||
e.Date.String(),
|
// e.Date.String(),
|
||||||
e.Desc,
|
// e.Desc,
|
||||||
e.Link,
|
// e.Link,
|
||||||
)
|
// )
|
||||||
}
|
//}
|
||||||
|
|
||||||
// PrintErrataMD pretty prints an errata in markdown
|
// PrintErrataMD pretty prints an errata in markdown
|
||||||
func PrintErrataMD(e *Erratum) string {
|
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.ID,
|
||||||
e.Date.Format("January 2, 2006"),
|
e.Date.Format("January 2, 2006"),
|
||||||
e.Desc,
|
e.Desc,
|
||||||
|
3
main.go
3
main.go
@ -180,8 +180,7 @@ func main() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
for _, room := range strings.Split(alertRooms, ",") {
|
for _, room := range strings.Split(alertRooms, ",") {
|
||||||
cli.SendNotice(room, PrintErrata(&erratum))
|
plugins.SendMDNotice(cli, room, PrintErrataMD(&erratum))
|
||||||
plugins.SendMD(cli, room, PrintErrataMD(&erratum))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c = c + 1
|
c = c + 1
|
||||||
|
@ -143,6 +143,25 @@ func SendHTML(c *gomatrix.Client, roomID, message string) error {
|
|||||||
return nil
|
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.
|
// SendMD takes markdown and converts it to an html message.
|
||||||
func SendMD(c *gomatrix.Client, roomID, message string) error {
|
func SendMD(c *gomatrix.Client, roomID, message string) error {
|
||||||
md := []byte(message)
|
md := []byte(message)
|
||||||
|
Loading…
Reference in New Issue
Block a user