TapSwapBot
TapSwapBot copied to clipboard
Completing missions after watching videos.
Has anyone tried to adapt the Java code for completing missions for this bot?
Help me with the implementation of basic queries. I’ll finish the wrapper with sorting through the codes and updating the file with the answers and make a pull. I undertake to update it up to date. The videos have already started to repeat themselves.
Join mission:
async joinMissions(missionId) {
twist.log(`Joining Mission with id : ${missionId}`, this.acc, this);
this.generateHeader();
const requestBody = {
id: missionId,
};
const response = await this.page.evaluate(
async (url, requestBody) => {
const res = await fetch(url, {
method: "POST",
body: JSON.stringify(requestBody),
});
const json = await res.json().catch(() => ({}));
return {
status: res.status,
statusText: res.statusText,
ok: res.ok,
data: json,
};
},
this.apiUrl + "/api/missions/join_mission",
requestBody
);
if (response.ok) {
const data = response.data;
this.account = data.account;
await Helper.sleep(
1000,
this.acc,
`Missions ${missionId} joined successfully`,
this
);
} else if (response.status == 400) {
await Helper.sleep(
1000,
this.acc,
`Missions ${missionId} - ${response.data.message}`,
this
);
} else {
await Helper.sleep(
3000,
this.acc,
`Error During Join Mission : ${response.status} - ${response.statusText}`,
this
);
await this.handleError("joinMissions", totalTap);
}
}
Finish mission Item:
async finishMissionsItem(missionId) {
twist.log(`Finisihing Mission Item with id : ${missionId}`, this.acc, this);
const requestBody = {
id: missionId,
itemIndex: 0,
};
const response = await this.page.evaluate(
async (url, requestBody) => {
const res = await fetch(url, {
method: "POST",
body: JSON.stringify(requestBody),
});
const json = await res.json().catch(() => ({}));
return {
status: res.status,
statusText: res.statusText,
ok: res.ok,
data: json,
};
},
this.apiUrl + "/api/missions/finish_mission_item",
requestBody
);
// console.log(response);
if (response.ok) {
const data = response.data;
this.account = data.account;
await Helper.sleep(
1000,
this.acc,
`Missions Item ${missionId} Finished Successfully`,
this
);
} else if (response.status == 400) {
await Helper.sleep(
1000,
this.acc,
`Missions ${missionId} - ${response.data.message}`,
this
);
} else {
await Helper.sleep(
3000,
this.acc,
`Error : ${response.status} - ${response.statusText}`,
this
);
await this.handleError("finishMissionsItem", missionId);
}
}
Finish mission Item with Input:
async finishMissionsItemWithInput(missionId, code = "") {
twist.log(
`Finisihing Mission Item with id : ${missionId} , with code : ${code}`,
this.acc,
this
);
const requestBody = {
id: missionId,
itemIndex: 0,
user_input: code,
};
const response = await this.page.evaluate(
async (url, requestBody) => {
const res = await fetch(url, {
method: "POST",
body: JSON.stringify(requestBody),
});
const json = await res.json().catch(() => ({}));
return {
status: res.status,
statusText: res.statusText,
ok: res.ok,
data: json,
};
},
this.apiUrl + "/api/missions/finish_mission_item",
requestBody
);
// console.log(response);
if (response.ok) {
const data = response.data;
this.account = data.account;
await Helper.sleep(
1000,
this.acc,
`Missions Item ${missionId} Finished Successfully`,
this
);
} else if (response.status == 400) {
await Helper.sleep(
1000,
this.acc,
`Missions ${missionId} - ${response.data.message}`,
this
);
} else {
await Helper.sleep(
3000,
this.acc,
`Error : ${response.status} - ${response.statusText}`,
this
);
await this.handleError("finishMissionsItemWithInput", [missionId, code]);
}
}
Finish mission:
async finishMissions(missionId) {
twist.log(`Finisihing Mission with id : ${missionId}`, this.acc, this);
const requestBody = {
id: missionId,
};
const response = await this.page.evaluate(
async (url, requestBody) => {
const res = await fetch(url, {
method: "POST",
body: JSON.stringify(requestBody),
});
const json = await res.json().catch(() => ({}));
return {
status: res.status,
statusText: res.statusText,
ok: res.ok,
data: json,
};
},
this.apiUrl + "/api/missions/finish_mission",
requestBody
);
if (response.ok) {
const data = response.data;
this.account = data.account;
this.player = data.player;
await Helper.sleep(
1000,
this.acc,
`Missions ${missionId} Finished Successfully`,
this
);
} else if (response.status == 400) {
await Helper.sleep(
1000,
this.acc,
`Missions Item ${missionId} Failed to Finish - ${response.data.message}`,
this
);
} else {
await Helper.sleep(
3000,
this.acc,
`Error : ${response.status} - ${response.statusText}`,
this
);
await this.handleError("finishMissions", missionId);
}
}
Claim mission:
async claimMission(missionId) {
await this.generateHeader();
twist.log(`Claiming Mission with id : ${missionId}`, this.acc, this);
const requestBody = {
task_id: missionId,
};
const response = await this.page.evaluate(
async (url, requestBody) => {
const res = await fetch(url, {
method: "POST",
body: JSON.stringify(requestBody),
});
const json = await res.json().catch(() => ({}));
return {
status: res.status,
statusText: res.statusText,
ok: res.ok,
data: json,
};
},
this.apiUrl + "/api/player/claim_reward",
requestBody
);
if (response.ok) {
const data = response.data;
this.player = data.player;
await Helper.sleep(
1000,
this.acc,
`Missions ${missionId} Claimed Successfully`,
this
);
} else {
await Helper.sleep(
3000,
this.acc,
`Error : ${response.status} - ${response.statusText}`,
this
);
await this.handleError("claimMission", missionId);
}
}
how to add this code to program?