-
Notifications
You must be signed in to change notification settings - Fork 1
/
bard.ahk
80 lines (77 loc) · 1.9 KB
/
bard.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
lock_path := A_ScriptDir "\app\lock.txt"
key_path := A_ScriptDir "\app\token.txt"
temp_path := A_ScriptDir "\app\t.txt"
request_path := A_ScriptDir "\app\request.txt"
response_path := A_ScriptDir "\app\response.txt"
trash_path := A_ScriptDIr "\app\trash.txt"
app_path := A_ScriptDIr "\app\GoogleBard.exe"
fileList := [lock_path, key_path, request_path, response_path, trash_path]
class Bard {
__New(token) {
this.clean()
this.token := token
this.pid := ""
this.request := ""
this.response := ""
this.openLock()
this.writeKey()
}
connect(){
; runs python exe and connects using session token.!Requires that you .Close() when done.
this.openApp()
}
clean() {
for i in fileList {
if FileExist(i) {
FileMove(i, trash_path, 1)
}
}
}
singleAsk(txt){
; opens connection, asks the question, and upon response the connection to bard is closed. Use "connect() then ask() to ask concurrent questions"
this.openApp()
this.ask(txt)
this.Close()
return this.response
}
openLock() {
FileAppend(lock_path, lock_path)
}
writeKey() {
FileAppend(this.token, key_path)
}
openApp() {
SplitPath(app_path, ,&dir)
Run(app_path, dir,,&PID)
this.PID := PID
}
ask(text) {
; if .Connect() has been run, this will ask the chatbot param question, !Requires that you .Close() when done.
this.response := ""
if FileExist(response_path) {
FileMove(response_path, trash_path, 1)
}
if FileExist(temp_path) {
FileMove(temp_path, trash_path, 1)
}
FileAppend(text, temp_path)
FileMove(temp_path, request_path, 1)
return this.responseWait()
}
responseWait() {
While not FileExist(response_path) {
if FileExist(response_path) {
break
}
else {
Sleep(10)
}
}
this.response := FileRead(response_path)
return this.response
}
Close() {
; disconnect from chatbot
this.clean()
}
}