-
Notifications
You must be signed in to change notification settings - Fork 32
/
main-discord.gs
98 lines (80 loc) · 2.98 KB
/
main-discord.gs
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
const profiles = [
{
token: "ltoken_v2=gBxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxCY; ltuid_v2=26XXXXX20;",
genshin: true,
honkai_star_rail: true,
honkai_3: false,
accountName: "YOUR NICKNAME"
}
];
const discord_notify = true
const myDiscordID = ""
const discordWebhook = ""
/** The above is the config. Please refer to the instructions on https://github.com/canaria3406/hoyolab-auto-sign for configuration. **/
/** The following is the script code. Please DO NOT modify. **/
const urlDict = {
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 && discordWebhook) {
postWebhook(hoyolabResp);
}
}
function discordPing() {
return myDiscordID ? `<@${myDiscordID}> ` : '';
}
function autoSignFunction({ token, genshin, honkai_star_rail, honkai_3, accountName }) {
const urls = [];
if (genshin) urls.push(urlDict.Genshin);
if (honkai_star_rail) urls.push(urlDict.Star_Rail);
if (honkai_3) urls.push(urlDict.Honkai_3);
const header = {
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'
};
const options = {
method: 'POST',
headers: header,
muteHttpExceptions: true,
};
let response = `Check-in completed for ${accountName}`;
const httpResponses = UrlFetchApp.fetchAll(urls.map(url => ({ url, ...options })));
for (const [i, hoyolabResponse] of httpResponses.entries()) {
const responseJson = JSON.parse(hoyolabResponse);
const checkInResult = responseJson.message;
const gameName = Object.keys(urlDict).find(key => urlDict[key] === urls[i])?.replace(/_/g, ' ');
const isError = checkInResult != "OK";
const bannedCheck = responseJson.data?.gt_result?.is_risk;
if (bannedCheck) {
response += `\n${gameName}: ${discordPing()} Auto check-in failed due to CAPTCHA blocking.`;
} else {
response += `\n${gameName}: ${isError ? discordPing() : ""}${checkInResult}`;
}
}
return response;
}
function postWebhook(data) {
let payload = JSON.stringify({
'username': 'auto-sign',
'avatar_url': 'https://i.imgur.com/LI1D4hP.png',
'content': data
});
const options = {
method: 'POST',
contentType: 'application/json',
payload: payload,
muteHttpExceptions: true
};
UrlFetchApp.fetch(discordWebhook, options);
}