Skip to content

Instantly share code, notes, and snippets.

@Areha11Fz
Last active April 28, 2023 06:46
Show Gist options
  • Save Areha11Fz/5abde2e19b75cb5f29321aa491107c1d to your computer and use it in GitHub Desktop.
Save Areha11Fz/5abde2e19b75cb5f29321aa491107c1d to your computer and use it in GitHub Desktop.
HoYoLab Auto Sign In
const token = "ltoken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; ltuid=xxxxxxxx;"
const genshin = false
const honkai_star_rail = true
const honkai_3 = false
const discord_notify = false
const myDiscordID = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
const myDiscordName = "xxxxxxxxxx"
const discordWebhook = "https://discord.com/api/webhooks/xxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
/** Original by https://github.com/canaria3406/hoyolab-auto-sign**/
/** Modified by Areha **/
function main(){
let hoyolabResp = autoSignFunction();
if(discord_notify == true){
let discordPostData = "";
if(myDiscordID){
discordPostData += "<@" + myDiscordID + ">, " + hoyolabResp;
}
else{
discordPostData += myDiscordName + ", " + hoyolabResp;
}
if(discordWebhook){
postWebhook(discordPostData);
}
}
}
function autoSignFunction() {
const signurl_gs = "https://sg-hk4e-api.hoyolab.com/event/sol/sign?lang=en-us&act_id=e202102251931481"
const signurl_hsr = "https://sg-public-api.hoyolab.com/event/luna/os/sign?lang=en-us&act_id=e202303301540311"
const signurl_bh3 = "https://sg-public-api.hoyolab.com/event/mani/sign?lang=en-us&act_id=e202110291205111"
const header = {
Cookie: token
};
const options = {
method: 'POST',
headers: header,
muteHttpExceptions: true,
};
let response = "";
if(genshin == true){
let hoyolabResponse_gs = UrlFetchApp.fetch(signurl_gs,options);
response += "\n" + JSON.parse(hoyolabResponse_gs).message;
}
if(honkai_star_rail == true){
let hoyolabResponse_hsr = UrlFetchApp.fetch(signurl_hsr,options);
response += "\n" + JSON.parse(hoyolabResponse_hsr).message;
}
if(honkai_3 == true){
let hoyolabResponse_bh3 = UrlFetchApp.fetch(signurl_bh3,options);
response += "\n" + JSON.parse(hoyolabResponse_bh3).message;
}
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment