diff --git a/src/example.ts b/src/example.ts index 9489d68..64f5e73 100644 --- a/src/example.ts +++ b/src/example.ts @@ -12,7 +12,14 @@ F95_PASSWORD = YOUR_PASSWORD import dotenv from "dotenv"; // Modules from file -import { login, getUserData, getLatestUpdates, getGameData} from "./index"; +import { login, + getUserData, + getLatestUpdates, + LatestSearchQuery, + Game, + searchHandiwork, + HandiworkSearchQuery +} from "./index.js"; // Configure the .env reader dotenv.config(); @@ -35,27 +42,37 @@ async function main() { // Get user data console.log("Fetching user data..."); const userdata = await getUserData(); - console.log(`${userdata.username} follows ${userdata.watched.length} threads\n`); + const gameThreads = userdata.watched.filter(e => e.forum === "Games").length; + console.log(`${userdata.name} follows ${userdata.watched.length} threads of which ${gameThreads} are games\n`); // Get latest game update - // const latestUpdates = await getLatestUpdates({ - // tags: ["3d game"] - // }, 1); - // console.log(`"${latestUpdates[0].name}" was the last "3d game" tagged game to be updated\n`); + const latestQuery: LatestSearchQuery = new LatestSearchQuery(); + latestQuery.category = "games"; + latestQuery.includedTags = ["3d game"]; + + const latestUpdates = await getLatestUpdates(latestQuery, 1); + console.log(`"${latestUpdates.shift().name}" was the last "3d game" tagged game to be updated\n`); // Get game data for(const gamename of gameList) { console.log(`Searching '${gamename}'...`); - const found = await getGameData(gamename, false); - // If no game is found - if (found.length === 0) { + // Prepare the query + const query: HandiworkSearchQuery = new HandiworkSearchQuery(); + query.keywords = gamename; + + // Fetch the first result + const result = await searchHandiwork(query, 1); + + // No game found + if (result.length === 0) { console.log(`No data found for '${gamename}'`); continue; } // Extract first game - const gamedata = found[0]; - //console.log(`Found: ${gamedata.name} (${gamedata.version}) by ${gamedata.author}\n`); + const gamedata = result.shift(); + const authors = gamedata.authors.map((a, idx) => a.name).join(", "); + console.log(`Found: ${gamedata.name} (${gamedata.version}) by ${authors}\n`); } }