From 45a8083857c80583ed7c692135b73172d54bc6cd Mon Sep 17 00:00:00 2001 From: Zynh0722 Date: Thu, 8 Feb 2024 04:08:27 -0800 Subject: [PATCH] fetching games? --- docker-compose.yml | 6 +++++ index.mjs | 63 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 6f0454e..7117ac7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,7 @@ +volumes: + lol-fetcher-data: + external: true + services: stat-fetcher: image: node:current-alpine @@ -13,3 +17,5 @@ services: redis: image: redis + volumes: + - lol-fetcher-data:/data diff --git a/index.mjs b/index.mjs index 7b9fa85..b200fbc 100644 --- a/index.mjs +++ b/index.mjs @@ -1,6 +1,8 @@ // @ts-check import { RiotAPI, RiotAPITypes, PlatformId } from "@fightmegg/riot-api"; +const METHOD_KEY = RiotAPITypes.METHOD_KEY; + /** @type {RiotAPITypes.Config} */ const config = { cache: { @@ -8,7 +10,9 @@ const config = { client: "redis://redis:6379", // leave null if client is local ttls: { byMethod: { - [RiotAPITypes.METHOD_KEY.SUMMONER.GET_BY_SUMMONER_NAME]: 30 * 60 * 100, // ms + [METHOD_KEY.SUMMONER.GET_BY_SUMMONER_NAME]: 24 * 60 * 60 * 100, // ms + [METHOD_KEY.MATCH_V5.GET_IDS_BY_PUUID]: 24 * 60 * 60 * 100, // ms + [METHOD_KEY.MATCH.GET_MATCHLIST_BY_ACCOUNT]: 24 * 60 * 60 * 100, // ms }, }, }, @@ -16,9 +20,56 @@ const config = { const rAPI = new RiotAPI("RGAPI-8f41294d-7bb1-4fd5-83d4-773a8a7b25f5", config); -const summoner = await rAPI.summoner.getBySummonerName({ - region: PlatformId.NA1, - summonerName: "RavenShade", -}); +let val = await rAPI.summoner + .getBySummonerName({ + region: PlatformId.NA1, + summonerName: "RavenShade", + }) + .then(({ name, puuid }) => ({ name, puuid })); -console.log(`${JSON.stringify(summoner, null, " ")}`); +const ice = await rAPI.summoner + .getBySummonerName({ + region: PlatformId.NA1, + summonerName: "IcePhoenix05", + }) + .then(({ name, puuid }) => ({ name, puuid })); + +console.log(`${JSON.stringify(val, null, " ")}`); +console.log(`${JSON.stringify(ice, null, " ")}`); + +const valGames = await get_games_by_puuid(val.puuid); +const iceGames = await get_games_by_puuid(ice.puuid); + +const commonGames = valGames.filter(Set.prototype.has, new Set(iceGames)); + +console.log(`${JSON.stringify(commonGames, null, " ")}`); + +/** + * @param {string} puuid + * @returns {Promise} + */ +async function get_games_by_puuid(puuid) { + let games = []; + + let start = 0; + while (start >= 0) { + console.log(`getting entries ${start}-${start + 19}`); + let newGames = await rAPI.matchV5.getIdsByPuuid({ + cluster: PlatformId.AMERICAS, + puuid: val.puuid, + params: { + start, + }, + }); + + if (newGames.length < 20) { + break; + } + + games.push.apply(games, newGames); + + start += 20; + } + + return games; +}