matrix-development-lauge/matrix-bot/matrix-bot.go

37 lines
889 B
Go
Raw Normal View History

2022-02-22 22:14:11 +01:00
package matrixbot
import (
2022-02-25 17:16:36 +01:00
"fmt"
2022-02-22 22:14:11 +01:00
"maunium.net/go/mautrix"
2022-02-25 18:46:24 +01:00
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/format"
2022-02-22 22:14:11 +01:00
"maunium.net/go/mautrix/id"
"roese.dev/matrix-development-lauge/modules/config"
)
2022-09-10 20:14:14 +02:00
func SendMessage(roomID string, topic string, header string, content string, url string) {
2022-02-22 22:14:11 +01:00
cfg := config.Cfg.Bot
client, err := mautrix.NewClient(cfg.HomeserverUrl, "", "")
if err != nil {
panic(err)
}
_, err = client.Login(&mautrix.ReqLogin{
Type: "m.login.password",
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: cfg.User},
Password: cfg.Password,
StoreCredentials: true,
})
if err != nil {
panic(err)
}
2022-09-10 20:14:14 +02:00
msg := format.RenderMarkdown(fmt.Sprintf("Thema: %s <h4>%s</h4>%s<br>%s", topic, header, content, url), false, true)
2022-02-22 22:14:11 +01:00
2022-09-10 20:14:14 +02:00
client.SendMessageEvent(id.RoomID(roomID), event.EventMessage, &msg)
2022-02-22 22:14:11 +01:00
}