74 lines
1.7 KiB
JavaScript
74 lines
1.7 KiB
JavaScript
// @ts-check
|
|
import { RiotAPI, RiotAPITypes, PlatformId } from "@fightmegg/riot-api";
|
|
|
|
const METHOD_KEY = RiotAPITypes.METHOD_KEY;
|
|
|
|
/** @type {RiotAPITypes.Config} */
|
|
const config = {
|
|
debug: false,
|
|
cache: {
|
|
cacheType: "ioredis", // local or ioredis
|
|
client: "redis://redis:6379", // leave null if client is local
|
|
ttls: {
|
|
byMethod: {
|
|
[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
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const rAPI = new RiotAPI("RGAPI-8f41294d-7bb1-4fd5-83d4-773a8a7b25f5", config);
|
|
|
|
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));
|
|
|
|
console.log(`Common Games Found: ${commonGames.length}`);
|
|
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,
|
|
puuid,
|
|
params: {
|
|
start,
|
|
},
|
|
});
|
|
|
|
if (newGames.length < 20) {
|
|
break;
|
|
}
|
|
|
|
games.push.apply(games, newGames);
|
|
|
|
start += 20;
|
|
}
|
|
|
|
return games;
|
|
}
|