From 98791fb757f19fda21c903c3cdf3b1e1bffc4cfe Mon Sep 17 00:00:00 2001 From: zhaoYangguang <1163765691@qq.com> Date: Fri, 17 Sep 2021 18:14:34 +0800 Subject: [PATCH] auto update custom user access token --- custompuppet.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/custompuppet.go b/custompuppet.go index 58cab5c..30143e9 100644 --- a/custompuppet.go +++ b/custompuppet.go @@ -4,6 +4,7 @@ import ( "crypto/hmac" "crypto/sha512" "encoding/hex" + "strings" "time" "github.com/pkg/errors" @@ -100,8 +101,13 @@ func (puppet *Puppet) StartCustomMXID() error { } resp, err := intent.Whoami() if err != nil { - puppet.clearCustomMXID() - return err + if strings.Index(err.Error(), "M_UNKNOWN_TOKEN (HTTP 401)") > -1 { + err, _ = puppet.customUser.UpdateAccessToken(puppet) + } + if err != nil { + puppet.clearCustomMXID() + return err + } } if resp.UserID != puppet.CustomMXID { puppet.clearCustomMXID()