Skip to content

Commit

Permalink
修复不自动刷新cloudflare cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
yxw21 committed Dec 26, 2022
1 parent ca4abc2 commit 96cca5e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ apk add chromium


# 环境变量
建议同时提供`QQ_CHAT_GPT_USERNAME``QQ_CHAT_GPT_PASSWORD``QQ_CHAT_GPT_ACCESS_TOKEN`

如果只提供用户名和密码登录账号可能需要一些时间。可能是几十秒,也有可能是几分钟,十几分钟(受网络、识别验证码影响)。如果同时提供`QQ_CHAT_GPT_ACCESS_TOKEN`可以避免等待登录。

`QQ_CHAT_GPT_ACCESS_TOKEN`即将到期前的6个小时就开始自动刷新token。

### QQ_UIN (可选)
QQ号
### QQ_PASSWORD (可选)
Expand Down
5 changes: 4 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Config struct {

var (
Instance *Config
Session *chatgpt.Session
Session = &chatgpt.Session{}
Browser *chatgpt.Browser
Chats = make(map[int64]*chatgpt.Chat)
)
Expand All @@ -42,4 +42,7 @@ func init() {
if err == nil {
Instance.QQ = qq
}
Session.Username = Instance.AIUsername
Session.Password = Instance.AIPassword
Session.AccessToken = Instance.AccessToken
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f
github.com/Mrs4s/MiraiGo v0.0.0-20221206193101-cf66e2864798
github.com/tuotoo/qrcode v0.0.0-20220425170535-52ccc2bebf5d
github.com/yxw21/chatgpt v0.9.0
github.com/yxw21/chatgpt v0.9.1
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ github.com/ulikunitz/xz v0.5.9 h1:RsKRIA2MO8x56wkkcd3LbtcE/uMszhb6DpRf+3uwa3I=
github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
github.com/yxw21/chatgpt v0.9.0 h1:QVAbgT1EBGSY6Z0j+cV265A/t7ZtYNwFms8+GqaSJGk=
github.com/yxw21/chatgpt v0.9.0/go.mod h1:40HZqYFtcZoUNXsG0LKCgzea+KHdW1XJ7MnVvhFm8z4=
github.com/yxw21/chatgpt v0.9.1 h1:bI7WK4Y1LN2l1fJ/W0J+H4zuH9IBU2BDPRr59CtjJ98=
github.com/yxw21/chatgpt v0.9.1/go.mod h1:40HZqYFtcZoUNXsG0LKCgzea+KHdW1XJ7MnVvhFm8z4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db h1:D/cFflL63o2KSLJIwjlcIt8PR064j/xsmdEJL/YvY/o=
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
Expand Down
6 changes: 1 addition & 5 deletions qqchatgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ func main() {
}
defer closeBrowser()
config.Browser = browser
if config.Instance.AIUsername != "" && config.Instance.AIPassword != "" {
config.Session = chatgpt.NewSessionWithCredential(browser, config.Instance.AIUsername, config.Instance.AIPassword).AutoRefresh()
} else {
config.Session = chatgpt.NewSessionWithAccessToken(browser, config.Instance.AccessToken).AutoRefresh()
}
config.Session.Browser = browser
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if err = helpers.AutoLoadDevice(); err != nil {
Expand Down

0 comments on commit 96cca5e

Please sign in to comment.