lol-pairing-stat-fetcher/index.mjs

74 lines
1.7 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:08:27 +00:00
[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
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 }));
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));
2024-02-08 12:15:34 +00:00
console.log(`Common Games Found: ${commonGames.length}`);
2024-02-08 12:08:27 +00:00
console.log(`${JSON.stringify(commonGames, null, " ")}`);
/**
* @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;
}