diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/main.go b/src/main.go index 0540ed0..1837cc1 100644 --- a/src/main.go +++ b/src/main.go @@ -19,6 +19,7 @@ import ( "flag" "fmt" "os" + "strings" "sync" "time" @@ -35,7 +36,7 @@ import ( var homeserver = flag.String("homeserver", "", "Matrix homeserver") var username = flag.String("username", "", "Matrix username localpart") -var accesstoken = flag.String("accesstoken", "", "Matrix accesstoken") +var accesstokenpath = flag.String("accesstokenpath", "", "Matrix accesstoken path") // var password = flag.String("password", "", "Matrix password") // var database = flag.String("database", "mautrix-example.db", "SQLite database path") @@ -44,7 +45,16 @@ var debug = flag.Bool("debug", false, "Enable debug logs") func main() { flag.Parse() - if *username == "" || *homeserver == "" || *accesstoken == "" { + + // read the accesstoken + dat, err := os.ReadFile(*accesstokenpath) + if err != nil { + _, _ = fmt.Fprintf(os.Stderr, "Couldn't read the accesstokenpath: %s\n", *accesstokenpath) + os.Exit(1) + } + accesstoken := strings.TrimSuffix(string(dat), "\n") + + if *username == "" || *homeserver == "" || accesstoken == "" { _, _ = fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0]) flag.PrintDefaults() os.Exit(1) @@ -52,7 +62,7 @@ func main() { // create a new client using the given username, homeserver and accesstoken userID := id.NewUserID(*username, *homeserver) - client, err := mautrix.NewClient(*homeserver, userID, *accesstoken) + client, err := mautrix.NewClient(*homeserver, userID, accesstoken) if err != nil { panic(err) } |