From a068ca493445f17ec847535b04b47664c3202679 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 27 Nov 2021 17:13:27 -0500 Subject: [PATCH] initial --- dealer.go | 33 +++++++++++++++++++++++++++++++++ main.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 dealer.go create mode 100644 main.go diff --git a/dealer.go b/dealer.go new file mode 100644 index 0000000..d4ebc30 --- /dev/null +++ b/dealer.go @@ -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 +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..3b43e80 --- /dev/null +++ b/main.go @@ -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) + +}