UNPKG

@chiraitori/hoyolab-core

Version:

Core utilities for HoYoLab automation - daily check-ins and code redemption with smart rate limiting

117 lines (108 loc) 3.6 kB
const Games = { GENSHIN_IMPACT: 'genshin', HONKAI_STAR_RAIL: 'starrail', ZENLESS_ZONE_ZERO: 'zenless' }; const Regions = { NORTH_AMERICA: 'NA', EUROPE: 'EU', ASIA: 'SEA', TAIWAN_HK_MO: 'TW/HK/MO' }; // HoYoLab API rate limits and delays const RateLimits = { CODE_REDEMPTION_DELAY: 6000, // 6 seconds between code redemptions (HoYoLab API limit) CHECK_IN_DELAY: 1000, // 1 second between check-ins ACCOUNT_INFO_DELAY: 500 // 0.5 seconds between account info requests }; const GameConfigs = { [Games.GENSHIN_IMPACT]: { name: 'Genshin Impact', actId: 'e202102251931481', gameBiz: 'hk4e_global', signGame: 'hk4e', urls: { sign: 'https://sg-hk4e-api.hoyoverse.com/event/sol/sign', info: 'https://sg-hk4e-api.hoyoverse.com/event/sol/info', home: 'https://sg-hk4e-api.hoyoverse.com/event/sol/home', redeem: 'https://sg-hk4e-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey' }, // Optional: Built-in code API (developers can use their own) codeApi: 'https://api.ennead.cc/mihoyo/genshin/codes', regionMappings: { 'os_asia': 'SEA', 'os_usa': 'NA', 'os_euro': 'EU', 'os_cht': 'TW/HK/MO' } }, [Games.HONKAI_STAR_RAIL]: { name: 'Honkai: Star Rail', actId: 'e202303301540311', gameBiz: 'hkrpg_global', signGame: 'hkrpg', urls: { sign: 'https://sg-public-api.hoyoverse.com/event/luna/os/sign', info: 'https://sg-public-api.hoyoverse.com/event/luna/os/info', home: 'https://sg-public-api.hoyoverse.com/event/luna/os/home', redeem: 'https://sg-hkrpg-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey' }, // Optional: Built-in code API (developers can use their own) codeApi: 'https://api.ennead.cc/mihoyo/starrail/codes', regionMappings: { 'prod_official_usa': 'NA', 'prod_official_eur': 'EU', 'prod_official_asia': 'SEA', 'prod_official_cht': 'TW/HK/MO' } }, [Games.ZENLESS_ZONE_ZERO]: { name: 'Zenless Zone Zero', actId: 'e202406031448091', gameBiz: 'nap_global', signGame: 'nap', urls: { sign: 'https://sg-act-nap-api.hoyoverse.com/event/luna/os/sign', info: 'https://sg-act-nap-api.hoyoverse.com/event/luna/os/info', home: 'https://sg-act-nap-api.hoyoverse.com/event/luna/os/home', redeem: 'https://sg-nap-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey' }, // Optional: Built-in code API (developers can use their own) codeApi: 'https://api.ennead.cc/mihoyo/zenless/codes', regionMappings: { 'prod_gf_sg': 'TW/HK/MO', 'prod_gf_jp': 'SEA', 'prod_gf_eu': 'EU', 'prod_gf_us': 'NA' } } }; // Helper function to get region name for a specific game const getRegionName = (game, regionCode) => { const config = GameConfigs[game]; if (!config || !config.regionMappings) { return 'Unknown'; } return config.regionMappings[regionCode] || 'Unknown'; }; // Legacy mapping for backward compatibility (deprecated) const REGION_MAPPINGS = { 'os_cht': 'TW/HK/MO', 'prod_gf_sg': 'TW/HK/MO', 'prod_official_cht': 'TW/HK/MO', 'os_asia': 'SEA', 'prod_gf_jp': 'SEA', 'prod_official_asia': 'SEA', 'os_euro': 'EU', 'prod_gf_eu': 'EU', 'prod_official_eur': 'EU', 'os_usa': 'NA', 'prod_gf_us': 'NA', 'prod_official_usa': 'NA' }; module.exports = { Games, Regions, RateLimits, GameConfigs, REGION_MAPPINGS, getRegionName };