Skip to content

Commit fcc2bd6

Browse files
ud
1 parent 8ef82b1 commit fcc2bd6

File tree

7 files changed

+143
-114
lines changed

7 files changed

+143
-114
lines changed

.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#id các task bỏ qua, không cần quan tâm nếu không hiểu
22
SKIP_TASKS =[""]
3-
BASE_URL="https://tgapi.sleepagotchi.com/v1/tg"
3+
BASE_URL="https://api.kushempire.games/api"
44
ENABLE_DEBUG=false
55

66
# cập nhật tự động true/false

checkAPI.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ async function getBaseApi(url) {
2525
try {
2626
const response = await axios.get(url);
2727
const content = response.data;
28-
if (content?.sleep) {
29-
return { endpoint: content.sleep, message: content.copyright };
28+
if (content?.kushempire) {
29+
return { endpoint: content.kushempire, message: content.copyright };
3030
} else {
3131
return {
3232
endpoint: null,

config/config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ const settings = {
3030
AUTO_CODE_GATEWAY: process.env.AUTO_CODE_GATEWAY ? process.env.AUTO_CODE_GATEWAY.toLowerCase() === "true" : false,
3131

3232
API_ID: process.env.API_ID ? process.env.API_ID : null,
33-
BASE_URL: process.env.BASE_URL ? process.env.BASE_URL : "https://tgapi.sleepagotchi.com/v1/tg",
34-
REF_ID: process.env.REF_ID ? process.env.REF_ID : "T_1092680235",
33+
BASE_URL: process.env.BASE_URL ? process.env.BASE_URL : "https://api.kushempire.games/api",
34+
REF_ID: process.env.REF_ID ? process.env.REF_ID : "Iil4QcC4TF",
3535

3636
DELAY_BETWEEN_REQUESTS: process.env.DELAY_BETWEEN_REQUESTS && _isArray(process.env.DELAY_BETWEEN_REQUESTS) ? JSON.parse(process.env.DELAY_BETWEEN_REQUESTS) : [1, 5],
3737
DELAY_START_BOT: process.env.DELAY_START_BOT && _isArray(process.env.DELAY_START_BOT) ? JSON.parse(process.env.DELAY_START_BOT) : [1, 15],

core/header.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const headers = {
2+
Accept: "application/json, text/plain, */*",
3+
"Accept-Encoding": "gzip, deflate, br",
4+
"Accept-Language": "vi-VN,vi;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6,en;q=0.5",
5+
"Content-Type": "application/json",
6+
Origin: "https://game.kushempire.games",
7+
referer: "https://game.kushempire.games/",
8+
"Sec-Ch-Ua": '"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"',
9+
"Sec-Ch-Ua-Mobile": "?0",
10+
"Sec-Ch-Ua-Platform": '"Windows"',
11+
"Sec-Fetch-Dest": "empty",
12+
"Sec-Fetch-Mode": "cors",
13+
"Sec-Fetch-Site": "same-origin",
14+
"Cache-Control": "no-cache",
15+
Connection: "keep-alive",
16+
"user-device": "Edge/131.0.0.0#Windows/10",
17+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
18+
};
19+
20+
module.exports = headers;

data.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
user=.......
2-
query=........

main-proxy.js

+58-55
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,11 @@ const settings = require("./config/config");
99
const { sleep, loadData, getRandomNumber, saveToken, isTokenExpired, saveJson, updateEnv } = require("./utils");
1010
const { Worker, isMainThread, parentPort, workerData } = require("worker_threads");
1111
const { checkBaseUrl } = require("./checkAPI");
12+
const headers = require("./core/header");
1213

1314
class ClientAPI {
1415
constructor(queryId, accountIndex, proxy, baseURL) {
15-
this.headers = {
16-
Accept: "*/*",
17-
"Accept-Encoding": "gzip, deflate, br",
18-
"Accept-Language": "vi-VN,vi;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6,en;q=0.5",
19-
"Content-Type": "application/json",
20-
Origin: "https://tg-sleepagotchi-tmp-cdn.sfo3.digitaloceanspaces.com",
21-
referer: "https://tg-sleepagotchi-tmp-cdn.sfo3.digitaloceanspaces.com/",
22-
"Sec-Ch-Ua": '"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"',
23-
"Sec-Ch-Ua-Mobile": "?0",
24-
"Sec-Ch-Ua-Platform": '"Windows"',
25-
"Sec-Fetch-Dest": "empty",
26-
"Sec-Fetch-Mode": "cors",
27-
"Sec-Fetch-Site": "same-origin",
28-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
29-
};
16+
this.headers = headers;
3017
this.baseURL = baseURL;
3118
this.queryId = queryId;
3219
this.accountIndex = accountIndex;
@@ -147,25 +134,41 @@ class ClientAPI {
147134
}
148135
}
149136

150-
async makeRequest(url, method, data = {}, retries = 1) {
137+
async makeRequest(
138+
url,
139+
method,
140+
data = {},
141+
options = {
142+
retries: 1,
143+
isAuth: false,
144+
}
145+
) {
146+
const { retries, isAuth } = options;
147+
151148
const headers = {
152149
...this.headers,
150+
Authorization: `tma ${this.queryId}`,
153151
};
152+
153+
if (!isAuth) {
154+
headers["Authorization"] = `Bearer ${this.token}`;
155+
}
156+
154157
const proxyAgent = new HttpsProxyAgent(this.proxy);
155158
let currRetries = 0,
156159
success = false;
157160
do {
158161
try {
159162
const response = await axios({
160163
method,
161-
url: `${url}?${this.queryId}`,
164+
url: `${url}`,
162165
data,
163166
headers,
164167
httpsAgent: proxyAgent,
165168
timeout: 30000,
166169
});
167170
success = true;
168-
return { success: true, data: response.data };
171+
return { success: true, data: response.data.data };
169172
} catch (error) {
170173
if (error.status == 400) {
171174
return { success: false, error: error.message };
@@ -178,47 +181,45 @@ class ClientAPI {
178181
currRetries++;
179182
} while (currRetries <= retries && !success);
180183
}
184+
async auth() {
185+
return this.makeRequest(`${this.baseURL}/auth/create-user`, "post", { refCode: "Iil4QcC4TF" }, { isAuth: true });
186+
}
181187

182188
async getUserInfo() {
183-
return this.makeRequest(`${this.baseURL}/getUserData`, "get");
189+
return this.makeRequest(`${this.baseURL}/user`, "get");
190+
}
191+
192+
async getQuests() {
193+
return this.makeRequest(`${this.baseURL}/user/quest`, "get");
184194
}
185195

186-
// async getValidToken(isRf = false) {
187-
// const userId = this.session_name;
188-
// const existingToken = this.token;
189-
// const existingRefreshToken = this.rfToken;
190-
// let loginResult = null;
191-
192-
// const isExp = isTokenExpired(!isRf ? existingToken : existingRefreshToken);
193-
// if (!isRf && existingToken && !isExp) {
194-
// this.log("Using valid token", "success");
195-
// return { access_token: existingToken, refresh_token: existingRefreshToken };
196-
// } else if (!isRf && existingToken && isExp) {
197-
// this.log("Token expired, refreshing token...", "info");
198-
// return await this.getValidToken(true);
199-
// } else if (isRf && existingRefreshToken && !isExp) {
200-
// loginResult = await this.refreshToken();
201-
// } else {
202-
// this.log("Token not found or expired, logging in...", "warning");
203-
// loginResult = await this.auth();
204-
// }
205-
// // console.log(loginResult);
206-
// if (loginResult?.success) {
207-
// const { refresh_token, access_token } = loginResult?.data;
208-
// if (access_token) {
209-
// saveToken(userId, access_token);
210-
// this.token = access_token;
211-
// }
212-
// if (refresh_token) {
213-
// saveJson(userId, refresh_token, "refresh_token.json");
214-
// this.rfToken = refresh_token;
215-
// }
216-
// return { access_token: access_token, refresh_token: refresh_token };
217-
// } else {
218-
// this.log(`Can't get token, try get new query_id!`, "warning");
219-
// }
220-
// return { access_token: null, refresh_token: null };
221-
// }
196+
async getValidToken() {
197+
const userId = this.session_name;
198+
const existingToken = this.token;
199+
let loginResult = null;
200+
201+
const isExp = isTokenExpired(existingToken);
202+
if (existingToken && !isExp) {
203+
this.log("Using valid token", "success");
204+
return token;
205+
} else {
206+
this.log("Token not found or expired, logging in...", "warning");
207+
loginResult = await this.auth();
208+
}
209+
210+
if (loginResult?.success) {
211+
const { token } = loginResult?.data;
212+
if (token) {
213+
saveToken(userId, token);
214+
this.token = token;
215+
}
216+
217+
return token;
218+
} else {
219+
this.log(`Can't get token, try get new query_id!`, "warning");
220+
}
221+
return null;
222+
}
222223

223224
async runAccount() {
224225
try {
@@ -240,6 +241,8 @@ class ClientAPI {
240241
this.#set_headers();
241242
await sleep(timesleep);
242243

244+
const token = await this.getValidToken();
245+
if (!token) return this.log(`Can't get token for account ${this.accountIndex + 1}, skipping...`, "error");
243246
let userData = { success: false },
244247
retries = 0;
245248
do {

main.js

+60-52
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,15 @@ const user_agents = require("./config/userAgents");
77
const settings = require("./config/config");
88
const { sleep, loadData, saveToken, isTokenExpired, saveJson, updateEnv } = require("./utils");
99
const { checkBaseUrl } = require("./checkAPI");
10+
const headers = require("./core/header");
1011

1112
class ClientAPI {
1213
constructor(accountIndex, initData, session_name, baseURL) {
1314
this.accountIndex = accountIndex;
1415
this.queryId = initData;
15-
this.headers = {
16-
Accept: "application/json, text/plain, */*",
17-
"Accept-Encoding": "gzip, deflate, br",
18-
"Accept-Language": "vi-VN,vi;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6,en;q=0.5",
19-
"Content-Type": "application/json",
20-
Origin: "https://tg-sleepagotchi-tmp-cdn.sfo3.digitaloceanspaces.com",
21-
referer: "https://tg-sleepagotchi-tmp-cdn.sfo3.digitaloceanspaces.com/",
22-
"Sec-Ch-Ua": '"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"',
23-
"Sec-Ch-Ua-Mobile": "?0",
24-
"Sec-Ch-Ua-Platform": '"Windows"',
25-
"Sec-Fetch-Dest": "empty",
26-
"Sec-Fetch-Mode": "cors",
27-
"Sec-Fetch-Site": "same-origin",
28-
"Cache-Control": "no-cache",
29-
Connection: "keep-alive",
30-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
31-
};
16+
this.headers = headers;
3217
this.session_name = session_name;
3318
this.session_user_agents = this.#load_session_data();
34-
this.skipTasks = settings.SKIP_TASKS;
3519
this.baseURL = baseURL;
3620
}
3721

@@ -117,23 +101,39 @@ class ClientAPI {
117101
console.log(logMessage);
118102
}
119103

120-
async makeRequest(url, method, data = {}, retries = 1) {
104+
async makeRequest(
105+
url,
106+
method,
107+
data = {},
108+
options = {
109+
retries: 1,
110+
isAuth: false,
111+
}
112+
) {
113+
const { retries, isAuth } = options;
114+
121115
const headers = {
122116
...this.headers,
117+
Authorization: `tma ${this.queryId}`,
123118
};
119+
120+
if (!isAuth) {
121+
headers["Authorization"] = `Bearer ${this.token}`;
122+
}
123+
124124
let currRetries = 0,
125125
success = false;
126126
do {
127127
try {
128128
const response = await axios({
129129
method,
130-
url: `${url}?${this.queryId}`,
130+
url: `${url}`,
131131
data,
132132
headers,
133133
timeout: 30000,
134134
});
135135
success = true;
136-
if (response.data) return { success: true, data: response.data };
136+
if (response.data) return { success: true, data: response.data.data };
137137
return { success: false, data: response.data };
138138
} catch (error) {
139139
if (error.status == 400) {
@@ -148,42 +148,50 @@ class ClientAPI {
148148
} while (currRetries <= retries && !success);
149149
}
150150

151+
async auth() {
152+
return this.makeRequest(`${this.baseURL}/auth/create-user`, "post", { refCode: "Iil4QcC4TF" }, { isAuth: true });
153+
}
154+
151155
async getUserInfo() {
152-
return this.makeRequest(`${this.baseURL}/getUserData`, "get");
156+
return this.makeRequest(`${this.baseURL}/user`, "get");
157+
}
158+
159+
async getQuests() {
160+
return this.makeRequest(`${this.baseURL}/user/quest`, "get");
153161
}
154162

155-
// async getValidToken() {
156-
// const userId = this.session_name;
157-
// const existingToken = this.token;
158-
// let loginResult = null;
159-
160-
// const isExp = isTokenExpired(existingToken );
161-
// if (!isRf && existingToken && !isExp) {
162-
// this.log("Using valid token", "success");
163-
// return token
164-
// }else {
165-
// this.log("Token not found or expired, logging in...", "warning");
166-
// loginResult = await this.auth();
167-
// }
168-
169-
// if (loginResult?.success) {
170-
// const { refresh_token, access_token } = loginResult?.data;
171-
// if (access_token) {
172-
// saveToken(userId, access_token);
173-
// this.token = access_token;
174-
// }
175-
// if (refresh_token) {
176-
// saveJson(userId, refresh_token, "refresh_token.json");
177-
// this.rfToken = refresh_token;
178-
// }
179-
// return { access_token: access_token, refresh_token: refresh_token };
180-
// } else {
181-
// this.log(`Can't get token, try get new query_id!`, "warning");
182-
// }
183-
// return { access_token: null, refresh_token: null };
184-
// }
163+
async getValidToken() {
164+
const userId = this.session_name;
165+
const existingToken = this.token;
166+
let loginResult = null;
167+
168+
const isExp = isTokenExpired(existingToken);
169+
if (existingToken && !isExp) {
170+
this.log("Using valid token", "success");
171+
return token;
172+
} else {
173+
this.log("Token not found or expired, logging in...", "warning");
174+
loginResult = await this.auth();
175+
}
176+
177+
if (loginResult?.success) {
178+
const { token } = loginResult?.data;
179+
if (token) {
180+
saveToken(userId, token);
181+
this.token = token;
182+
}
183+
184+
return token;
185+
} else {
186+
this.log(`Can't get token, try get new query_id!`, "warning");
187+
}
188+
return null;
189+
}
185190

186191
async processAccount() {
192+
const token = await this.getValidToken();
193+
if (!token) return this.log(`Can't get token for account ${this.accountIndex + 1}, skipping...`, "error");
194+
187195
let userData = { success: false },
188196
retries = 0;
189197
do {

0 commit comments

Comments
 (0)