-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathautoDailyCheckIn.js
More file actions
136 lines (117 loc) · 4.35 KB
/
autoDailyCheckIn.js
File metadata and controls
136 lines (117 loc) · 4.35 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
const profiles = [
{
token: "ltoken_v2=v2_XXXXX; ltuid_v2=XXXXX;",
zzz: true,
genshin: false,
honkai_star_rail: false,
honkai_3: false,
accountName: "ADD UNQIUE IDENTIFIER FOR YOUR ACCOUNT HERE"
}
];
/** Discord Notification **/
const discord_notify = false;
const myDiscordID = "INSERT YOUR DISCORD ID IF YOU WANT TO GET PING, OR YOU CAN LEAVE IT EMPTY";
const discordWebhook =
"INSERT YOUR WEBHOOK HERE";
/** This code is based on canaria3406 and modified by Areha11Fz **/
/** The following is the script code. Please DO NOT modify. **/
const urlDict = {
ZZZ:
"https://sg-act-nap-api.hoyolab.com/event/luna/zzz/os/sign?lang=en-us&act_id=e202406031448091",
Genshin:
"https://sg-hk4e-api.hoyolab.com/event/sol/sign?lang=en-us&act_id=e202102251931481",
Star_Rail:
"https://sg-public-api.hoyolab.com/event/luna/os/sign?lang=en-us&act_id=e202303301540311",
Honkai_3:
"https://sg-public-api.hoyolab.com/event/mani/sign?lang=en-us&act_id=e202110291205111"
};
async function main() {
const messages = await Promise.all(profiles.map(autoSignFunction));
const hoyolabResp = `${messages.join("\n\n")}`;
if (discord_notify == true) {
if (discordWebhook) {
postWebhook(hoyolabResp);
}
}
}
function discordPing() {
if (myDiscordID) {
return `<@${myDiscordID}> `;
} else {
return "";
}
}
function autoSignFunction({ token, zzz, genshin, honkai_star_rail, honkai_3, accountName }) {
const urls = [];
if (zzz) urls.push(urlDict.ZZZ);
if (genshin) urls.push(urlDict.Genshin);
if (honkai_star_rail) urls.push(urlDict.Star_Rail);
if (honkai_3) urls.push(urlDict.Honkai_3);
const baseHeader = {
Cookie: token,
Accept: "application/json, text/plain, */*",
"Accept-Encoding": "gzip, deflate, br",
Connection: "keep-alive",
"x-rpc-app_version": "2.34.1",
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
"x-rpc-client_type": "4",
Referer: "https://act.hoyolab.com/",
Origin: "https://act.hoyolab.com"
};
// Build a separate request for each URL with the correct x-rpc-signgame header
const httpRequests = urls.map(url => {
const headers = { ...baseHeader };
if (url === urlDict.ZZZ) headers["x-rpc-signgame"] = "zzz";
if (url === urlDict.Star_Rail) headers["x-rpc-signgame"] = "honkai_star_rail";
if (url === urlDict.Genshin) headers["x-rpc-signgame"] = "genshin";
if (url === urlDict.Honkai_3) headers["x-rpc-signgame"] = "honkai_3";
return {
url,
method: "POST",
headers,
muteHttpExceptions: true
};
});
let response = `${accountName}`;
let retry = false;
do {
const httpResponses = UrlFetchApp.fetchAll(httpRequests);
for (const [i, hoyolabResponse] of httpResponses.entries()) {
const result = JSON.parse(hoyolabResponse);
const checkInResult = result.message;
const gameName = Object.keys(urlDict)
.find(key => urlDict[key] === urls[i])
?.replace(/_/g, " ");
const isError = checkInResult != "OK";
const bannedCheck = result.data?.gt_result?.is_risk;
if (bannedCheck) {
response += `\n${gameName}: ${discordPing()} Auto check-in failed due to CAPTCHA blocking.`;
retry = true;
break;
} else {
response += `\n${gameName}: ${isError ? discordPing() : ""}${checkInResult}`;
}
}
// If any request failed due to CAPTCHA, retry in an hour
if (retry) {
Utilities.sleep(3600000); // Sleep for 1 hour (3600 seconds * 1000 milliseconds)
retry = false;
}
} while (retry);
return response;
}
function postWebhook(data) {
let payload = JSON.stringify({
username: "Auto Check-In Notification",
avatar_url: "https://i.imgur.com/ibrSmCn.png",
content: data
});
const options = {
method: "POST",
contentType: "application/json",
payload: payload,
muteHttpExceptions: true
};
UrlFetchApp.fetch(discordWebhook, options);
}