Skip to content

Commit

Permalink
add teams and account priority
Browse files Browse the repository at this point in the history
  • Loading branch information
xqdoo00o committed Apr 20, 2024
1 parent 0a7512d commit b1ec850
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 68 deletions.
103 changes: 68 additions & 35 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import (
"github.com/xqdoo00o/OpenAIAuth/auth"
)

var accounts []Account
var accounts map[string]AccountInfo

var validAccounts []string

const interval = time.Hour * 24

type Account struct {
Email string `json:"username"`
type AccountInfo struct {
Password string `json:"password"`
Times []int `json:"times"`
}

type TokenExp struct {
Expand Down Expand Up @@ -57,19 +57,36 @@ func AppendIfNone(slice []string, i string) []string {
return append(slice, i)
}

var TimesCounter int

func getSecret() (string, tokens.Secret) {
if len(validAccounts) != 0 {
account := validAccounts[0]
validAccounts = append(validAccounts[1:], account)
return account, ACCESS_TOKENS.GetSecret(account)
secret := ACCESS_TOKENS.GetSecret(account)
if TimesCounter == 0 {
TimesCounter = accounts[account].Times[0]
if secret.TeamUserID != "" && len(accounts[account].Times) == 2 {
TimesCounter += accounts[account].Times[1]
}
}
TimesCounter--
if TimesCounter == 0 {
validAccounts = append(validAccounts[1:], account)
}
if secret.TeamUserID != "" {
if TimesCounter < accounts[account].Times[0] {
secret.TeamUserID = ""
}
}
return account, secret
} else {
return "", tokens.Secret{}
}
}

// Read accounts.txt and create a list of accounts
func readAccounts() {
accounts = []Account{}
accounts = map[string]AccountInfo{}
// Read accounts.txt and create a list of accounts
if _, err := os.Stat("accounts.txt"); err == nil {
// Each line is a proxy, put in proxies array
Expand All @@ -79,23 +96,38 @@ func readAccounts() {
for scanner.Scan() {
// Split by :
line := strings.Split(scanner.Text(), ":")
if len(line) < 2 {
length := len(line)
if length < 2 {
continue
}
var times []int
if length == 2 {
times = append(times, 1)
} else {
timeStrs := strings.Split(line[2], "/")
for i := 0; i < len(timeStrs); i++ {
time, err := strconv.Atoi(timeStrs[i])
if i == 2 || err != nil || time < 1 {
break
}
times = append(times, time)
}
if len(times) == 0 {
times = append(times, 1)
}
}
// Create an account
account := Account{
Email: line[0],
accounts[line[0]] = AccountInfo{
Password: line[1],
Times: times,
}
// Append to accounts
accounts = append(accounts, account)
}
}
}

func newTimeFunc(account Account, token_list map[string]tokens.Secret, cron bool) func() {
func newTimeFunc(email string, password string, token_list map[string]tokens.Secret, cron bool) func() {
return func() {
updateSingleToken(account, token_list, cron)
updateSingleToken(email, password, token_list, cron)
}
}

Expand Down Expand Up @@ -127,28 +159,28 @@ func scheduleTokenPUID() {
} else {
ACCESS_TOKENS = tokens.NewAccessToken(token_list)
validAccounts = []string{}
for _, account := range accounts {
token := token_list[account.Email].Token
for account, info := range accounts {
token := token_list[account].Token
if token == "" {
updateSingleToken(account, nil, true)
updateSingleToken(account, info.Password, nil, true)
} else {
var toPUIDExpire time.Duration
var puidTime time.Time
var toExpire time.Duration
if token_list[account.Email].PUID != "" {
if token_list[account].PUID != "" {
re := regexp.MustCompile(`\d{10,}`)
puidIat := re.FindString(token_list[account.Email].PUID)
puidIat := re.FindString(token_list[account].PUID)
if puidIat != "" {
puidIatInt, _ := strconv.ParseInt(puidIat, 10, 64)
puidTime = time.Unix(puidIatInt, 0)
toPUIDExpire = interval - time.Since(puidTime)
if toPUIDExpire < 0 {
updateSingleToken(account, nil, false)
updateSingleToken(account, info.Password, nil, false)
}
}
}
tokenProcess:
token = ACCESS_TOKENS.GetSecret(account.Email).Token
token = ACCESS_TOKENS.GetSecret(account).Token
expireTime, err := getTokenExpire(token)
nowTime := time.Now()
if err != nil {
Expand All @@ -162,32 +194,32 @@ func scheduleTokenPUID() {
if toPUIDExpire > 0 {
toPUIDExpire = interval - nowTime.Sub(puidTime)
if toExpire-toPUIDExpire > 2e9 {
updateSingleToken(account, nil, false)
updateSingleToken(account, info.Password, nil, false)
toPUIDExpire = 0
goto tokenProcess
}
}
if toExpire > 0 {
validAccounts = AppendIfNone(validAccounts, account.Email)
f := newTimeFunc(account, nil, true)
validAccounts = AppendIfNone(validAccounts, account)
f := newTimeFunc(account, info.Password, nil, true)
time.AfterFunc(toExpire+time.Second, f)
} else {
updateSingleToken(account, nil, true)
updateSingleToken(account, info.Password, nil, true)
}
}
}
}
}
}

func updateSingleToken(account Account, token_list map[string]tokens.Secret, cron bool) {
func updateSingleToken(email string, password string, token_list map[string]tokens.Secret, cron bool) {
if os.Getenv("CF_PROXY") != "" {
// exec warp-cli disconnect and connect
exec.Command("warp-cli", "disconnect").Run()
exec.Command("warp-cli", "connect").Run()
time.Sleep(5 * time.Second)
}
println("Updating access token for " + account.Email)
println("Updating access token for " + email)
var proxy_url string
if len(proxies) == 0 {
proxy_url = ""
Expand All @@ -196,16 +228,16 @@ func updateSingleToken(account Account, token_list map[string]tokens.Secret, cro
// Push used proxy to the back of the list
proxies = append(proxies[1:], proxies[0])
}
authenticator := auth.NewAuthenticator(account.Email, account.Password, proxy_url)
authenticator := auth.NewAuthenticator(email, password, proxy_url)
err := authenticator.RenewWithCookies()
if err != nil {
authenticator.ResetCookies()
err := authenticator.Begin()
if err != nil {
if token_list == nil {
ACCESS_TOKENS.Delete(account.Email)
ACCESS_TOKENS.Delete(email)
for i, v := range validAccounts {
if v == account.Email {
if v == email {
validAccounts = append(validAccounts[:i], validAccounts[i+1:]...)
break
}
Expand All @@ -219,20 +251,21 @@ func updateSingleToken(account Account, token_list map[string]tokens.Secret, cro
}
access_token := authenticator.GetAccessToken()
puid, _ := authenticator.GetPUID()
teamUserID, _ := authenticator.GetTeamUserID()
if token_list != nil {
token_list[account.Email] = tokens.Secret{Token: access_token, PUID: puid}
token_list[email] = tokens.Secret{Token: access_token, PUID: puid, TeamUserID: teamUserID}
} else {
ACCESS_TOKENS.Set(account.Email, access_token, puid)
ACCESS_TOKENS.Set(email, access_token, puid, teamUserID)
ACCESS_TOKENS.Save()
}
validAccounts = AppendIfNone(validAccounts, account.Email)
validAccounts = AppendIfNone(validAccounts, email)
println("Success!")
err = authenticator.SaveCookies()
if err != nil {
println(err.Details)
}
if cron {
f := newTimeFunc(account, token_list, cron)
f := newTimeFunc(email, password, token_list, cron)
time.AfterFunc(interval+time.Second, f)
}
}
Expand All @@ -241,8 +274,8 @@ func updateToken() {
token_list := map[string]tokens.Secret{}
validAccounts = []string{}
// Loop through each account
for _, account := range accounts {
updateSingleToken(account, token_list, false)
for account, info := range accounts {
updateSingleToken(account, info.Password, token_list, false)
}
// Append access token to access_tokens.json
ACCESS_TOKENS = tokens.NewAccessToken(token_list)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ require (
github.com/gorilla/websocket v1.5.1
github.com/joho/godotenv v1.5.1
github.com/tidwall/gjson v1.17.1
github.com/xqdoo00o/OpenAIAuth v0.0.0-20240403091529-7ef147706fc4
github.com/xqdoo00o/OpenAIAuth v0.0.0-20240420184134-706a5d60f6c1
github.com/xqdoo00o/funcaptcha v0.0.0-20240403090732-1b604d808f6c
golang.org/x/crypto v0.22.0
golang.org/x/image v0.15.0
k8s.io/apimachinery v0.29.3
)
Expand Down Expand Up @@ -48,7 +49,6 @@ require (
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
Expand Down
27 changes: 7 additions & 20 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
Expand All @@ -42,17 +41,14 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4=
github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
github.com/go-resty/resty/v2 v2.12.0 h1:rsVL8P90LFvkUYq/V5BTVe203WfRIU4gvcf+yfzJzGA=
github.com/go-resty/resty/v2 v2.12.0/go.mod h1:o0yGPrkS3lOe1+eFajk6kBW8ScXzwU3hD69/gt2yB/0=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
Expand Down Expand Up @@ -83,12 +79,10 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q=
github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3RonqW57k=
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg=
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg=
github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -111,22 +105,19 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tam7t/hpkp v0.0.0-20160821193359-2b70b4024ed5 h1:YqAladjX7xpA6BM04leXMWAEjS0mTZ5kUU9KRBriQJc=
github.com/tam7t/hpkp v0.0.0-20160821193359-2b70b4024ed5/go.mod h1:2JjD2zLQYH5HO74y5+aE3remJQvl6q4Sn6aWA2wD1Ng=
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U=
github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/xqdoo00o/OpenAIAuth v0.0.0-20240403091529-7ef147706fc4 h1:Goj6yoMgADshscKkfhRpDeMxyGm2wdcHCUPj0YQ+B3c=
github.com/xqdoo00o/OpenAIAuth v0.0.0-20240403091529-7ef147706fc4/go.mod h1:XHxG7wI3Erk4nS0rwjXVF3FllYW5QxsRynnJ0GqAMCQ=
github.com/xqdoo00o/OpenAIAuth v0.0.0-20240420184134-706a5d60f6c1 h1:pSzLMgRZ8G9f6qytVm/OL97hD+qSTvhceSzDhW7SRbY=
github.com/xqdoo00o/OpenAIAuth v0.0.0-20240420184134-706a5d60f6c1/go.mod h1:XHxG7wI3Erk4nS0rwjXVF3FllYW5QxsRynnJ0GqAMCQ=
github.com/xqdoo00o/funcaptcha v0.0.0-20240403090732-1b604d808f6c h1:nj17XsSTwprsZUDXLldOUZmqz7VlHsLCeXXFOE6Q+Mk=
github.com/xqdoo00o/funcaptcha v0.0.0-20240403090732-1b604d808f6c/go.mod h1:7aCyoW5MHDUsoooMVLqKe0F7W9HMPUvDG3bXqw++8XA=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand All @@ -147,7 +138,6 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
Expand All @@ -160,7 +150,6 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -179,12 +168,12 @@ golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
Expand All @@ -201,8 +190,6 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/apimachinery v0.27.2 h1:vBjGaKKieaIreI+oQwELalVG4d8f3YAMNpWLzDXkxeg=
k8s.io/apimachinery v0.27.2/go.mod h1:XNfZ6xklnMCOGGFNqXG7bUrQCoR04dh/E7FprV6pb+E=
k8s.io/apimachinery v0.29.3 h1:2tbx+5L7RNvqJjn7RIuIKu9XTsIZ9Z5wX2G22XAa5EU=
k8s.io/apimachinery v0.29.3/go.mod h1:hx/S4V2PNW4OMg3WizRrHutyB5la0iCUbZym+W0EQIU=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
Expand Down
16 changes: 9 additions & 7 deletions internal/chatgpt/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,20 @@ func POSTconversation(message chatgpt_types.ChatGPTRequest, secret *tokens.Secre
if err != nil {
return &http.Response{}, err
}
// Clear cookies
if secret.PUID != "" {
request.Header.Set("Cookie", "_puid="+secret.PUID+";")
}
request.Header.Set("Content-Type", "application/json")
request.Header.Set("User-Agent", userAgent)
request.Header.Set("Accept", "text/event-stream")
request.Header.Set("Oai-Device-Id", deviceId)
request.Header.Set("Oai-Language", "en-US")
if secret.Token != "" {
request.Header.Set("Authorization", "Bearer "+secret.Token)
}
if secret.PUID != "" {
request.Header.Set("Cookie", "_puid="+secret.PUID+";")
}
if secret.TeamUserID != "" {
request.Header.Set("Chatgpt-Account-Id", secret.TeamUserID)
}
if arkoseToken != "" {
request.Header.Set("Openai-Sentinel-Arkose-Token", arkoseToken)
}
Expand All @@ -375,9 +380,6 @@ func POSTconversation(message chatgpt_types.ChatGPTRequest, secret *tokens.Secre
if proofToken != "" {
request.Header.Set("Openai-Sentinel-Proof-Token", proofToken)
}
if secret.Token != "" {
request.Header.Set("Authorization", "Bearer "+secret.Token)
}
if err != nil {
return &http.Response{}, err
}
Expand Down
Loading

0 comments on commit b1ec850

Please sign in to comment.