42 lines
714 B
Go
42 lines
714 B
Go
package message
|
|
|
|
import (
|
|
"fmt"
|
|
"local/truckstop/config"
|
|
|
|
"github.com/matrix-org/gomatrix"
|
|
)
|
|
|
|
type Matrix struct {
|
|
homeserver string
|
|
username string
|
|
token string
|
|
room string
|
|
}
|
|
|
|
func NewMatrix() Matrix {
|
|
conf := config.Get().Message.Matrix
|
|
return Matrix{
|
|
homeserver: conf.Homeserver,
|
|
username: conf.Username,
|
|
token: conf.Token,
|
|
room: conf.Room,
|
|
}
|
|
}
|
|
|
|
func (m Matrix) client() (*gomatrix.Client, error) {
|
|
return gomatrix.NewClient(m.homeserver, m.username, m.token)
|
|
}
|
|
|
|
func (m Matrix) Send(text string) error {
|
|
c, err := m.client()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
resp, err := c.SendText(m.room, text)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return fmt.Errorf("%+v", resp)
|
|
}
|