Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Databingo committed Jan 25, 2024
1 parent 9b7d1a3 commit bbed7ec
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 50 deletions.
21 changes: 15 additions & 6 deletions bard.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,36 @@ func Bard() {
for {
select {
case question := <-channel_bard:
//page_bard.MustActivate()
page_bard.MustActivate()
//page_bard.MustElementX("//rich-textarea[@aria-label='Input for prompt text']").MustWaitVisible().MustInput(question)
page_bard.MustElementX("//rich-textarea[@enterkeyhint='send']").MustWaitVisible().MustInput(question)
page_bard.MustElementX("//button[@mattooltip='Submit']").MustClick()
fmt.Println("Bard generating...")
fmt.Println("Bard generating...", role)
//page_bard.MustActivate()
//if role == ".all" {
// channel_bard <- "click_bard"
//}
if role == ".all" {
//fmt.Println("Bard role", role)
channel_bard <- "click_bard"
}
// wait generated icon
var generated_icon_appear = false
var c = 0
for i := 1; i <= 60; i++ {
if page_bard.MustHasX("//img[contains(@src, 'https://www.gstatic.com/lamda/images/sparkle_resting_v2_1ff6f6a71f2d298b1a31.gif')]") {
generated_icon_appear = true
break
}
c = c + 1
if c == 5 {
page_bard.MustActivate()
c = 0
}
time.Sleep(1 * time.Second)
}
if generated_icon_appear == true {
img := page_bard.MustElementX("//img[contains(@src, 'https://www.gstatic.com/lamda/images/sparkle_resting_v2_1ff6f6a71f2d298b1a31.gif')][last()]").MustWaitVisible()
response := img.MustElementX("parent::div/parent::bard-logo/parent::div/parent::div").MustWaitVisible()
//response := img.MustElementX("parent::div/parent::bard-logo/parent::div/parent::div").MustWaitVisible()
//response := img.MustElementX("parent::div/parent::div/parent::bard-avatar/parent::div/parent::div").MustWaitVisible()
response := img.MustElementX("ancestor::bard-avatar[1]/parent::div/parent::div").MustWaitVisible()
answer := response.MustText()
channel_bard <- answer
} else {
Expand Down
32 changes: 25 additions & 7 deletions chatgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func Chatgpt() {
for {
select {
case question := <-channel_chatgpt:
//page_chatgpt.MustActivate()
page_chatgpt.MustActivate()
for i := 1; i <= 20; i++ {
if page_chatgpt.MustHasX("//textarea[@id='prompt-textarea']") {
page_chatgpt.MustElementX("//textarea[@id='prompt-textarea']").MustInput(question)
Expand All @@ -94,31 +94,49 @@ func Chatgpt() {
}
time.Sleep(1 * time.Second)
}
fmt.Println("ChatGPT generating...")
fmt.Println("ChatGPT generating...", role)
//page_chatgpt.MustActivate()
//if role == ".all" {
// channel_chatgpt <- "click_chatgpt"
//}
if role == ".all" {
channel_chatgpt <- "click_chatgpt"
}


//page_chatgpt.MustElementX("//div[contains(text(), 'Stop generating')]")
page_chatgpt.MustElement("svg path[d='M0 2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V2z']")
//page_chatgpt.MustElement("svg path[d='M0 2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V2z']")
//fmt.Println("found creating icon")
var regenerate_icon = false

for i := 1; i <= 60; i++ {
//if page_chatgpt.MustHas("svg path[d='M20.49 9A9 9 0 0 0 5.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 0 1 3.51 15']") {
if page_chatgpt.MustHas("svg path[d='M0 2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V2z']") {

time.Sleep(1 * time.Second)
continue
}

if page_chatgpt.MustHas("svg path[d='M4.5 2.5C5.05228 2.5 5.5 2.94772 5.5 3.5V5.07196C7.19872 3.47759 9.48483 2.5 12 2.5C17.2467 2.5 21.5 6.75329 21.5 12C21.5 17.2467 17.2467 21.5 12 21.5C7.1307 21.5 3.11828 17.8375 2.565 13.1164C2.50071 12.5679 2.89327 12.0711 3.4418 12.0068C3.99033 11.9425 4.48712 12.3351 4.5514 12.8836C4.98798 16.6089 8.15708 19.5 12 19.5C16.1421 19.5 19.5 16.1421 19.5 12C19.5 7.85786 16.1421 4.5 12 4.5C9.7796 4.5 7.7836 5.46469 6.40954 7H9C9.55228 7 10 7.44772 10 8C10 8.55228 9.55228 9 9 9H4.5C3.96064 9 3.52101 8.57299 3.50073 8.03859C3.49983 8.01771 3.49958 7.99677 3.5 7.9758V3.5C3.5 2.94772 3.94771 2.5 4.5 2.5Z']") {
//page_chatgpt.MustElement("svg path[d='M7 11L12 6L17 11M12 18V7']").MustWaitVisible().MustWaitStable()
if page_chatgpt.MustHas("svg path[d='M7 11L12 6L17 11M12 18V7']") {
regenerate_icon = true
//fmt.Println("wait...")
break
}
}
time.Sleep(1 * time.Second)
}
if regenerate_icon == true {
answer := page_chatgpt.MustElementX("(//div[contains(@class, 'w-full text-token-text-primary')])[last()]").MustText()[7:]
page_chatgpt.MustActivate()
time.Sleep(3 * time.Second)

answer := page_chatgpt.MustElementX("(//div[contains(@class, 'w-full text-token-text-primary')])[last()]").MustText()[15:]
//answer := page_chatgpt.MustElementX("(//div[contains(@class, 'group w-full')])[last()]").MustText()[7:]
//answer := page_chatgpt.MustElementX("(//div[contains(@class, 'group final-completion w-full')])[last()]").MustText()[7:]
//answer_div := page_chatgpt.MustElementX("(//div[contains(@class, 'w-full text-token-text-primary')])[last()]").MustWaitStable()
//answer := answer_div.MustText()[15:]

//response := img.MustElementX("ancestor::bard-avatar[1]/parent::div/parent::div").MustWaitVisible()
//answer := response.MustText()

if strings.Contains(answer,
"An error occurred. Either the engine you requested does not exist or there was another issue processing your request. If this issue persists please contact us through our help center at help.openai.com.") {
relogin_chatgpt = true
Expand Down
59 changes: 46 additions & 13 deletions claude.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
_ "embed"
"fmt"
"github.com/go-rod/rod"
"github.com/go-rod/stealth"
//"github.com/go-rod/stealth"
"github.com/google/uuid"
"github.com/tidwall/gjson"
"strconv"
Expand All @@ -23,9 +23,21 @@ func Claude2() {
relogin_claude = true
}
}()
//page_claude = browser.MustPage("https://claude.ai")
page_claude = stealth.MustPage(browser)
page_claude.MustNavigate("https://claude.ai/api/organizations").MustWaitLoad()
page_claude = browser.MustPage("https://claude.ai")
//page_claude = stealth.MustPage(browser)
//page_claude.MustNavigate("https://claude.ai/chats").MustWaitLoad()
for i := 1; i <= 30; i++ {
if page_claude.MustHasX("//div[contains(text(), 'Start a new chat')]") {
time.Sleep(3 * time.Second)
page_claude.MustElementX("//div[contains(text(), 'Start a new chat')]").MustClick()
relogin_claude = false
break
}
time.Sleep(time.Second)
}



org_json := page_claude.MustElementX("//pre").MustText()
org_uuid := gjson.Get(string(org_json), "0.uuid").String()
time.Sleep(6 * time.Second)
Expand Down Expand Up @@ -92,15 +104,36 @@ func Claude2() {
record_chat_messages = gjson.Get(string(record_json), "chat_messages").String()
record_count := gjson.Get(string(response_chat_messages), "#").Int()
page_claude.MustNavigate("https://claude.ai/api/organizations/" + org_uuid).MustWaitLoad()
time.Sleep(2 * time.Second) // delay to simulate human being
time.Sleep(3 * time.Second) // delay to simulate human being
//question = strings.Replace(question, `"`, `\"`, -1) // escape " in input text when code into json

d := `{"completion":{"prompt":"` + question + `","timezone":"Asia/Shanghai","model":"claude-2"},"organization_uuid":"` + org_uuid + `","conversation_uuid":"` + new_uuid + `","text":"` + question + `","attachments":[]}`
//d := `{"completion":{"prompt":"` + question + `","timezone":"Asia/Shanghai","model":"claude-2"},"organization_uuid":"` + org_uuid + `","conversation_uuid":"` + new_uuid + `","text":"` + question + `","attachments":[]}`
d := `{"prompt":"` + question + `","timezone":"Asia/Bangkok","model":"claude-2.1","attachments":[],"files":[]}`
//fmt.Println(d)
//js := `
// (sdata, new_uuid) => {
// var xhr = new XMLHttpRequest();
// xhr.open("POST", "https://claude.ai/api/append_message");
// xhr.setRequestHeader('Content-Type', 'application/json');
// xhr.setRequestHeader('Referer', 'https://claude.ai/chat/new_uuid');
// xhr.setRequestHeader('Origin', 'https://claude.ai');
// xhr.setRequestHeader('TE', 'trailers');
// xhr.setRequestHeader('Connection', 'keep-alive');
// xhr.setRequestHeader('Accept', 'text/event-stream, text/event-stream');
// xhr.onreadystatechange = function() {
// if (xhr.readyState == XMLHttpRequest.DONE) {
// var res_text = xhr.responseText;
// console.log(res_text);
// }
// }
// console.log(sdata);
// xhr.send(sdata);
// }
// `
js := `
(sdata, new_uuid) => {
(sdata, org_uuid, new_uuid) => {
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://claude.ai/api/append_message");
xhr.open("POST", "https://claude.ai/api/organizations/org_uuid/chat_conversations/new_uuid/completion");
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Referer', 'https://claude.ai/chat/new_uuid');
xhr.setRequestHeader('Origin', 'https://claude.ai');
Expand All @@ -117,11 +150,11 @@ func Claude2() {
xhr.send(sdata);
}
`
page_claude.MustEval(js, d, new_uuid).Str()
fmt.Println("Claude generating...")
//if role == ".all" {
// channel_claude <- "click_claude"
//}
page_claude.MustEval(js, d, org_uuid, new_uuid).Str()
fmt.Println("Claude generating...", role)
if role == ".all" {
channel_claude <- "click_claude"
}
time.Sleep(3 * time.Second) // delay to simulate human being

// wait answer
Expand Down
178 changes: 178 additions & 0 deletions claude.goo
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
package main

import (
_ "embed"
"fmt"
"github.com/go-rod/rod"
"github.com/go-rod/stealth"
"github.com/google/uuid"
"github.com/tidwall/gjson"
"strconv"
"strings"
"time"
)

var page_claude *rod.Page
var relogin_claude = true
var channel_claude chan string

func Claude2() {
channel_claude = make(chan string)
defer func() {
if err := recover(); err != nil {
relogin_claude = true
}
}()
//page_claude = browser.MustPage("https://claude.ai")
page_claude = stealth.MustPage(browser)
page_claude.MustNavigate("https://claude.ai/api/organizations").MustWaitLoad()
org_json := page_claude.MustElementX("//pre").MustText()
org_uuid := gjson.Get(string(org_json), "0.uuid").String()
time.Sleep(6 * time.Second)

new_uuid := uuid.New().String()
new_uuid_url := "https://claude.ai/api/organizations/" + org_uuid + "/chat_conversations"
create_new_converastion_json := `{"uuid":"` + new_uuid + `","name":""}`
create_new_converastion_js := `
(new_uuid_url, sdata) => {
var xhr = new XMLHttpRequest();
xhr.open("POST", new_uuid_url);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Referer', 'https://claude.ai/chats');
xhr.setRequestHeader('Origin', 'https://claude.ai');
xhr.setRequestHeader('TE', 'trailers');
xhr.setRequestHeader('DNT', '1');
xhr.setRequestHeader('Connection', 'keep-alive');
xhr.setRequestHeader('Accept', 'text/event-stream, text/event-stream');
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
var res_text = xhr.responseText;
console.log(res_text);
}
}
console.log(sdata);
xhr.send(sdata);
}
`
page_claude.MustEval(create_new_converastion_js, new_uuid_url, create_new_converastion_json).Str()
// posted new conversation uuid
time.Sleep(3 * time.Second) // delay to simulate human being

var record_chat_messages string
var response_chat_messages string
for i := 1; i <= 20; i++ {
create_json := page_claude.MustNavigate("https://claude.ai/api/organizations/" + org_uuid + "/chat_conversations/" + new_uuid).MustElementX("//pre").MustText()

message_uuid := gjson.Get(string(create_json), "uuid").String()
if message_uuid == new_uuid {
//fmt.Println("create_conversation success...")
relogin_claude = false
record_chat_messages = gjson.Get(string(create_json), "chat_messages").String()
break
}
time.Sleep(2 * time.Second)
}

if relogin_claude == true {
sprint("✘ Claude")
//page_claude.MustPDF("./tmp/Claude✘.pdf")
}
if relogin_claude == false {
sprint("✔ Claude")
for {
select {
case question := <-channel_claude:
question = strings.Replace(question, "\r", "\n", -1)
question = strings.Replace(question, "\"", "\\\"", -1)
question = strings.Replace(question, "\n", "\\n", -1)
question = strings.TrimSuffix(question, "\n")
// re-activate
page_claude.MustNavigate("https://claude.ai/api/account/statsig/" + org_uuid).MustWaitLoad()
record_json := page_claude.MustNavigate("https://claude.ai/api/organizations/" + org_uuid + "/chat_conversations/" + new_uuid).MustElementX("//pre").MustText()
record_chat_messages = gjson.Get(string(record_json), "chat_messages").String()
record_count := gjson.Get(string(response_chat_messages), "#").Int()
page_claude.MustNavigate("https://claude.ai/api/organizations/" + org_uuid).MustWaitLoad()
time.Sleep(3 * time.Second) // delay to simulate human being
//question = strings.Replace(question, `"`, `\"`, -1) // escape " in input text when code into json

//d := `{"completion":{"prompt":"` + question + `","timezone":"Asia/Shanghai","model":"claude-2"},"organization_uuid":"` + org_uuid + `","conversation_uuid":"` + new_uuid + `","text":"` + question + `","attachments":[]}`
d := `{"prompt":"` + question + `","timezone":"Asia/Bangkok","model":"claude-2.1","attachments":[],"files":[]}`
//fmt.Println(d)
//js := `
// (sdata, new_uuid) => {
// var xhr = new XMLHttpRequest();
// xhr.open("POST", "https://claude.ai/api/append_message");
// xhr.setRequestHeader('Content-Type', 'application/json');
// xhr.setRequestHeader('Referer', 'https://claude.ai/chat/new_uuid');
// xhr.setRequestHeader('Origin', 'https://claude.ai');
// xhr.setRequestHeader('TE', 'trailers');
// xhr.setRequestHeader('Connection', 'keep-alive');
// xhr.setRequestHeader('Accept', 'text/event-stream, text/event-stream');
// xhr.onreadystatechange = function() {
// if (xhr.readyState == XMLHttpRequest.DONE) {
// var res_text = xhr.responseText;
// console.log(res_text);
// }
// }
// console.log(sdata);
// xhr.send(sdata);
// }
// `
js := `
(sdata, org_uuid, new_uuid) => {
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://claude.ai/api/organizations/org_uuid/chat_conversations/new_uuid/completion");
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Referer', 'https://claude.ai/chat/new_uuid');
xhr.setRequestHeader('Origin', 'https://claude.ai');
xhr.setRequestHeader('TE', 'trailers');
xhr.setRequestHeader('Connection', 'keep-alive');
xhr.setRequestHeader('Accept', 'text/event-stream, text/event-stream');
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
var res_text = xhr.responseText;
console.log(res_text);
}
}
console.log(sdata);
xhr.send(sdata);
}
`
page_claude.MustEval(js, d, org_uuid, new_uuid).Str()
fmt.Println("Claude generating...", role)
if role == ".all" {
channel_claude <- "click_claude"
}
time.Sleep(3 * time.Second) // delay to simulate human being

// wait answer
var claude_response = false
var response_json string
for i := 1; i <= 20; i++ {
if page_claude.MustNavigate("https://claude.ai/api/organizations/" + org_uuid + "/chat_conversations/" + new_uuid).MustHasX("//pre") {
response_json = page_claude.MustNavigate("https://claude.ai/api/organizations/" + org_uuid + "/chat_conversations/" + new_uuid).MustElementX("//pre").MustText()
response_chat_messages = gjson.Get(string(response_json), "chat_messages").String()
count := gjson.Get(string(response_chat_messages), "#").Int()

if response_chat_messages != record_chat_messages && count == record_count+2 {
claude_response = true
record_chat_messages = response_chat_messages
break
}
}
time.Sleep(3 * time.Second)
}
if claude_response == true {
count := gjson.Get(string(response_chat_messages), "#").Int()
answer := gjson.Get(string(response_json), "chat_messages.#(index=="+strconv.FormatInt(count-1, 10)+").text").String()
channel_claude <- answer
} else {
channel_claude <- "✘✘ Claude, Please check the internet connection and verify login status."
relogin_claude = true
//page_claude.MustPDF("./tmp/Claude✘.pdf")
}
}
}
}

}
2 changes: 1 addition & 1 deletion falcon180.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func Falcon180() {
for {
select {
case question := <-channel_falcon180:
//page_hc.MustActivate()
//page_falcon180.MustActivate()
//fmt.Println("Falcon180 received question...", question)
for i := 1; i <= 20; i++ {
if page_falcon180.MustHasX("//textarea[@data-testid='textbox']") {
Expand Down
Loading

0 comments on commit bbed7ec

Please sign in to comment.