Add control.go include UserOperation
This commit is contained in:
parent
7255e605d5
commit
5d6de79738
42
control.go
Normal file
42
control.go
Normal file
@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/tidwall/gjson"
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
"time"
|
||||
)
|
||||
|
||||
func BindUser(m *tb.Message) bool {
|
||||
fmt.Printf("%d Begin Bind", m.Chat.ID)
|
||||
code := GetURLValue(m.Text, "code")
|
||||
fmt.Println(code)
|
||||
access, refresh := MSFirGetToken(code)
|
||||
if refresh == "" {
|
||||
fmt.Printf("%d Bind error:Getinfo", m.Chat.ID)
|
||||
return false
|
||||
}
|
||||
fmt.Printf("TGID:%d Refresh Token: %s", m.Chat.ID, refresh)
|
||||
//
|
||||
bot.Send(m.Chat, "Token获取成功!")
|
||||
info := MSGetUserInfo(access)
|
||||
fmt.Printf("TGID:%d Refresh Token: %s", m.Chat.ID, refresh)
|
||||
if info == "" {
|
||||
fmt.Printf("%d Bind error:Getinfo", m.Chat.ID)
|
||||
return false
|
||||
}
|
||||
var u MSData
|
||||
u.tgId = m.Chat.ID
|
||||
u.refreshToken = refresh
|
||||
u.msId = gjson.Get(info, "id").String()
|
||||
u.uptime = time.Now()
|
||||
u.other = ""
|
||||
//
|
||||
bot.Send(m.Chat, "MS_ID:"+u.msId+"\nuserPrincipalName: "+gjson.Get(info, "userPrincipalName").String()+"\ndisplayName"+gjson.Get(info, "displayName").String())
|
||||
if ok, err := AddData(db, u); !ok {
|
||||
fmt.Printf("%d Bind error: %s", m.Chat.ID, err)
|
||||
return false
|
||||
}
|
||||
fmt.Printf("%d Bind Successfully!", m.Chat.ID)
|
||||
return true
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user