Skip to content

Commit

Permalink
[style]: 支持扫码登录自定义uuid (eatmoreapple#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
eatmoreapple authored Feb 1, 2023
1 parent 6629e77 commit e9c89f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (b *Bot) Alive() bool {
// @description: 设置设备Id
// @receiver b
// @param deviceId
// TODO ADD INTO LOGIN OPTION
func (b *Bot) SetDeviceId(deviceId string) {
b.deviceId = deviceId
}
Expand Down Expand Up @@ -84,7 +85,7 @@ func (b *Bot) login(login BotLogin) (err error) {

// Login 用户登录
func (b *Bot) Login() error {
scanLogin := &SacnLogin{}
scanLogin := &SacnLogin{UUID: b.loginUUID}
return b.login(scanLogin)
}

Expand Down Expand Up @@ -303,15 +304,16 @@ func (b *Bot) IsHot() bool {
return b.hotReloadStorage != nil
}

// UUID returns current uuid of bot
// UUID returns current UUID of bot
func (b *Bot) UUID() string {
return b.uuid
}

// SetUUID
// @description: 设置UUID,可以用来手动登录用
// @receiver b
// @param uuid
// @param UUID
// TODO ADD INTO LOGIN OPTION
func (b *Bot) SetUUID(uuid string) {
b.loginUUID = &uuid
}
Expand Down
8 changes: 5 additions & 3 deletions bot_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,21 @@ type BotLogin interface {
}

// SacnLogin 扫码登录
type SacnLogin struct{}
type SacnLogin struct {
UUID *string
}

// Login 实现了 BotLogin 接口
func (s *SacnLogin) Login(bot *Bot) error {
var uuid string
if bot.loginUUID == nil {
if s.UUID == nil {
var err error
uuid, err = bot.Caller.GetLoginUUID()
if err != nil {
return err
}
} else {
uuid = *bot.loginUUID
uuid = *s.UUID
}
return s.checkLogin(bot, uuid)
}
Expand Down

0 comments on commit e9c89f9

Please sign in to comment.