35 lines
763 B
Go
35 lines
763 B
Go
package matrixbot
|
|
|
|
import (
|
|
"maunium.net/go/mautrix"
|
|
"maunium.net/go/mautrix/event"
|
|
"maunium.net/go/mautrix/format"
|
|
"maunium.net/go/mautrix/id"
|
|
"roese.dev/matrix-development-lauge/modules/config"
|
|
)
|
|
|
|
func SendMessage(msg string) {
|
|
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)
|
|
}
|
|
|
|
content := format.RenderMarkdown(msg, false, true)
|
|
|
|
client.SendMessageEvent(id.RoomID(cfg.RoomId), event.EventMessage, &content)
|
|
}
|