diff --git a/client.go b/client.go index b7d9444..29b90ee 100644 --- a/client.go +++ b/client.go @@ -1,7 +1,7 @@ package matrixbotlib import ( - "io" + "log" "os" "strings" @@ -49,19 +49,25 @@ func NewMatrixClient(config *MatrixClientConfig, store mautrix.Storer) (*mautrix } func SyncToken(config *MatrixClientConfig) error { + log.Println("syncing token") + + t := make(map[string]interface{}) + data, err := os.ReadFile(config.filename) + if err != nil { + return err + } + err = yaml.Unmarshal([]byte(data), &t) + if err != nil { + return err + } + log.Println(t) + t["token"] = config.Token file, err := os.OpenFile(config.filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600) if err != nil { return err } defer file.Close() - t := make(map[string]interface{}) - data, err := io.ReadAll(file) - if err != nil { - return err - } - yaml.Unmarshal([]byte(data), &t) - t["token"] = config.Token enc := yaml.NewEncoder(file) err = enc.Encode(t)