add ability to send images
This commit is contained in:
parent
a53fde7d09
commit
e09d5853ac
@ -3,6 +3,9 @@ package plugins
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"image"
|
||||
"image/png"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
@ -148,6 +151,28 @@ func SendMD(c *gomatrix.Client, roomID, message string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SendImage takes an image and sends it!.
|
||||
func SendImage(c *gomatrix.Client, roomID string, img *image.RGBA) error {
|
||||
r, w := io.Pipe()
|
||||
|
||||
go func() {
|
||||
defer w.Close()
|
||||
png.Encode(w, img)
|
||||
}()
|
||||
|
||||
mediaURL, err := c.UploadToContentRepo(r, "image/png", 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = c.SendImage(roomID, "", mediaURL.ContentURI)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Plugins is a collection of our plugins. An instance of this is iterated
|
||||
// over for each message the bot receives.
|
||||
type Plugins []Plugin
|
||||
|
Loading…
Reference in New Issue
Block a user