This commit is contained in:
parent
786bc69cf3
commit
6947c30c23
@ -37,7 +37,7 @@ app.use(
|
|||||||
timezone: "Europe/London",
|
timezone: "Europe/London",
|
||||||
run: async () => {
|
run: async () => {
|
||||||
const pages = 10;
|
const pages = 10;
|
||||||
const cooldown = 60_000 / 200; // 200 requests per minute
|
const cooldown = 60_000 / 250; // 250 requests per minute
|
||||||
|
|
||||||
let toTrack: PlayerDocument[] = await PlayerModel.find({});
|
let toTrack: PlayerDocument[] = await PlayerModel.find({});
|
||||||
const toRemoveIds: string[] = [];
|
const toRemoveIds: string[] = [];
|
||||||
@ -54,7 +54,7 @@ app.use(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (const player of page.players) {
|
for (const player of page.players) {
|
||||||
const foundPlayer = await PlayerService.getPlayer(player.id, true);
|
const foundPlayer = await PlayerService.getPlayer(player.id, true, player);
|
||||||
await PlayerService.trackScoreSaberPlayer(foundPlayer, player);
|
await PlayerService.trackScoreSaberPlayer(foundPlayer, player);
|
||||||
toRemoveIds.push(foundPlayer.id);
|
toRemoveIds.push(foundPlayer.id);
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,19 @@ export class PlayerService {
|
|||||||
*
|
*
|
||||||
* @param id the player to fetch
|
* @param id the player to fetch
|
||||||
* @param create if true, create the player if it doesn't exist
|
* @param create if true, create the player if it doesn't exist
|
||||||
|
* @param playerToken an optional player token for the player
|
||||||
* @returns the player
|
* @returns the player
|
||||||
* @throws NotFoundError if the player is not found
|
* @throws NotFoundError if the player is not found
|
||||||
*/
|
*/
|
||||||
public static async getPlayer(id: string, create: boolean = false): Promise<PlayerDocument> {
|
public static async getPlayer(
|
||||||
|
id: string,
|
||||||
|
create: boolean = false,
|
||||||
|
playerToken?: ScoreSaberPlayerToken
|
||||||
|
): Promise<PlayerDocument> {
|
||||||
let player: PlayerDocument | null = await PlayerModel.findById(id);
|
let player: PlayerDocument | null = await PlayerModel.findById(id);
|
||||||
if (player === null) {
|
if (player === null) {
|
||||||
// If create is on, create the player, otherwise return unknown player
|
// If create is on, create the player, otherwise return unknown player
|
||||||
const playerToken = create ? await scoresaberService.lookupPlayer(id) : undefined;
|
playerToken = create ? (playerToken ? playerToken : await scoresaberService.lookupPlayer(id)) : undefined;
|
||||||
if (playerToken === undefined) {
|
if (playerToken === undefined) {
|
||||||
throw new NotFoundError(`Player "${id}" not found`);
|
throw new NotFoundError(`Player "${id}" not found`);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user