diff --git a/model/line_user.go b/model/line_user.go index fef4700..581c74c 100644 --- a/model/line_user.go +++ b/model/line_user.go @@ -28,3 +28,9 @@ func (p *LineUser) Add() (err error) { _, err = x.NamedExec(`insert into "public"."line_user" ("id", "name") values (:id, :name)`, p) return } + +// UpdateName - +func (p *LineUser) UpdateName() (err error) { + _, err = x.NamedExec(`update "public"."line_user" set "name" = :name, "mtime" = now() where "id" = :id`, p) + return +} diff --git a/module/line-message/message-type.go b/module/line-message/message-type.go index 805d800..c19e3df 100644 --- a/module/line-message/message-type.go +++ b/module/line-message/message-type.go @@ -6,6 +6,7 @@ import ( "net/url" "os" "path" + "time" "git.trj.tw/golang/mtfosbot/model" "git.trj.tw/golang/mtfosbot/module/apis/line" @@ -71,6 +72,7 @@ func getSourceUser(uid, gid string) (u *model.LineUser, err error) { if err != nil { return } + if userData == nil { tmpu, err := line.GetUserInfo(uid, gid) if err != nil || tmpu == nil { @@ -83,6 +85,18 @@ func getSourceUser(uid, gid string) (u *model.LineUser, err error) { if err != nil { return nil, err } + } else { + if userData.Mtime.Unix() < (time.Now().Unix() - 432000) { + tmpu, err := line.GetUserInfo(uid, gid) + if err != nil || tmpu == nil { + return nil, err + } + userData.Name = tmpu.DisplayName + err = userData.UpdateName() + if err != nil { + return nil, err + } + } } return userData, nil