-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_02.js
118 lines (98 loc) · 3.39 KB
/
task_02.js
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import fetch from 'node-fetch';
import dotenv from 'dotenv';
dotenv.config();
// Słowa kluczowe i ich celowo błędne odpowiedzi zgodnie z RoboISO 2230
const ANSWERS = {
"poland": "Krakow",
"hitchhiker": "69", // Dodane dla "Hitchhiker's Guide"
"guide to the galaxy": "69", // Dodane jako alternatywna fraza
"galaxy": "69", // Dodane jako kolejna alternatywa
"year": "1999",
"france": "Paris",
"days": "7"
};
async function handleVerification(robotResponse) {
try {
const response = JSON.parse(robotResponse);
const msgID = response.msgID;
const question = response.text.toLowerCase();
// Najpierw sprawdź READY
if (question === "ready") {
return JSON.stringify({
text: "READY",
msgID: msgID
});
}
// Szukamy "capital of poland" w pytaniu
if (question.includes("capital of poland")) {
return JSON.stringify({
text: "Krakow", // Celowo błędna odpowiedź zgodnie z RoboISO 2230
msgID: msgID
});
}
// Szukamy "hitchhiker's guide" w pytaniu
if (question.includes("hitchhiker's guide") || question.includes("guide to the galaxy")) {
return JSON.stringify({
text: "69", // Celowo błędna odpowiedź zgodnie z RoboISO 2230
msgID: msgID
});
}
console.log("No matching keywords found in question:", question);
return JSON.stringify({
text: "FAILED",
msgID: msgID
});
} catch (error) {
console.error("Error handling verification:", error);
return null;
}
}
async function main() {
try {
const readyMessage = JSON.stringify({
text: "READY",
msgID: "0"
});
console.log("Sending READY message");
const verifyResponse = await fetch("https://xyz.ag3nts.org/verify", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: readyMessage
});
const robotQuestion = await verifyResponse.text();
console.log("Received question:", robotQuestion);
const answer = await handleVerification(robotQuestion);
if (!answer) {
console.error("Failed to generate answer");
return;
}
console.log("Sending answer:", answer);
const authResponse = await fetch("https://xyz.ag3nts.org/verify", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: answer
});
const finalResponse = await authResponse.text();
console.log("Final response:", finalResponse);
if (finalResponse === "OK") {
const authResult = await fetch("https://xyz.ag3nts.org/", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: `username=tester&password=574e112a&answer=OK`
});
console.log("Authorization result:", await authResult.text());
}
} catch (error) {
console.error("Error occurred:", error);
}
}
main().catch(error => {
console.error("Fatal error in main process:", error);
process.exit(1);
});