async function player( id, language ) {
	
	try {
    	
		let allycode = id.toString().match(/^\d{9}$/) ? parseInt(id.toString().match(/\d{9}/)[0]) : null;
		let discordId = id.toString().match(/^\d{17,18}$/) ? id.toString().match(/^\d{17,18}$/)[0] : null;
		
		if( !allycode && !discordId ) { 
			throw new Error('Please provide a valid allycode'); 
		}
		
        let expiredDate = new Date();
	        expiredDate.setHours(expiredDate.getHours() - playerCooldown);
		
		/** Get player from cache */
		let player = allycode ?
			await cache.get('swapi', 'players', {allyCode:allycode, updated:{ $gte:expiredDate.getTime() }}) :
			await cache.get('swapi', 'players', {discordId:discordId, updated:{ $gte:expiredDate.getTime() }});

		/** Check if existance and expiration */
		if( !player || !player[0] ) { 
		
			/** If not found or expired, fetch new from API and save to cache */
			player = allycode ? 
				await swgoh.fetchPlayer({ allycodes:[allycode], language:language, enums:true }) :
				await swgoh.fetchPlayer({ discordIds:[discordId], language:language, enums:true });
			
			if( !player || player.length === 0 ) { 
				throw new Error('No player found'); 
			} 
			
			if( discordId ) { player[0].discordId = discordId; }
			player = await cache.put('swapi', 'players', {allyCode:player[0].allyCode}, player[0]);
		} 

        return Array.isArray(player) ? player[0] : player;
		
	} catch(e) { 
		throw e; 
	}    		

}
/**
 *  Fetch player profile object from cache, and sync if necessary
 *  ! This will only fetch a single allycode 
 * 
 *  Params
 *  @id - allycode or discordId (! discord Id requires patreon-tier api user)
 *  @language - language code for reply
 */
Fetch player profile object from cache, and sync if necessary
! This will only fetch a single allycode

Params
@id - allycode or discordId (. discord Id requires patreon-tier api user)
@language - language code for reply
Fetch player profile object from cache and sync if necessary ! This will only fetch a single allycode Params @id - allycode or discordId ( . discord Id requires patreon - tier api user ) @language - language code for reply
async function player( id, language ) {
	try {
		let allycode = id.toString().match(/^\d{9}$/) ? parseInt(id.toString().match(/\d{9}/)[0]) : null;
		let discordId = id.toString().match(/^\d{17,18}$/) ? id.toString().match(/^\d{17,18}$/)[0] : null;
		if( !allycode && !discordId ) { 
			throw new Error('Please provide a valid allycode'); 
		}
        let expiredDate = new Date();
	        expiredDate.setHours(expiredDate.getHours() - playerCooldown);
		let player = allycode ?
			await cache.get('swapi', 'players', {allyCode:allycode, updated:{ $gte:expiredDate.getTime() }}) :
			await cache.get('swapi', 'players', {discordId:discordId, updated:{ $gte:expiredDate.getTime() }});
		if( !player || !player[0] ) { 
			player = allycode ? 
				await swgoh.fetchPlayer({ allycodes:[allycode], language:language, enums:true }) :
				await swgoh.fetchPlayer({ discordIds:[discordId], language:language, enums:true });
			if( !player || player.length === 0 ) { 
				throw new Error('No player found'); 
			} 
			if( discordId ) { player[0].discordId = discordId; }
			player = await cache.put('swapi', 'players', {allyCode:player[0].allyCode}, player[0]);
		} 
        return Array.isArray(player) ? player[0] : player;
	} catch(e) { 
		throw e; 
	}    		
}
async function player ( id , language ) { try { let allycode = id . toString ( ) . match ( / ^\d{9}$ / ) ? parseInt ( id . toString ( ) . match ( / \d{9} / ) [ 0 ] ) : null ; let discordId = id . toString ( ) . match ( / ^\d{17,18}$ / ) ? id . toString ( ) . match ( / ^\d{17,18}$ / ) [ 0 ] : null ; if ( ! allycode && ! discordId ) { throw new Error ( 'Please provide a valid allycode' ) ; } let expiredDate = new Date ( ) ; expiredDate . setHours ( expiredDate . getHours ( ) - playerCooldown ) ; let player = allycode ? await cache . get ( 'swapi' , 'players' , { allyCode : allycode , updated : { $gte : expiredDate . getTime ( ) } } ) : await cache . get ( 'swapi' , 'players' , { discordId : discordId , updated : { $gte : expiredDate . getTime ( ) } } ) ; if ( ! player || ! player [ 0 ] ) { player = allycode ? await swgoh . fetchPlayer ( { allycodes : [ allycode ] , language : language , enums : true } ) : await swgoh . fetchPlayer ( { discordIds : [ discordId ] , language : language , enums : true } ) ; if ( ! player || player . length === 0 ) { throw new Error ( 'No player found' ) ; } if ( discordId ) { player [ 0 ] . discordId = discordId ; } player = await cache . put ( 'swapi' , 'players' , { allyCode : player [ 0 ] . allyCode } , player [ 0 ] ) ; } return Array . isArray ( player ) ? player [ 0 ] : player ; } catch ( e ) { throw e ; } }
Fetch player profile object from cache, and sync if necessary
  !
Fetch player profile object from cache and sync if necessary !
/** Get player from cache */ /** Check if existance and expiration */ /** If not found or expired, fetch new from API and save to cache */