add stupid shit i just ran
This commit is contained in:
parent
ecedf23c76
commit
53d48912d0
1 changed files with 60 additions and 0 deletions
60
bin/one-time/add-quest-sync-info
Executable file
60
bin/one-time/add-quest-sync-info
Executable file
|
|
@ -0,0 +1,60 @@
|
|||
#!/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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue