Skip to content

Latest commit

 

History

History
204 lines (118 loc) · 5.85 KB

README.en.md

File metadata and controls

204 lines (118 loc) · 5.85 KB

GenshinKit

简体中文 | English

Total alerts Language grade: JavaScript

An API wrapper for fetching player data of Genshin Impact from any servers.

Installation

# Via yarn
yarn add genshin-kit
# Or via npm
npm install genshin-kit

Usage

You can find some sample code snippets here.

Below is the documentation of GenshinKit.


Main methods

GenshinKit {Class}

Instances of GenshinKit.

Returns: application instances of GenshinKit.

Constructor Example
const { GenshinKit } = require('genshin-kit')
const App = new GenshinKit()

App.loginWithCookie(cookie: string): this

Use cookies of hoyolab site to login to the instance.

⚠️ Caution ⚠️:Please keep your cookies safe.
NEVER SHARE YOUR COOKIES WITH ANYONE ELSE!

How to obtain: login to hoyolab Battle Chronicle https://webstatic-sea.mihoyo.com/app/community-game-records-sea/#/ys, then input document.cookie in the browser console, it returns the cookies you need. Usually the cookies you obtained can be used for some time; if it fails, try to obtain another one.

Usage Example
App.loginWithCookie(process.env.MHY_COOKIE)

App.setServerType(type: 'cn' | 'os'): this

Set the server location of UID to be queried. Default is cn; if you need to query Asia, Europe, US or HK-MC-TW server data, set this to os.

  • cn Chinese servers (Official, Bilibili)
  • os Oversea servers (Asia, Europe, US, HK-MC-TW)

App.getUserInfo(uid: number, noCache?: boolean): Promise<UserInfo>

Use UID to query player's basic information.

Returns: UserInfo

Request Example
App.getUserInfo(100000001).then(console.log)

App.getAllCharacters(uid: number, noCache?: boolean): Promise<Character[]>

Use UID to query player's detailed character information, including equipment.

Returns: Character[]

App.getSpiralAbyss(uid: number, type?: 1 | 2, noCache?: boolean): Promise<Abyss>

Use UID to query Spiral Abyss information.

type: 1 means current Lunar Phase, 2 means previous Lunar Phase.

Returns: Abyss

Quick query: App.getCurrentAbyss(<uid:number>): Promise<Abyss> App.getPreviousAbyss(<uid:number>): Promise<Abyss>

App.getActivities(uid: number): Promise<Activities>

Get current activities score by uid.

Returns: Activities


Auxiliary utilities

const { util } = require('genshin-kit')

util.getTheActivedConstellationsNumberOfSpecifiedGenshinImpactCharacter(character: Character): number get activated constellation number

Nah, just use util.activedConstellations should be fine; this f**king long name originated when the author was discussing with his friends how to name this method.

Returns the activated constellation number of specified Genshin Impact character. (Sorry for copy paste this name again :)

util.CharactersFilter(characters: Character[]) {class} character filter tool

A class encapsulating a set of methods for filtering character information.

Returns: Filter class

Usage Example
const { CharactersFilter } = require('genshin-kit').util
App.getAllCharacters(100000001).then((data) => {
  const Filter = new CharactersFilter(data)
  // ...
}, console.error)

all(): Character[]

Get all characters for a specified player.

id(id: number): Character | null

Get character information with specified id for a specified player.

name(name: string): Character | null

Get character information with specified name for a specified player.

name: character name, suggest in Simplified Chinese; also support aliases, see CharacterNickname.

element(element: string): Character[]

Get character information with specified element for a specified player.

element: can be in English or Simplified Chinese, e.g. pyro or .

rarity(rarity: number | number[]): Character[]

Get character information with specified rarity for a specified player.

rarity: should be a number or a number array, e.g. 4, 5 or [4, 5].

nicknameFilter: characterNickname

Expose the CharacterNickname instance which the filter is using.

util.CharacterNickname {class} tool for character nickname

Returns: Nickname class.

setNicknames(id: number, nicknames: string[]): this

Add some nicknames to a character by its ID.

getIdByNickname(keyword: string): number | undefined

Get a character's ID by its nickname, maybe absent.

getNicknamesById(id: number): string[] | undefined

Get a character's nicknames by its ID, maybe absent.

util.isValidOsUid(uid: any): boolean uid validation tool

Check whether input is a valid os uid.


For communication and learning only.

All game data & pictures from query: ©miHoYo

API endpoint: Refer Azure99/GenshinPlayerQuery (Apache-2.0 License)

Copyright 2021 Genshin-Kit

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0