lol-pairing-stat-fetcher/index.mjs

92 lines
2.2 KiB
JavaScript
Raw Normal View History

2024-02-08 11:18:03 +00:00
// @ts-check
import { RiotAPI, RiotAPITypes, PlatformId } from "@fightmegg/riot-api";
2024-02-08 12:08:27 +00:00
const METHOD_KEY = RiotAPITypes.METHOD_KEY;
2024-02-08 11:18:03 +00:00
/** @type {RiotAPITypes.Config} */
const config = {
2024-02-08 12:15:34 +00:00
debug: false,
2024-02-08 11:18:03 +00:00
cache: {
cacheType: "ioredis", // local or ioredis
client: "redis://redis:6379", // leave null if client is local
ttls: {
byMethod: {
2024-02-08 12:34:16 +00:00
[METHOD_KEY.SUMMONER.GET_BY_SUMMONER_NAME]: 24 * 60 * 60 * 100, // 1 day
[METHOD_KEY.MATCH_V5.GET_IDS_BY_PUUID]: 24 * 60 * 60 * 100, // 1 day
[METHOD_KEY.MATCH_V5.GET_MATCH_BY_ID]: 24 * 60 * 60 * 100, // 1 day
// TODO: Figure out if I can get more games with old API?
// [METHOD_KEY.MATCH.GET_MATCHLIST_BY_ACCOUNT]: 24 * 60 * 60 * 100, // ms
2024-02-08 11:18:03 +00:00
},
},
},
};
const rAPI = new RiotAPI("RGAPI-8f41294d-7bb1-4fd5-83d4-773a8a7b25f5", config);
2024-02-08 12:08:27 +00:00
let val = await rAPI.summoner
.getBySummonerName({
region: PlatformId.NA1,
summonerName: "RavenShade",
})
.then(({ name, puuid }) => ({ name, puuid }));
const ice = await rAPI.summoner
.getBySummonerName({
region: PlatformId.NA1,
summonerName: "IcePhoenix05",
})
.then(({ name, puuid }) => ({ name, puuid }));
2024-02-08 12:34:16 +00:00
const valGameIds = await get_games_by_puuid(val.puuid);
const iceGamesIds = await get_games_by_puuid(ice.puuid);
2024-02-08 12:08:27 +00:00
2024-02-08 12:34:16 +00:00
const commonGameIds = valGameIds.filter(
Set.prototype.has,
new Set(iceGamesIds),
);
2024-02-08 12:08:27 +00:00
2024-02-08 12:37:48 +00:00
// console.log(`${JSON.stringify(commonGameIds, null, " ")}`);
2024-02-08 12:34:16 +00:00
2024-02-08 12:37:48 +00:00
/** @type {RiotAPITypes.MatchV5.MatchDTO[]} */
2024-02-08 12:34:16 +00:00
let commonGames = [];
for (const matchId of commonGameIds) {
const game = await rAPI.matchV5.getMatchById({
cluster: PlatformId.AMERICAS,
matchId,
});
commonGames.push(game);
}
2024-02-08 12:08:27 +00:00
2024-02-08 12:37:48 +00:00
console.log(`Common Game Data Found: ${commonGameIds.length}`);
console.log(`${JSON.stringify(commonGames[0], null, " ")}`);
2024-02-08 12:08:27 +00:00
/**
* @param {string} puuid
* @returns {Promise<string[]>}
*/
async function get_games_by_puuid(puuid) {
let games = [];
let start = 0;
while (start >= 0) {
let newGames = await rAPI.matchV5.getIdsByPuuid({
cluster: PlatformId.AMERICAS,
2024-02-08 12:15:34 +00:00
puuid,
2024-02-08 12:08:27 +00:00
params: {
start,
},
});
if (newGames.length < 20) {
break;
}
games.push.apply(games, newGames);
start += 20;
}
2024-02-08 11:18:03 +00:00
2024-02-08 12:08:27 +00:00
return games;
}