fixing keys and filter for draft pick

main
Zynh0722 2024-02-08 16:52:26 -08:00
parent 5e95e2557b
commit 341893fdb7
5 changed files with 31 additions and 7 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
node_modules/ node_modules/
.env

1
example.env Normal file
View File

@ -0,0 +1 @@
RG_API_KEY=api_key_here

View File

@ -1,6 +1,11 @@
// @ts-check // @ts-check
import { RiotAPI, RiotAPITypes, PlatformId } from "@fightmegg/riot-api"; import { RiotAPI, RiotAPITypes, PlatformId } from "@fightmegg/riot-api";
import "dotenv/config";
/** @type {string} */
const RG_API_KEY = process.env.RG_API_KEY || "no api key found";
const METHOD_KEY = RiotAPITypes.METHOD_KEY; const METHOD_KEY = RiotAPITypes.METHOD_KEY;
/** @type {RiotAPITypes.Config} */ /** @type {RiotAPITypes.Config} */
@ -21,7 +26,7 @@ const config = {
}, },
}; };
const rAPI = new RiotAPI("RGAPI-8f41294d-7bb1-4fd5-83d4-773a8a7b25f5", config); const rAPI = new RiotAPI(RG_API_KEY, config);
let val = await rAPI.summoner let val = await rAPI.summoner
.getBySummonerName({ .getBySummonerName({
@ -45,8 +50,6 @@ const commonGameIds = valGameIds.filter(
new Set(iceGamesIds), new Set(iceGamesIds),
); );
// console.log(`${JSON.stringify(commonGameIds, null, " ")}`);
/** @type {RiotAPITypes.MatchV5.MatchDTO[]} */ /** @type {RiotAPITypes.MatchV5.MatchDTO[]} */
let commonGames = []; let commonGames = [];
for (const matchId of commonGameIds) { for (const matchId of commonGameIds) {
@ -65,6 +68,7 @@ commonGames.reverse();
commonGames commonGames
.map(({ info, metadata }) => ({ .map(({ info, metadata }) => ({
id: metadata.matchId, id: metadata.matchId,
queueId: info.queueId,
data: info.participants data: info.participants
.filter(({ puuid }) => puuid === ice.puuid || puuid === val.puuid) .filter(({ puuid }) => puuid === ice.puuid || puuid === val.puuid)
.map(({ championId, championName, summonerName, lane }) => ({ .map(({ championId, championName, summonerName, lane }) => ({
@ -74,6 +78,7 @@ commonGames
lane, lane,
})), })),
})) }))
.filter((g) => g.queueId !== 400)
// .filter(({ data }) => { // .filter(({ data }) => {
// const lanes = data.map((s) => s.lane); // const lanes = data.map((s) => s.lane);
// return lanes.includes("BOTTOM") && lanes.includes("SUPPORT"); // return lanes.includes("BOTTOM") && lanes.includes("SUPPORT");
@ -85,6 +90,8 @@ commonGames
* @returns {Promise<string[]>} * @returns {Promise<string[]>}
*/ */
async function get_games_by_puuid(puuid) { async function get_games_by_puuid(puuid) {
const COUNT = 100;
let games = []; let games = [];
let start = 0; let start = 0;
@ -94,6 +101,8 @@ async function get_games_by_puuid(puuid) {
puuid, puuid,
params: { params: {
start, start,
count: COUNT,
queue: 400,
}, },
}); });
@ -103,7 +112,7 @@ async function get_games_by_puuid(puuid) {
games.push.apply(games, newGames); games.push.apply(games, newGames);
start += 20; start += COUNT;
} }
return games; return games;

14
package-lock.json generated
View File

@ -9,7 +9,8 @@
"version": "1.0.0", "version": "1.0.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@fightmegg/riot-api": "^0.0.18" "@fightmegg/riot-api": "^0.0.18",
"dotenv": "^16.4.1"
}, },
"devDependencies": { "devDependencies": {
"nodemon": "^3.0.3" "nodemon": "^3.0.3"
@ -167,6 +168,17 @@
"node": ">=0.10" "node": ">=0.10"
} }
}, },
"node_modules/dotenv": {
"version": "16.4.1",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.1.tgz",
"integrity": "sha512-CjA3y+Dr3FyFDOAMnxZEGtnW9KBR2M0JvvUtXNW+dYJL5ROWxP9DUHCwgFqpMk0OXCc0ljhaNTr2w/kutYIcHQ==",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/motdotla/dotenv?sponsor=1"
}
},
"node_modules/fill-range": { "node_modules/fill-range": {
"version": "7.0.1", "version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",

View File

@ -5,12 +5,13 @@
"main": "index.mjs", "main": "index.mjs",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"start": "node --no-deprecation index.mjs" "start": "DEBUG=riotapi* node --no-deprecation index.mjs"
}, },
"author": "", "author": "",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@fightmegg/riot-api": "^0.0.18" "@fightmegg/riot-api": "^0.0.18",
"dotenv": "^16.4.1"
}, },
"devDependencies": { "devDependencies": {
"nodemon": "^3.0.3" "nodemon": "^3.0.3"