import ChessWebAPI from 'chess-web-api' ; import fetch from 'node-fetch' ; const chessAPI = new ChessWebAPI ( ) ; returns { Promise < ICurrentDailyGames > } export async function currentGames ( ) { let response = await chessAPI . getPlayerCurrentDailyChess ( 'andyruwruw' ) ; const { statusCode } = response ; if ( statusCode === 200 ) { return response . body ; } else { return { games : [ ] , } ; } } ; param { boolean } isWhite param { string } fen returns { Array < string | null > } export function convertFen ( isWhite , fen ) { let finalPosition = [ ] ; let position = fen . slice ( 0 , fen . indexOf ( ' ' ) ) ; let rows = position . split ( "/" ) ; if ( ! isWhite ) { rows . reverse ( ) ; } for ( let i = 0 ; i < rows . length ; i ++ ) { finalPosition . push ( [ ] ) ; for ( let j = 0 ; j < rows [ i ] . length ; j ++ ) { if ( rows [ i ] [ j ] >= '1' && rows [ i ] [ j ] <= '9' ) { for ( let k = 0 ; k < parseInt ( rows [ i ] [ j ] , 10 ) ; k ++ ) { finalPosition [ i ] . push ( null ) ; } } else { finalPosition [ i ] . push ( rows [ i ] [ j ] ) ; } } if ( ! isWhite ) { finalPosition [ i ] . reverse ( ) ; } } return finalPosition ; } /**
 * Loads the images into a buffer
 * Only does this once
 */ export async function getPieces ( ) { let pieceImages = { } ; let pieces = [ 'b' , 'k' , 'n' , 'p' , 'q' , 'r' ] ; let colors = [ 'white' , 'black' ] ; for ( const color of colors ) { for ( const piece of pieces ) { const buff = await ( await fetch ( `https://raw.githubusercontent.com/andyruwruw/andyruwruw/master/src/assets/${ color }-${ piece }.png` ) ) . arrayBuffer ( ) ; pieceImages [ `${ color }-${ piece }` ] = `data:image/jpeg;base64,${ Buffer . from ( buff ) . toString ( 'base64' ) }` ; } } return pieceImages ; } ;