initial
This commit is contained in:
commit
a068ca4934
33
dealer.go
Normal file
33
dealer.go
Normal 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
28
main.go
Normal 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)
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user