Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 15x 15x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 38x 38x 38x 38x 38x 38x 23x 23x 38x 38x 38x 38x 38x 38x 23x 23x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x | import { Language, LanguageEnum } from '../../language' import { DailyModule } from '../../module/daily' import { RedeemModule } from '../../module/redeem' import { IGenshinOptions } from './gi.interface' import { Cookie, ICookie } from '../../cookie' import { HTTPRequest } from '../../request' import { DEFAULT_REFERER } from '../../routes' import { getGenshinRegion } from './gi.helper' import { GamesEnum, Hoyolab, IGame } from '../hoyolab' import { GenshinRecordModule, SpiralAbyssScheduleEnum } from './record' import { DiaryEnum, GenshinDiaryModule, DiaryMonthEnum } from './diary' import { HoyoAPIError } from '../../error' import { GenshinTCGModule } from './tcg' /** * The `Genshin` class provides an interface to interact with Genshin Impact-related features on the Mihoyo website. * It contains references to various modules such as `DailyModule`, `RedeemModule`, `GenshinRecordModule`, and `GenshinDiaryModule` which allow you to perform various operations related to these features. * * @class * @category Main */ export class GenshinImpact { /** * The `DailyModule` object provides an interface to interact with the daily check-in feature in Genshin Impact. * */ readonly daily: DailyModule /** * The `RedeemModule` object provides an interface to interact with the code redemption feature in Genshin Impact. * */ readonly redeem: RedeemModule /** * The `GenshinRecordModule` object provides an interface to interact with the user record feature in Genshin Impact. * */ readonly record: GenshinRecordModule /** * The `GenshinDiaryModule` object provides an interface to interact with the user diary feature in Genshin Impact. * */ readonly diary: GenshinDiaryModule /** * The `GenshinTCGModule` object provides an interface to interact with the user diary feature in Genshin Impact. * */ readonly tcg: GenshinTCGModule /** * HoyYolab account object * */ private _account: IGame | null = null /** * The cookie object to be used in requests. */ readonly cookie: ICookie /** * The `Request` object used to make requests. */ private request: HTTPRequest /** * The UID of the user, if available. */ readonly uid: number | null /** * The region of the user, if available. */ readonly region: string | null /** * The language to be used in requests. */ private lang: LanguageEnum /** * Constructs a new `Genshin` object. * * @param options The options object used to configure the object. */ constructor(options: IGenshinOptions) { const cookie: ICookie = typeof options.cookie === 'string' ? Cookie.parseCookieString(options.cookie) : options.cookie this.cookie = cookie if (!options.lang) { options.lang = Language.parseLang(cookie.mi18nLang) } // Parse language to prevent language error options.lang = Language.parseLang(options.lang) this.request = new HTTPRequest(Cookie.parseCookie(this.cookie)) this.request.setReferer(DEFAULT_REFERER) this.request.setLang(options.lang) this.uid = options.uid ?? null this.region = this.uid !== null ? getGenshinRegion(this.uid) : null this.lang = options.lang this.daily = new DailyModule( this.request, this.lang, GamesEnum.GENSHIN_IMPACT, this.region, ) this.redeem = new RedeemModule( this.request, this.lang, GamesEnum.GENSHIN_IMPACT, this.region, this.uid, ) this.record = new GenshinRecordModule( this.request, this.lang, this.region, this.uid, ) this.diary = new GenshinDiaryModule( this.request, this.lang, this.region, this.uid, ) this.tcg = new GenshinTCGModule( this.request, this.lang, this.region, this.uid, ) } /** * Create a new instance of the GenshinImpact class asynchronously. * * @param options The options object used to configure the object. * @throws {HoyoAPIError} Error Wnen the CookieTokenV2 is not set. * @returns {Promise<GenshinImpact>} A promise that resolves with a new Genshin instance. * * @remarks * If an object is instantiated from this method but options.cookie.cookieTokenV2 is not set, * it will throw an error. This method will access an Endpoint that contains a list of game accounts, * which requires the cookieTokenV2 option. * @remarks * Because CookieTokenV2 has a short expiration time and cannot be refreshed so far. * It is evident that every few days, when logging in, it always requests authentication first. * Therefore, this method that uses CookieTokenV2 is not suitable if filled statically. */ static async create(options: IGenshinOptions): Promise<GenshinImpact> { try { let game: IGame | null = null if (typeof options.uid === 'undefined') { const hoyolab = new Hoyolab({ cookie: options.cookie, }) game = await hoyolab.gameAccount(GamesEnum.GENSHIN_IMPACT) options.uid = parseInt(game.game_uid) } const gi = new GenshinImpact(options) gi.account = game return gi } catch (error: any) { throw new HoyoAPIError(error.message, error.code) } } /** * Setter for the account property. Prevents from changing the value once set * @param game The game object to set as the account. */ public set account(game: IGame | null) { if (this.account === null && game !== null) { this._account = game } } /** * Getter for the account property. * @returns {IGame | null} The current value of the account property. */ public get account(): IGame | null { return this._account } /** * Get user's Genshin Impact record * * @alias {@link GenshinImpact.record | Genshin.record.records()} * @deprecated Use through {@link GenshinImpact.record | Genshin.record.records()} instead */ async records() { return this.record.records() } /** * Retrieves the Genshin characters of the user. * * @alias {@link GenshinImpact.record | Genshin.record.characters()} * @deprecated Use through {@link GenshinImpact.record | Genshin.record.characters()} instead */ async characters() { return this.record.characters() } /** * Returns the summary information of Genshin Impact game characters * * @param characterIds number[] Characters ID * @alias {@link GenshinImpact.record | Genshin.record.charactersSummary()} * @deprecated Use through {@link GenshinImpact.record | Genshin.record.charactersSummary()} instead */ async charactersSummary(characterIds: number[]) { return this.record.charactersSummary(characterIds) } /** * Retrieves information about the player's performance in the Spiral Abyss. * * @param scheduleType SpiralAbyssScheduleEnum * @alias {@link GenshinImpact.record | Genshin.record.spiralAbyss()} * @deprecated Use through {@link GenshinImpact.record | Genshin.record.spiralAbyss()} instead */ async spiralAbyss( scheduleType: SpiralAbyssScheduleEnum = SpiralAbyssScheduleEnum.CURRENT, ) { return this.record.spiralAbyss(scheduleType) } /** * Retrieve the daily note information for a Genshin Impact user. * * @alias {@link GenshinImpact.record | Genshin.record.dailyNote()} * @deprecated Use through {@link GenshinImpact.record | Genshin.record.dailyNote()} instead */ async dailyNote() { return this.record.dailyNote() } /** * Returns the diary information of a given month for a user * * @param month * @alias {@link GenshinImpact.diary | Genshin.diary.list()} * @deprecated Use through {@link GenshinImpact.diary | Genshin.diary.list()} instead */ async diaryList(month: DiaryMonthEnum = DiaryMonthEnum.CURRENT) { return this.diary.list(month) } /** * Returns the diary details of a given type and month for a user * * @param type DiaryEnum * @param month DiaryMonthEnum * @alias {@link GenshinImpact.diary | Genshin.diary.detail()} * @deprecated Use through {@link GenshinImpact.diary | Genshin.diary.detail()} instead */ async diaryDetail( type: DiaryEnum, month: DiaryMonthEnum = DiaryMonthEnum.CURRENT, ) { return this.diary.detail(type, month) } /** * Retrieves daily information. * * @alias {@link GenshinImpact.daily | Genshin.daily.info()} * @deprecated Use through {@link GenshinImpact.daily | Genshin.daily.info()} instead */ dailyInfo() { return this.daily.info() } /** * Retrieve daily rewards information. * * @alias {@link GenshinImpact.daily | Genshin.daily.rewards()} * @deprecated Use through {@link GenshinImpact.daily | Genshin.daily.rewards()} instead */ dailyRewards() { return this.daily.rewards() } /** * Get the daily reward for a specific day or the current day * * @param day number | null * @alias {@link GenshinImpact.daily | Genshin.daily.reward()} * @deprecated Use through {@link GenshinImpact.daily | Genshin.daily.reward()} instead */ dailyReward(day: number | null = null) { return this.daily.reward(day) } /** * Claim current reward * * @alias {@link GenshinImpact.daily | Genshin.daily.claim()} * @deprecated Use through {@link GenshinImpact.daily | Genshin.daily.claim()} instead */ dailyClaim() { return this.daily.claim() } /** * Redeems a code for a specific account. * * @param code string * @alias {@link GenshinImpact.daily | Genshin.redeem.claim()} * @deprecated Use through {@link GenshinImpact.daily | Genshin.redeem.claim()} instead */ redeemCode(code: string) { return this.redeem.claim(code) } } |