#!/usr/bin/env -S node --env-file-if-exists=.env // Adds `quest-sync` parameters to quest infoboxes that don't have them import { findEDBQuestSync } from '../../lib/api/lodestone.js'; import {getMediawikiClient} from '../../lib/config.js'; import {diff} from '../../lib/util/diff.js'; import { addParameterBesideExistingParameter } from '../../lib/util/template-parameters.js'; const mw = await getMediawikiClient(); const allquestcats = ` Category:Main Scenario quests Category:Side Story quests Category:Guildleves Category:Sidequests Category:other quests Category:Daily quests Category:Feature quests Category:Repeatable Feature quests Category:Quasi-quests Category:Feature quasi-quests Category:Quests with no type specified `.split('\n').filter(s => s); console.log(allquestcats) const pages = (await Promise.all(allquestcats.map(category => mw.listCategoryPages(category, [0], 'max')))).flat(); console.log(pages.length); function insertQuestSync (pageContent) { if (pageContent.includes('quest-sync')) { throw new Error('Page already contains a `quest-sync` parameter'); } let result = addParameterBesideExistingParameter(pageContent, 'quest-sync', 'true', 'after', 'level'); if (result == null) throw new Error('Failed to add parameter'); return result; } const start = parseInt(process.env.START ?? '0', 10); if (start) { console.log('Starting from item index', start); pages.splice(0, start); } for (const [i, {title}] of Object.entries(pages)) { console.log(start+parseInt(i), title); const content = await mw.readPage(title); const hasQuestSync = await findEDBQuestSync(title.replace(' (Quest)', '')); if (!hasQuestSync) continue; let newContent; try { newContent = insertQuestSync(content); } catch (error) { console.error(error); continue; } diff(content, newContent); await mw.editPage(title, newContent, 'Add quest-sync parameter', true); }