fix token sync

This commit is contained in:
stryan 2023-10-12 21:49:42 -04:00
parent 547977237c
commit 9d0ab0b818

View File

@ -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)