-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutopia.go
35 lines (27 loc) · 842 Bytes
/
utopia.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"encoding/base64"
"errors"
"fmt"
swissknife "github.com/Sagleft/swiss-knife"
)
func (app *solution) utopiaConnect() error {
if !app.Utopia.CheckClientConnection() {
return errors.New("failed to open connection to Utopia. check host, token or port")
}
return nil
}
func (app *solution) sendPostImage() error {
imageBytes, err := swissknife.ReadFileToBytes(postImageOutput)
if err != nil {
return fmt.Errorf("read post image: %w", err)
}
imgEncoded := base64.StdEncoding.EncodeToString(imageBytes)
_, err = app.Utopia.SendChannelPicture(app.Config.ChannelID, imgEncoded, "", postImageFilename)
return err
}
func (app *solution) sendPost(postText string) error {
_, err := app.Utopia.SendChannelMessage(app.Config.ChannelID, postText)
return err
// TBD: pin post if time variant "month" given
}