Code Monkey home page Code Monkey logo

hoyolab-auto-sign's Introduction

Hi there, I'm canaria 👋

  • 💼 Site Reliability Engineer
  • 💬 Contact me from Discord!

javascript typescript ecmascript nodejs php sql

linux googlecloud googleappsscript cloudflare vstudiocode

hoyolab-auto-sign's People

Contributors

canaria3406 avatar cd36th avatar chillrend avatar lostlang avatar mbs0ft avatar mchangrh avatar natsumeaoii avatar wudifeixue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hoyolab-auto-sign's Issues

Doubt regarding setting up environmental variables in google script

Hello,
First of all I want to convey my gratitude to @canaria3406 for creating this script.

I have a question. I heard that cookies data shouldn't be shared with anyone. How we can set up environmental variables in google script? Or there is nothing to worry about as my project in google script is private and no one can view my secret values.

Waiting for your response and thankyou.

ltoken value changed to ltoken_v2 by hoyoverse

It looks like hoyoverse changed ltoken value to ltoken_v2 and ltuid to ltuid_v2
Hence, whenever I run the script below it gives me undefined as output.

function getCookie(name) {
  const value = `; ${document.cookie}`;
  const parts = value.split(`; ${name}=`);
  if (parts.length === 2) return parts.pop().split(';').shift();
}
let token = 'ltoken=' + getCookie('ltoken') + '; ltuid=' + getCookie('ltuid') + ';';
let ask = confirm(token + '\n\nPress enter, then paste the token into your Google Apps Script Project');
if (ask == true) {
  copy(token);
  msg = token;
} else {
  msg = 'Cancel';
}

request: how to add 2 discord webhooks

nvm, i asked co-pilot and it worked

const profiles = [
  { token: "account_mid_v2=123xyzabcd_hi; account_id_v2=26XXXXX20; ltoken_v2=v2_CANARIAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX3406; ltmid_v2=123xyzabcd_hi; ltuid_v2=26XXXXX20;", 
    genshin: true, 
    honkai_star_rail: true, 
    honkai_3: false, 
    accountName: "HuTao" }
];

const discord_notify = true
const myDiscordID = "240000800000300040"
const discordWebhooks = [
  "https://discord.com/api/webhooks/10xxxxxxxxxxxxxxx60/6aXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXnB",
  "https://discord.com/api/webhooks/1050000000000000060/6aXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXnB"
];

/** 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 has been modified to be in 2 webhooks of 2 diffrent servers. Modified by @AureliusGemini . **/

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 && discordWebhooks.length > 0){
    postWebhooks(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);
}

Not working for Genshin

The script seems to be no longer working for Genshin (Still works for Honkai and Star Rail).

not working for one account

Screenshot_2023-05-19-19-37-54-71_1149b56b894fd37d9a6fe46f85aae740

Screenshot_2023-05-19-19-38-00-96_40deb401b9ffe8e1df2f1cc5ba480b12
I've tried everything i can think of yet one of the account isn't working, the other one work. But the second one doesn't work.

Not working for genshin

It was working fine last month, until this month where it keeps sending "OK" message even if it's actually failed. And after I manually checked-in then ran the script, it still sends "OK". When I manually checked-in I had to complete a CAPTCHA.

However, when I added my second account, it was working fine on that account.

Add support for multiple accounts

it seems only support a single account to check in, I tried to put in another token and did not recognize my main account, or maybe there is something wrong with my setup.

image

2 HoYoLAB account sign-in problem

Hi, I want to use the bot for my 2 accounts. However when i log in into the second account, the bot will not run on the first account. Anyone has made it work yet?

README.md 請補充說明

          README.md 請補充說明
  1. myTelegramID 如何取得。
  2. 如何創建一個自己的bot,以及如何產生token。
    我做了一下功課。執行成功但是不知為何bot收不到通知。
    不知道哪裡錯了,可否協助?感謝。
    image

myTelegramID 是指自身帳號ID還是bot ID?
我試了上述兩個,bot都收不到任何通知。

另比對中英script程式碼行數不符,英文版有缺漏61-73行的程式碼。

Originally posted by @ingrid-z in #1 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.