This commit is contained in:
stryan 2021-11-27 17:13:27 -05:00
commit a068ca4934
2 changed files with 61 additions and 0 deletions

33
dealer.go Normal file
View File

@ -0,0 +1,33 @@
package main
import (
"fmt"
"log"
"github.com/google/uuid"
"maunium.net/go/mautrix"
)
type Dealer struct {
Matches map[uuid.UUID]string
Client *mautrix.Client
}
func (d *Dealer) ConnectToMatrix(homeserver, uname, passwd string) {
log.Println("Logging into", homeserver, "as", uname)
client, err := mautrix.NewClient(homeserver, "", "")
if err != nil {
panic(err)
}
_, err = client.Login(&mautrix.ReqLogin{
Type: "m.login.password",
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: uname},
Password: passwd,
StoreCredentials: true,
})
if err != nil {
panic(err)
}
fmt.Println("Login successful")
d.Client = client
}

28
main.go Normal file
View File

@ -0,0 +1,28 @@
package main
import (
"log"
"github.com/google/uuid"
"github.com/spf13/viper"
)
func main() {
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
log.Fatalf("Fatal error config file: %v \n", err)
}
viper.SetConfigType("yaml")
homeserver := viper.GetString("homeserver")
viper.SetDefault("domain", homeserver)
username := viper.GetString("username")
password := viper.GetString("password")
dealer := &Dealer{
Matches: make(map[uuid.UUID]string),
Client: nil,
}
dealer.ConnectToMatrix(homeserver, username, password)
}