Lishogi Bot API

Lishogi has not yet released an API and also don’t have a repo for their API, so here I will be writing the API for lishogi. Do note that it is taken from the lichess Bot API ( lichess.org/api#tag/Bot ). There are only a few changes but I will show it over here. Do note that all example responses were copied from lichess API without any changes at all. Also this is completely unofficial.

Play on Lishogi as a bot. Allows engine play.

Only works with Bot accounts.

Features:

- Stream incoming shogi moves
- Play shogi moves
- Read and write in the player and spectator chats
- Receive, create and accept (or decline) challenges
- Abort and resign games
- Engine assistance is allowed

Restrictions:
:(

- Bots can only play challenge games: pools and tournaments are off-limits.

Stream incoming events:
=====================

Stream the events reaching a lichess user in real time as ndjson( http://ndjson.org/ ).

Each line is a JSON object containing a type field. Possible values are:

- ‘gameStart’ Start of a game
- ‘gameFinish’ Completion of a game
- ‘challenge’ A player sends you a challenge
- ‘challengeCanceled’ A player cancels their challenge to you
- ‘challengeDeclined’ The opponent declines your challenge

When the stream opens, all current challenges and games are sent.

Authorizations: OAuth2 (‘challenge:read’, ‘bot:play’, ‘board:play’) ( lishogi.org/account/oauth/token )

Responses:

GET : lishogi.org/api/stream/event
Content type : text/plain

Example response:

{"type":"challenge","challenge":{"id":"7pGLxJ4F","status":"created","challenger":{"id":"lovlas","name":"Lovlas","title":"IM","rating":2506,"patron":true,"online":true,"lag":24},"destUser":{"id":"thibot","name":"thibot","title":null,"rating":1500,"provisional":true,"online":true,"lag":45},"variant":{"key":"standard","name":"Standard","short":"Std"},"rated":true,"timeControl":{"type":"clock","limit":300,"increment":25,"show":"5+25"},"color":"random","perf":{"icon":"#","name":"Rapid"}}}
{"type":"gameStart","game":{"id":"1lsvP62l"}}

Upgrade to Bot account:
=====================

Upgrade a lishogi player account into a Bot account. Only Bot accounts can use the Bot API.

The account cannot have played any game before becoming a Bot account. The upgrade is irreversible. The account will only be able to play as a Bot.

To upgrade an account to Bot, use the Lishogi-Bot client( github.com/TheYoBots/Lishogi-Bot ), or follow these steps:

- Create an API access token with "Play bot moves" permission.
- ‘curl -d '' lishogi.org/api/bot/account/upgrade -H "Authorization: Bearer <yourTokenHere>"’
- To know if an account has already been upgraded, use the Get my profile API(taken from lichess lichess.org/api#operation/accountMe) : the ‘title’ field should be set to ‘BOT’.

AUTHORIZATIONS : OAuth2 (‘bot:play’) ( lishogi.org/account/oauth/token )

Responses:

POST : lishogi.org/api/bot/account/upgrade
Content type : application/json

Example response:

{
"ok": true
}

Stream Bot game state:
====================

Stream the state of a game being played with the Bot API, as ndjson.

Use this endpoint to get updates about the game in real-time, with a single request.

Each line is a JSON object containing a type field. Possible values are:

- ‘gameFull’ Full game data. All values are immutable, except for the state field.
- ‘gameState’ Current state of the game. Immutable values not included.
- ‘chatLine’ Chat message sent by a user (or the bot itself) in the room "player" or "spectator".

The first line is always of type ‘gameFull’.

AUTHORIZATIONS : OAuth2 (bot:play) ( lishogi.org/account/oauth/token )

PATH PARAMETERS :
- ‘gameId’ (required) : Example: 5IrD6Gzz

Responses:

GET : lishogi.org/api/bot/game/stream/{gameId}
Content type: application/json

Example response:

[
{
"type": "gameFull",
"id": "5IrD6Gzz",
"rated": true,
"variant": {
"key": "standard",
"name": "Standard",
"short": "Std"
},
"clock": {
"initial": 1200000,
"increment": 10000
},
"speed": "classical",
"perf": {
"name": "Classical"
},
"createdAt": 1523825103562,
"white": {
"id": "lovlas",
"name": "lovlas",
"provisional": false,
"rating": 2500,
"title": "IM"
},
"black": {
"id": "leela",
"name": "leela",
"rating": 2390,
"title": null
},
"initialFen": "startpos",
"state": {
"type": "gameState",
"moves": "e2e4 c7c5 f2f4 d7d6 g1f3 b8c6 f1c4 g8f6 d2d3 g7g6 e1g1 f8g7",
"wtime": 7598040,
"btime": 8395220,
"winc": 10000,
"binc": 10000,
"status": "started"
}
},
{
"type": "gameState",
"moves": "e2e4 c7c5 f2f4 d7d6 g1f3 b8c6 f1c4 g8f6 d2d3 g7g6 e1g1 f8g7 b1c3",
"wtime": 7598040,
"btime": 8395220,
"winc": 10000,
"binc": 10000,
"status": "started"
},
{
"type": "chatLine",
"username": "thibault",
"text": "Good luck, have fun",
"room": "player"
},
{
"type": "chatLine",
"username": "lovlas",
"text": "!eval",
"room": "spectator"
},
{
"type": "gameState",
"moves": "e2e4 c7c5 f2f4 d7d6 g1f3 b8c6 f1c4 g8f6 d2d3 g7g6 e1g1 f8g7 b1c3",
"wtime": 7598040,
"btime": 8395220,
"winc": 10000,
"binc": 10000,
"status": "resign",
"winner": "black"
}
]

Make a Bot move:
===============

Make a move in a game being played with the Bot API.

The move can also contain a draw offer/agreement.

AUTHORIZATIONS : OAuth2 (bot:play) ( lishogi.org/account/oauth/token )

Path Parameters:

- ‘gameId’ (required) : Example: 5IrD6Gzz
- ‘move’ (required) : Example: e2e4 . The move to play, in UCI format.

Query Parameters:

- ‘offeringDraw‘ : Whether to offer (or agree to) a draw

Responses:

POST : lishogi.org/api/bot/game/{gameId}/move/{move}
Content type: application/json

Example response:

{
"ok": true
}

Write in the chat:
===============

Post a message to the player or spectator chat, in a game being played with the Bot API.

AUTHORIZATIONS : OAuth2 (bot:play) ( lishogi.org/account/oauth/token )

PATH PARAMETERS:

- ‘ gameId’ (required) : Example: 5IrD6Gzz

REQUEST BODY SCHEMA : application/x-www-form-urlencoded

- ‘room’ (required) : Enum: "player" "spectator"
- ‘text’ (required) : (what you want to chat)

Responses:

POST : lishogi.org/api/bot/game/{gameId}/chat
Content type : application/json

Example response:

{
"ok": true
}

Reconnecting